mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-31 19:26:42 +00:00
much better factory implementation - thanks art yerkes
svn path=/branches/xmlbuildsystem/; revision=12846
This commit is contained in:
@@ -9,25 +9,29 @@
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
vector<Backend::Factory*> Backend::factories;
|
||||
vector<Backend::Factory*>* Backend::Factory::factories = NULL;
|
||||
|
||||
/*static*/ void
|
||||
Backend::InitFactories()
|
||||
Backend::Factory::Factory ( const std::string& name_ )
|
||||
: name(name_)
|
||||
{
|
||||
factories.push_back ( new Factory ( "mingw", MingwBackend::Factory ) );
|
||||
if ( !factories )
|
||||
factories = new vector<Factory*>;
|
||||
factories->push_back ( this );
|
||||
}
|
||||
|
||||
/*static*/ Backend*
|
||||
Backend::Create ( const std::string& name, Project& project )
|
||||
Backend::Factory::Create ( const std::string& name, Project& project )
|
||||
{
|
||||
string sname ( name );
|
||||
strlwr ( &sname[0] );
|
||||
if ( !factories.size() )
|
||||
if ( !factories || !factories->size() )
|
||||
throw Exception ( "internal tool error: no registered factories" );
|
||||
for ( size_t i = 0; i < factories.size(); i++ )
|
||||
vector<Backend::Factory*>& fact = *factories;
|
||||
for ( size_t i = 0; i < fact.size(); i++ )
|
||||
{
|
||||
if ( sname == factories[i]->name )
|
||||
return (factories[i]->factory) ( project );
|
||||
//char* p = *fact[i];
|
||||
if ( sname == fact[i]->name )
|
||||
return (*fact[i]) ( project );
|
||||
}
|
||||
throw UnknownBackendException ( sname );
|
||||
return NULL;
|
||||
|
||||
@@ -9,24 +9,24 @@ typedef Backend* BackendFactory ( Project& project );
|
||||
|
||||
class Backend
|
||||
{
|
||||
public:
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
static std::vector<Factory*>* factories;
|
||||
std::string name;
|
||||
BackendFactory* factory;
|
||||
|
||||
Factory ( const std::string& name_, BackendFactory* factory_ )
|
||||
: name(name_), factory(factory_)
|
||||
{
|
||||
}
|
||||
protected:
|
||||
|
||||
Factory ( const std::string& name_ );
|
||||
|
||||
virtual Backend* operator() ( Project& ) = 0;
|
||||
|
||||
public:
|
||||
static Backend* Create ( const std::string& name, Project& project );
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
static std::vector<Factory*> factories;
|
||||
|
||||
public:
|
||||
static void InitFactories();
|
||||
static Backend* Create ( const std::string& name, Project& project );
|
||||
|
||||
protected:
|
||||
Backend ( Project& project );
|
||||
|
||||
|
||||
@@ -6,11 +6,15 @@
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
Backend*
|
||||
MingwBackend::Factory ( Project& project )
|
||||
static class MingwFactory : public Backend::Factory
|
||||
{
|
||||
return new MingwBackend ( project );
|
||||
}
|
||||
public:
|
||||
MingwFactory() : Factory ( "mingw" ) {}
|
||||
Backend* operator() ( Project& project )
|
||||
{
|
||||
return new MingwBackend ( project );
|
||||
}
|
||||
} factory;
|
||||
|
||||
#ifdef WIN32
|
||||
#define EXEPOSTFIX ".exe"
|
||||
|
||||
@@ -20,10 +20,7 @@ public:
|
||||
class MingwBackend : public Backend
|
||||
{
|
||||
public:
|
||||
static Backend* Factory ( Project& project );
|
||||
protected:
|
||||
MingwBackend ( Project& project );
|
||||
public:
|
||||
virtual void Process ();
|
||||
private:
|
||||
void ProcessModule ( Module& module );
|
||||
|
||||
@@ -17,7 +17,6 @@ using std::vector;
|
||||
int
|
||||
main ( int argc, char** argv )
|
||||
{
|
||||
Backend::InitFactories();
|
||||
if ( argc != 2 )
|
||||
{
|
||||
printf ( "syntax: rbuild {buildtarget}\n" );
|
||||
@@ -29,7 +28,7 @@ main ( int argc, char** argv )
|
||||
{
|
||||
string projectFilename ( "ReactOS.xml" );
|
||||
Project project ( projectFilename );
|
||||
Backend* backend = Backend::Create ( buildtarget, project );
|
||||
Backend* backend = Backend::Factory::Create ( buildtarget, project );
|
||||
backend->Process ();
|
||||
delete backend;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user