ALBA
albaObjectFactory.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaObjectFactory
5 Authors: Based on itkObjectFactory (www.itk.org), adapted by Marco Petrone
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaObjectFactory_h
17#define __albaObjectFactory_h
18
20#include "albaSmartPointer.h"
21#include "albaString.h"
22
23#include <vector>
24#include <list>
25#include <map>
26#include <string>
27
29#define albaPlugObjectMacro(node_type,typeName) \
30 RegisterNewObject(node_type::GetStaticTypeName(), typeName, node_type::NewObject);
31
32typedef albaObject* (*albaCreateObjectFunction)();
33
34//------------------------------------------------------------------------------
35// Forward declarations
36//------------------------------------------------------------------------------
37class albaIndent;
38
51class ALBA_EXPORT albaObjectFactory : public albaReferenceCounted
52{
53public:
56
61 static albaObject *CreateInstance(const char* classname);
62
67 static std::list<albaObject *>
68 CreateAllInstance(const char* classname);
69
72 static void ReHash();
73
76
79
82
85 static std::list<albaObjectFactory*> GetRegisteredFactories();
86
92 virtual const char* GetALBASourceVersion(void) const = 0;
93
95 virtual const char* GetDescription(void) const = 0;
96
98 virtual std::list<std::string> GetClassOverrideNames();
99
101 virtual std::list<std::string> GetClassOverrideWithNames();
102
104 virtual std::list<std::string> GetClassOverrideTypeNames();
105
107 virtual std::list<bool> GetEnableFlags();
108
110 virtual void SetEnableFlag(bool flag,
111 const char* className,
112 const char* subclassName);
113
115 virtual bool GetEnableFlag(const char* className,
116 const char* subclassName);
117
122 virtual void Disable(const char* className);
123
125 const char* GetLibraryPath();
126
128 std::string GetObjectTypeName(const char* classname);
129
130
133 void RegisterNewObject(const char* ObjectName, const char* typeName, albaCreateObjectFunction createFunction,albaReferenceCounted *args=NULL);
134
136 void RegisterOverride(const char* classOverride,
137 const char* overrideClassName,
138 const char* typeName,
139 bool enableFlag,
140 albaCreateObjectFunction createFunction,
141 albaReferenceCounted *args=NULL);
142
144 albaReferenceCounted *GetArgs(const char *type_name);
145
149 {
150 std::string m_TypeName;
155 };
156
158 virtual void Print(std::ostream& os, const int indent=0) const;
159
162
163
164protected:
165
169 virtual albaObject *CreateObject(const char* classname );
170
172 albaReferenceCounted *GetFactoryArgs(const char *type_name);
173
174 //------------------------------------------------------------------------------
180 typedef std::multimap<std::string, mmuOverrideInformation> mmuOverRideMap;
181
183
184private:
185 albaObjectFactory(const albaObjectFactory&); //purposely not implemented
186 void operator=(const albaObjectFactory&); //purposely not implemented
187
190 static void Initialize();
191
193 static void RegisterDefaults();
194
196 static void LoadDynamicFactories();
197
199 static void LoadLibrariesInPath( const char*);
200
202 static std::list<albaObjectFactory*>* m_RegisteredFactories;
203
206 void* m_LibraryHandle;
207 unsigned long m_LibraryDate;
208 std::string m_LibraryPath;
209};
210
211#endif
212
albaObject *(* albaCreateObjectFunction)()
Hold a reference to a T instance.
albaIndent - a simple class to control print indentation.
Definition: albaIndent.h:31
Create instances of classes using an object factory.
virtual const char * GetALBASourceVersion(void) const =0
All sub-classes of albaObjectFactory should must return the version of ALBA they were built with.
static albaObject * CreateInstance(const char *classname)
Create and return an instance of the named object.
static void UnRegisterFactory(albaObjectFactory *)
Remove a factory from the list of registered factories.
virtual const char * GetDescription(void) const =0
Return a descriptive string describing the factory.
virtual void Print(std::ostream &os, const int indent=0) const
dump the object
static std::list< albaObjectFactory * > GetRegisteredFactories()
Return the list of all registered factories.
void RegisterOverride(const char *classOverride, const char *overrideClassName, const char *typeName, bool enableFlag, albaCreateObjectFunction createFunction, albaReferenceCounted *args=NULL)
Register object creation information with the factory.
const char * GetLibraryPath()
This returns the path to a dynamically loaded factory.
void RegisterNewObject(const char *ObjectName, const char *typeName, albaCreateObjectFunction createFunction, albaReferenceCounted *args=NULL)
This function can be used by Application code to register new Objects's to the albaCoreFactory.
static void RegisterFactory(albaObjectFactory *)
Register a factory so it can be used to create alba objects.
static void ReHash()
Re-check the ALBA_AUTOLOAD_PATH for new factory libraries.
virtual std::list< bool > GetEnableFlags()
Return a list of enable flags.
virtual std::list< std::string > GetClassOverrideNames()
Return a list of classes that this factory overrides.
virtual std::list< std::string > GetClassOverrideTypeNames()
Return a list of typeName for class overrides.
virtual void SetEnableFlag(bool flag, const char *className, const char *subclassName)
Set the Enable flag for the specific override of className.
virtual std::list< std::string > GetClassOverrideWithNames()
Return a list of the names of classes that override classes.
std::multimap< std::string, mmuOverrideInformation > mmuOverRideMap
albaStringOverMap - Internal implementation class for ObjectFactorBase.
virtual bool GetEnableFlag(const char *className, const char *subclassName)
Get the Enable flag for the specific override of className.
virtual void Disable(const char *className)
Set all enable flags for the given class to 0.
static std::list< albaObject * > CreateAllInstance(const char *classname)
Create and return all possible instances of the named object.
static void UnRegisterAllFactories()
Unregister all factories.
albaAbstractTypeMacro(albaObjectFactory, albaReferenceCounted)
Run-time type information (and related methods).
std::string GetObjectTypeName(const char *classname)
Returns the Object Type Name.
mmuOverRideMap * m_OverrideMap
albaReferenceCounted * GetFactoryArgs(const char *type_name)
internally used to retrieve args for this factory
virtual albaObject * CreateObject(const char *classname)
This method is provided by sub-classes of albaObjectFactory.
virtual ~albaObjectFactory()
albaReferenceCounted * GetArgs(const char *type_name)
return argument data assigned to object in the factory
Abstract superclass for all ALBA classes implementing RTTI APIs.
Definition: albaObject.h:38
albaReferenceCounted - abstract base class for ALBA objects with reference counting.
mmuOverrideInformation utility class.
albaAutoPointer< albaReferenceCounted > m_Args