Merge aicom-network-branch (without NDIS changes for now)
[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 along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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_, const std::string& description_ )
33 {
34 string name(name_);
35 strlwr ( &name[0] );
36 if ( !ref++ )
37 factories = new map<string,Factory*>;
38 (*factories)[name] = this;
39 m_name = name;
40 m_description = description_;
41 }
42
43 Backend::Factory::~Factory ()
44 {
45 if ( !--ref )
46 {
47 delete factories;
48 factories = NULL;
49 }
50 }
51
52 /*static*/ Backend*
53 Backend::Factory::Create ( const string& name,
54 Project& project,
55 Configuration& configuration )
56 {
57 string sname ( name );
58 strlwr ( &sname[0] );
59 if ( !factories || !factories->size () )
60 throw InvalidOperationException ( __FILE__,
61 __LINE__,
62 "No registered factories" );
63 Backend::Factory* f = (*factories)[sname];
64 if ( !f )
65 {
66 throw UnknownBackendException ( sname );
67 return NULL;
68 }
69 return (*f) ( project, configuration );
70 }
71
72 Backend::Backend ( Project& project,
73 Configuration& configuration )
74 : ProjectNode ( project ),
75 configuration ( configuration )
76 {
77 }
78
79 Backend::~Backend()
80 {
81 }
82
83 string
84 Backend::GetFullPath ( const FileLocation& file ) const
85 {
86 string directory;
87 switch ( file.directory )
88 {
89 case SourceDirectory:
90 directory = "";
91 break;
92 case IntermediateDirectory:
93 directory = Environment::GetIntermediatePath ();
94 break;
95 case OutputDirectory:
96 directory = Environment::GetOutputPath ();
97 break;
98 case InstallDirectory:
99 directory = Environment::GetInstallPath ();
100 break;
101 default:
102 throw InvalidOperationException ( __FILE__,
103 __LINE__,
104 "Invalid directory %d.",
105 file.directory );
106 }
107
108 if ( file.relative_path.length () > 0 )
109 {
110 if ( directory.length () > 0 )
111 directory += sSep;
112 directory += file.relative_path;
113 }
114 return directory;
115 }
116
117 string
118 Backend::GetFullName ( const FileLocation& file ) const
119 {
120 string directory = GetFullPath ( file );
121
122 if ( directory.length () > 0 )
123 directory += sSep;
124
125 return directory + file.name;
126 }