replaced Backend Factory's vector with a map. added a map of the MingwModuleHandlers that's created at startup time Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h Modified: branches/xmlbuildsystem/reactos/tools/rbuild/pch.h _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.cpp 2005-01-09 01:58:53 UTC (rev 12900) @@ -6,15 +6,17 @@
using std::string; using std::vector; +using std::map;
-vectorBackend::Factory** Backend::Factory::factories = NULL; +map<const char*,Backend::Factory*>* Backend::Factory::factories = NULL;
Backend::Factory::Factory ( const std::string& name_ ) - : name(name_) { + string name(name_); + strlwr ( &name[0] ); if ( !factories ) - factories = new vector<Factory*>; - factories->push_back ( this ); + factories = new map<const char*,Factory*>; + (*factories)[name.c_str()] = this; }
/*static*/ Backend* @@ -24,15 +26,13 @@ strlwr ( &sname[0] ); if ( !factories || !factories->size() ) throw Exception ( "internal tool error: no registered factories" ); - vectorBackend::Factory*& fact = *factories; - for ( size_t i = 0; i < fact.size(); i++ ) + Backend::Factory* f = (*factories)[sname.c_str()]; + if ( !f ) { - //char* p = *fact[i]; - if ( sname == fact[i]->name ) - return (*fact[i]) ( project ); + throw UnknownBackendException ( sname ); + return NULL; } - throw UnknownBackendException ( sname ); - return NULL; + return (*f) ( project ); }
Backend::Backend ( Project& project ) _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/backend.h 2005-01-09 01:58:53 UTC (rev 12900) @@ -12,8 +12,7 @@
public: class Factory { - static std::vector<Factory*>* factories; - std::string name; + static std::map<const char*,Factory*>* factories;
protected:
_____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.cpp 2005-01-09 01:58:53 UTC (rev 12900) @@ -43,6 +43,7 @@
fMakefile = fopen ( ProjectNode.makefile.c_str (), "w" ); if ( !fMakefile ) throw AccessDeniedException ( ProjectNode.makefile ); + MingwModuleHandler::SetMakefile ( fMakefile ); }
void @@ -89,27 +90,10 @@ void MingwBackend::ProcessModule ( Module& module ) { - MingwModuleHandlerList moduleHandlers; - GetModuleHandlers ( moduleHandlers ); - for (size_t i = 0; i < moduleHandlers.size (); i++) - { - MingwModuleHandler& moduleHandler = *moduleHandlers[i]; - if (moduleHandler.CanHandleModule ( module ) ) - { - moduleHandler.Process ( module ); - return; - } - } + MingwModuleHandler* h = MingwModuleHandler::LookupHandler ( module.name ); + h->Process ( module ); }
-void -MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const -{ - moduleHandlers.push_back ( new MingwBuildToolModuleHandler ( fMakefile ) ); - moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) ); - moduleHandlers.push_back ( new MingwStaticLibraryModuleHandler ( fMakefile ) ); -} - string FixupTargetFilename ( const string& targetFilename ) { _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/mingw.h 2005-01-09 01:58:53 UTC (rev 12900) @@ -4,26 +4,6 @@
#include "../backend.h" #include "modulehandler.h"
-class MingwModuleHandlerList : public std::vector<MingwModuleHandler*> -{ -public: - MingwModuleHandlerList() - { - } - ~MingwModuleHandlerList() - { - for ( size_t i = 0; i < size(); i++ ) - { - delete (*this)[i]; - } - } -private: - // disable copy semantics - MingwModuleHandlerList ( const MingwModuleHandlerList& ); - MingwModuleHandlerList& operator = ( const MingwModuleHandlerList& ); -}; - - class MingwBackend : public Backend { public: @@ -31,7 +11,6 @@ virtual void Process (); private: void ProcessModule ( Module& module ); - void GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const; void CreateMakefile (); void CloseMakefile (); void GenerateHeader (); _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .cpp 2005-01-09 01:58:53 UTC (rev 12900) @@ -8,12 +8,45 @@
using std::string; using std::vector; +using std::map;
-MingwModuleHandler::MingwModuleHandler ( FILE* fMakefile ) - : fMakefile ( fMakefile ) +map<const char*,MingwModuleHandler*>* +MingwModuleHandler::handler_map = NULL; + +FILE* +MingwModuleHandler::fMakefile = NULL; + +MingwModuleHandler::MingwModuleHandler ( const char* moduletype_ ) { + string moduletype ( moduletype_ ); + strlwr ( &moduletype[0] ); + if ( !handler_map ) + handler_map = new map<const char*,MingwModuleHandler*>; + (*handler_map)[moduletype.c_str()] = this; }
+/*static*/ void +MingwModuleHandler::SetMakefile ( FILE* f ) +{ + fMakefile = f; +} + +/*static*/ MingwModuleHandler* +MingwModuleHandler::LookupHandler ( const string& moduletype_ ) +{ + string moduletype ( moduletype_ ); + strlwr ( &moduletype[0] ); + if ( !handler_map ) + throw Exception ( "internal tool error: no registered module handlers" ); + MingwModuleHandler* h = (*handler_map)[moduletype.c_str()]; + if ( !h ) + { + throw UnknownModuleTypeException ( moduletype ); + return NULL; + } + return h; +} + string MingwModuleHandler::GetWorkingDirectory () const { @@ -352,7 +385,7 @@ string invokeTarget = module.GetInvocationTarget ( i ); fprintf ( fMakefile, "%s: %s\n\n", - invoke.GetTargets ().c_str (), + invoke.GetTargets ().c_str (), invokeTarget.c_str () ); fprintf ( fMakefile, "%s: %s\n", @@ -398,22 +431,17 @@ sourceFilenames.c_str (), preconditionDependenciesName.c_str ()); fprintf ( fMakefile, - ".PNONY: %s\n\n", + ".PHONY: %s\n\n", preconditionDependenciesName.c_str () ); }
+static MingwBuildToolModuleHandler buildtool_handler;
-MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( FILE* fMakefile ) - : MingwModuleHandler ( fMakefile ) +MingwBuildToolModuleHandler::MingwBuildToolModuleHandler() + : MingwModuleHandler ( "buildtool" ) { }
-bool -MingwBuildToolModuleHandler::CanHandleModule ( const Module& module ) const -{ - return module.type == BuildTool; -} - void MingwBuildToolModuleHandler::Process ( const Module& module ) { @@ -438,18 +466,13 @@ GenerateObjectFileTargetsHost ( module ); }
+static MingwKernelModuleHandler kernelmodule_handler;
-MingwKernelModuleHandler::MingwKernelModuleHandler ( FILE* fMakefile ) - : MingwModuleHandler ( fMakefile ) +MingwKernelModuleHandler::MingwKernelModuleHandler () + : MingwModuleHandler ( "kernelmodedll" ) { }
-bool -MingwKernelModuleHandler::CanHandleModule ( const Module& module ) const -{ - return module.type == KernelModeDLL; -} - void MingwKernelModuleHandler::Process ( const Module& module ) { @@ -505,18 +528,13 @@ GenerateObjectFileTargetsTarget ( module ); }
+static MingwStaticLibraryModuleHandler staticlibrary_handler;
-MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( FILE* fMakefile ) - : MingwModuleHandler ( fMakefile ) +MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler () + : MingwModuleHandler ( "staticlibrary" ) { }
-bool -MingwStaticLibraryModuleHandler::CanHandleModule ( const Module& module ) const -{ - return module.type == StaticLibrary; -} - void MingwStaticLibraryModuleHandler::Process ( const Module& module ) { _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .h --- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .h 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler .h 2005-01-09 01:58:53 UTC (rev 12900) @@ -6,9 +6,15 @@
class MingwModuleHandler { public: - MingwModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const = 0; + static std::map<const char*,MingwModuleHandler*>* handler_map; + + MingwModuleHandler ( const char* moduletype_ ); + virtual ~MingwModuleHandler() {} + + static void SetMakefile ( FILE* f ); + static MingwModuleHandler* LookupHandler ( const std::string& moduletype_ ); virtual void Process ( const Module& module ) = 0; + protected: std::string MingwModuleHandler::GetWorkingDirectory () const; std::string ReplaceExtension ( const std::string& filename, @@ -29,7 +35,7 @@ std::string GetInvocationParameters ( const Invoke& invoke ) const; void GenerateInvocations ( const Module& module ) const; void GeneratePreconditionDependencies ( const Module& module ) const; - FILE* fMakefile; + static FILE* fMakefile; private: std::string ConcatenatePaths ( const std::string& path1, const std::string& path2 ) const; @@ -49,8 +55,7 @@ class MingwBuildToolModuleHandler : public MingwModuleHandler { public: - MingwBuildToolModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const; + MingwBuildToolModuleHandler (); virtual void Process ( const Module& module ); private: void GenerateBuildToolModuleTarget ( const Module& module ); @@ -60,8 +65,7 @@ class MingwKernelModuleHandler : public MingwModuleHandler { public: - MingwKernelModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const; + MingwKernelModuleHandler (); virtual void Process ( const Module& module ); private: void GenerateKernelModuleTarget ( const Module& module ); @@ -71,8 +75,7 @@ class MingwStaticLibraryModuleHandler : public MingwModuleHandler { public: - MingwStaticLibraryModuleHandler ( FILE* fMakefile ); - virtual bool CanHandleModule ( const Module& module ) const; + MingwStaticLibraryModuleHandler (); virtual void Process ( const Module& module ); private: void GenerateStaticLibraryModuleTarget ( const Module& module ); _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp --- branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.cpp 2005-01-09 01:58:53 UTC (rev 12900) @@ -122,3 +122,9 @@
name.c_str() ) { } + +UnknownModuleTypeException::UnknownModuleTypeException ( const string& moduletype ) + : Exception ( "module type requested: '%s'", + moduletype.c_str() ) +{ +} _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/exception.h --- branches/xmlbuildsystem/reactos/tools/rbuild/exception.h 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/exception.h 2005-01-09 01:58:53 UTC (rev 12900) @@ -92,4 +92,10 @@
UnknownBackendException ( const std::string& name ); };
+class UnknownModuleTypeException : public Exception +{ +public: + UnknownModuleTypeException ( const std::string& moduletype ); +}; + #endif /* __EXCEPTION_H */ _____
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/pch.h --- branches/xmlbuildsystem/reactos/tools/rbuild/pch.h 2005-01-09 01:25:16 UTC (rev 12899) +++ branches/xmlbuildsystem/reactos/tools/rbuild/pch.h 2005-01-09 01:58:53 UTC (rev 12900) @@ -9,6 +9,7 @@
#include <string> #include <vector> +#include <map>
#include <stdarg.h>