Branch setupapi
[reactos.git] / reactos / tools / rbuild / backend / backend.cpp
1
2 #include "../pch.h"
3
4 #include "../rbuild.h"
5 #include "backend.h"
6
7 using std::string;
8 using std::vector;
9 using std::map;
10
11 map<string,Backend::Factory*>*
12 Backend::Factory::factories = NULL;
13 int
14 Backend::Factory::ref = 0;
15
16 Backend::Factory::Factory ( const std::string& name_ )
17 {
18 string name(name_);
19 strlwr ( &name[0] );
20 if ( !ref++ )
21 factories = new map<string,Factory*>;
22 (*factories)[name] = this;
23 }
24
25 Backend::Factory::~Factory()
26 {
27 if ( !--ref )
28 {
29 delete factories;
30 factories = NULL;
31 }
32 }
33
34 /*static*/ Backend*
35 Backend::Factory::Create ( const string& name,
36 Project& project )
37 {
38 string sname ( name );
39 strlwr ( &sname[0] );
40 if ( !factories || !factories->size() )
41 throw Exception ( "internal tool error: no registered factories" );
42 Backend::Factory* f = (*factories)[sname];
43 if ( !f )
44 {
45 throw UnknownBackendException ( sname );
46 return NULL;
47 }
48 return (*f) ( project );
49 }
50
51 Backend::Backend ( Project& project )
52 : ProjectNode ( project )
53 {
54 }