much better factory implementation - thanks art yerkes
authorRoyce Mitchell III <royce3@ev1.net>
Thu, 6 Jan 2005 03:27:24 +0000 (03:27 +0000)
committerRoyce Mitchell III <royce3@ev1.net>
Thu, 6 Jan 2005 03:27:24 +0000 (03:27 +0000)
svn path=/branches/xmlbuildsystem/; revision=12846

reactos/tools/rbuild/backend/backend.cpp
reactos/tools/rbuild/backend/backend.h
reactos/tools/rbuild/backend/mingw/mingw.cpp
reactos/tools/rbuild/backend/mingw/mingw.h
reactos/tools/rbuild/rbuild.cpp

index 4375d21..03c764b 100644 (file)
@@ -9,25 +9,29 @@
 using std::string;\r
 using std::vector;\r
 \r
-vector<Backend::Factory*> Backend::factories;\r
+vector<Backend::Factory*>* Backend::Factory::factories = NULL;\r
 \r
-/*static*/ void\r
-Backend::InitFactories()\r
+Backend::Factory::Factory ( const std::string& name_ )\r
+       : name(name_)\r
 {\r
-       factories.push_back ( new Factory ( "mingw", MingwBackend::Factory ) );\r
+       if ( !factories )\r
+               factories = new vector<Factory*>;\r
+       factories->push_back ( this );\r
 }\r
 \r
 /*static*/ Backend*\r
-Backend::Create ( const std::string& name, Project& project )\r
+Backend::Factory::Create ( const std::string& name, Project& project )\r
 {\r
        string sname ( name );\r
        strlwr ( &sname[0] );\r
-       if ( !factories.size() )\r
+       if ( !factories || !factories->size() )\r
                throw Exception ( "internal tool error: no registered factories" );\r
-       for ( size_t i = 0; i < factories.size(); i++ )\r
+       vector<Backend::Factory*>& fact = *factories;\r
+       for ( size_t i = 0; i < fact.size(); i++ )\r
        {\r
-               if ( sname == factories[i]->name )\r
-                       return (factories[i]->factory) ( project );\r
+               //char* p = *fact[i];\r
+               if ( sname == fact[i]->name )\r
+                       return (*fact[i]) ( project );\r
        }\r
        throw UnknownBackendException ( sname );\r
        return NULL;\r
index 5ed778f..3219e79 100644 (file)
@@ -9,23 +9,23 @@ typedef Backend* BackendFactory ( Project& project );
 \r
 class Backend\r
 {\r
+public:\r
        class Factory\r
        {\r
-       public:\r
+               static std::vector<Factory*>* factories;\r
                std::string name;\r
-               BackendFactory* factory;\r
 \r
-               Factory ( const std::string& name_, BackendFactory* factory_ )\r
-                       : name(name_), factory(factory_)\r
-               {\r
-               }\r
-       };\r
+       protected:\r
 \r
-       static std::vector<Factory*> factories;\r
+               Factory ( const std::string& name_ );\r
 \r
-public:\r
-       static void InitFactories();\r
-       static Backend* Create ( const std::string& name, Project& project );\r
+               virtual Backend* operator() ( Project& ) = 0;\r
+\r
+       public:\r
+               static Backend* Create ( const std::string& name, Project& project );\r
+\r
+       private:\r
+       };\r
 \r
 protected:\r
        Backend ( Project& project );\r
index 0b1a935..b548134 100644 (file)
@@ -6,11 +6,15 @@
 using std::string;\r
 using std::vector;\r
 \r
-Backend*\r
-MingwBackend::Factory ( Project& project )\r
+static class MingwFactory : public Backend::Factory\r
 {\r
-       return new MingwBackend ( project );\r
-}\r
+public:\r
+       MingwFactory() : Factory ( "mingw" ) {}\r
+       Backend* operator() ( Project& project )\r
+       {\r
+               return new MingwBackend ( project );\r
+       }\r
+} factory;\r
 \r
 #ifdef WIN32\r
 #define EXEPOSTFIX ".exe"\r
index 94cf4aa..ebdf7fb 100644 (file)
@@ -20,10 +20,7 @@ public:
 class MingwBackend : public Backend\r
 {\r
 public:\r
-       static Backend* Factory ( Project& project );\r
-protected:\r
        MingwBackend ( Project& project );\r
-public:\r
        virtual void Process ();\r
 private:\r
        void ProcessModule ( Module& module );\r
index fcc1de5..58d6ac1 100644 (file)
@@ -17,7 +17,6 @@ using std::vector;
 int\r
 main ( int argc, char** argv )\r
 {\r
-       Backend::InitFactories();\r
        if ( argc != 2 )\r
        {\r
                printf ( "syntax: rbuild {buildtarget}\n" );\r
@@ -29,7 +28,7 @@ main ( int argc, char** argv )
        {\r
                string projectFilename ( "ReactOS.xml" );\r
                Project project ( projectFilename );\r
-               Backend* backend = Backend::Create ( buildtarget, project );\r
+               Backend* backend = Backend::Factory::Create ( buildtarget, project );\r
                backend->Process ();\r
                delete backend;\r
                \r