adding gccasm.rules to vcproj files
[reactos.git] / reactos / tools / rbuild / backend / backend.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #include "../pch.h"
19
20 #include "../rbuild.h"
21 #include "backend.h"
22
23 using std::string;
24 using std::vector;
25 using std::map;
26
27 map<string,Backend::Factory*>*
28 Backend::Factory::factories = NULL;
29 int
30 Backend::Factory::ref = 0;
31
32 Backend::Factory::Factory ( const std::string& name_ )
33 {
34 string name(name_);
35 strlwr ( &name[0] );
36 if ( !ref++ )
37 factories = new map<string,Factory*>;
38 (*factories)[name] = this;
39 }
40
41 Backend::Factory::~Factory ()
42 {
43 if ( !--ref )
44 {
45 delete factories;
46 factories = NULL;
47 }
48 }
49
50 /*static*/ Backend*
51 Backend::Factory::Create ( const string& name,
52 Project& project,
53 Configuration& configuration )
54 {
55 string sname ( name );
56 strlwr ( &sname[0] );
57 if ( !factories || !factories->size () )
58 throw InvalidOperationException ( __FILE__,
59 __LINE__,
60 "No registered factories" );
61 Backend::Factory* f = (*factories)[sname];
62 if ( !f )
63 {
64 throw UnknownBackendException ( sname );
65 return NULL;
66 }
67 return (*f) ( project, configuration );
68 }
69
70 Backend::Backend ( Project& project,
71 Configuration& configuration )
72 : ProjectNode ( project ),
73 configuration ( configuration )
74 {
75 }
76
77 Backend::~Backend()
78 {
79 }