Basic Image AlgorithmS Library
2.8.0
|
simple factory class designed for usage as a singleton More...
#include <Base/Common/BaseFactory.hh>
Classes | |
struct | MapEntry |
struct for storing class details in member map Map_ More... | |
Public Types | |
typedef BaseClassType *(* | AllocatorFunctionPointer )() |
typedef for function pointer to class allocator function More... | |
Public Member Functions | |
void | Add2Directories (const std::string &directories) |
This function only makes sense when shared libraries are used: Initialize the factory with ':' (linux) or ';' (windows) separated list of directories and a lib_prefix. More... | |
void | AddType (AllocatorFunctionPointer allocFunc) |
This function is only meaningfull, when static libraries are used. More... | |
void | Clear () |
empties the map, and unloads all shared libraries More... | |
BaseClassType * | Generate (const TagType &tag) |
function for generic class generation from More... | |
int | GetKnownTags (std::vector< TagType > &tags) const |
Searches for all available modules and gives all their tag. More... | |
int | GetLoadedFiles (std::vector< TagType > &tags, std::vector< std::string > &files) const |
Get all tags and associated filenames of all modules which have been loaded already. More... | |
void | GetNearTag (const TagType &tag, TagType &t1, TagType &t2) const |
void | SetPrefix (const std::string &prefix) |
This function only makes sense when shared libraries are used: Set the prefix used i. More... | |
Static Public Member Functions | |
static BaseFactory < BaseClassType, TagType > * | GetInstance () |
static char | GetSeperator () |
Protected Member Functions | |
BaseFactory () | |
private constructor, the factory is designed as a singleton More... | |
BaseFactory (const BaseFactory &b) | |
void | GetKnownTags_ (std::vector< TagType > &tags, const std::string &directory) const |
This function is onyl meaningfull when shared libraries are used: Search for all libraries with names lib${lib_prefix}*.so (linux) resp. More... | |
bool | IsInMap_ (const TagType &tag) const |
checks if tag is already in map More... | |
int | OpenDll_ (const std::string &tag) |
This function is onyl meaningfull when shared libraries are used: open file and store handle in DllMap. More... | |
BaseFactory & | operator= (const BaseFactory &b) |
~BaseFactory () | |
destructor More... | |
Static Protected Member Functions | |
static void | DeleteInstance_ () |
static pthread_mutex_t * | Mutex_ () |
Protected Attributes | |
std::vector< std::string > | Directories_ |
These members are onyl meaningfull when shared libraries are used. More... | |
std::map< TagType, MapEntry > | Map_ |
tag - class allocator correspondences are stored in this map More... | |
std::string | Prefix_ |
std::map< TagType, std::string > | TagToFileMap_ |
Static Protected Attributes | |
static BaseFactory < BaseClassType, TagType > * | Instance_ |
Private Member Functions | |
void | AddDebugLevel (const long int lv) |
void | AddDebugLevel (const std::string &name) |
long | ConsumeNextFreeDebuglevel_ () |
returns the next available debuglevel More... | |
bool | DebugLevelIsSet (const long int lv) const |
bool | DebugLevelIsSet (const std::string &name) const |
int | GetDebugLevel () const |
std::ostream & | GetDebugStream () const |
void | GetDebugStream (std::ostream &os) const |
long int | Name2DebugLevel (const std::string &name) const |
looks up a debuglevel in the internal map, returns 0 if not found More... | |
long int | NewDebugLevel (const std::string &name) |
creates a new debuglevel More... | |
void | PrintDebugLevel (std::ostream &os=std::cout) const |
void | RemoveDebugLevel (const long int lv) |
void | RemoveDebugLevel (const std::string &name) |
void | SetDebugLevel (const long int lv) |
void | SetDebugLevel (const std::string &name) |
void | SetDebugStream (const std::ostream &os) |
void | ShowDebugLevel (std::ostream &os=std::cout) const |
prints all internally known debuglevels More... | |
Static Private Member Functions | |
static long int | GetGlobalDebugLevel () |
static void | SetGlobalDebugLevel (long int lev) |
Private Attributes | |
long int | _liDebugLevel |
long int | _liNextDebugLevel |
new concept, debuglevel are managed here in the debug class More... | |
std::map< std::string, long int > | _String2Debuglevel |
Static Private Attributes | |
static std::ostream | _zDebugStream |
static long int | GlobalDebugLevel = 0 |
Friends | |
std::ostream & | operator<< (std::ostream &os, const BaseFactory< BaseClassType, TagType > &bf) |
class | Singleton< BaseFactory< BaseClassType, TagType > > |
the singleton must be able to use the base factory More... | |
simple factory class designed for usage as a singleton
The factory differenciates between being used in a context with dynamic libraries (*.so / *.dll) and being used in a static library context (*.a / *.a). In a dynamic library context, the factory looks for possible candidates for creation by itself by searching certain directories. These directories are set using the Add2Directories() function. Each library with name lib${PREFIX}*.so / ${PREFIX}*.dll is investigated. If it contains a C-style function with signature Base *create(); The associated class can be created with the factory. The create function is very simple and typically created by adding /code #ifdef BIAS_BUILD_SHARED_LIBS extern "C" TFModuleBase *create() { return new TFMSpecialModule();} extern "C" void destroy(TFModuleBase *p) { delete p; } #endif /endcode to the TFMSpecialModule.cpp file. In a static library context, the factory must be manually made aware of the different classes which it manages. This is typically done by calling the AddType() function of the directory. Instantiate this class with the desired base class as template argument. The base class must provide the functions - TagType BaseClassType::GetTag() const The instantiation will fail otherwise. Exemplary usage: /code typedef tag_type std::string class Base { public: Base(const tag_type& name) : Name_(name) {} void Who() { cout << "I am "<<Name_<<endl; } inline tag_type GetTag() const { return Name_; } tag_type Name_; }; class A : public Base { public: A() : Base("a") {}; static Base *Allocator() { return dynamic_cast<Base *>(new A); } }; class B : public Base { public: B() : Base("b") {}; static Base *Allocator() { return dynamic_cast<Base *>(new B); } }; BaseFactory<Base, tag_type> *factory = FactorySingleton<Base, tag_type>::Factory.GetInstance(); #ifdef BIAS_BUILD_SHARED_LIBS
Make sure class A compiles in a library libMyPrefixA.so and that this library contains a C-style function similar to Base *create() { return new A; } The corresponding must be ensured for class B and each class managed by the factory factory->SetPrefix("MyPrefix"); factory->Add2Directories("directory where libMyPrefixA.so resides"); factory->Add2Directories("directory where libMyPrefixB.so resides"); #else populate the factory (only necessary with static factories) factory->AddType(&A::Allocator); factory->AddType(&B::Allocator); #endif
Base *p = factory->Generate("a");
/endcode
Definition at line 49 of file BaseFactory.hh.
typedef BaseClassType*(* BIAS::BaseFactory< BaseClassType, TagType >::AllocatorFunctionPointer)() |
typedef for function pointer to class allocator function
Definition at line 148 of file BaseFactory.hh.
|
protected |
private constructor, the factory is designed as a singleton
Definition at line 263 of file BaseFactory.hh.
|
protected |
Definition at line 270 of file BaseFactory.hh.
|
protected |
destructor
Definition at line 277 of file BaseFactory.hh.
void BIAS::BaseFactory< BaseClassType, TagType >::Add2Directories | ( | const std::string & | directories | ) |
This function only makes sense when shared libraries are used: Initialize the factory with ':' (linux) or ';' (windows) separated list of directories and a lib_prefix.
All shared libraries in the given directories with names lib${lib_prefix}*.so (linux) resp. ${lib_prefix}*.dll (windows) are opened. An object can only be created when the library contains a c-style function with the signature BaseClass *create() and hence all libraries not containing this symbol are neglected.
Definition at line 290 of file BaseFactory.hh.
void BIAS::BaseFactory< BaseClassType, TagType >::AddType | ( | AllocatorFunctionPointer | allocFunc | ) |
This function is only meaningfull, when static libraries are used.
add a new class entry to map
Definition at line 421 of file BaseFactory.hh.
void BIAS::BaseFactory< BaseClassType, TagType >::Clear | ( | ) |
empties the map, and unloads all shared libraries
Definition at line 444 of file BaseFactory.hh.
|
staticprotectedinherited |
BaseClassType * BIAS::BaseFactory< BaseClassType, TagType >::Generate | ( | const TagType & | tag | ) |
function for generic class generation from
Definition at line 325 of file BaseFactory.hh.
|
staticinherited |
int BIAS::BaseFactory< BaseClassType, TagType >::GetKnownTags | ( | std::vector< TagType > & | tags | ) | const |
Searches for all available modules and gives all their tag.
Definition at line 398 of file BaseFactory.hh.
|
protected |
This function is onyl meaningfull when shared libraries are used: Search for all libraries with names lib${lib_prefix}*.so (linux) resp.
${lib_prefix}*.dll (windows) are opened. An object can only be created when the library contains a c-style function with the signature BaseClass *create() and hence all libraries not containing this symbol are neglected.
Definition at line 553 of file BaseFactory.hh.
int BIAS::BaseFactory< BaseClassType, TagType >::GetLoadedFiles | ( | std::vector< TagType > & | tags, |
std::vector< std::string > & | files | ||
) | const |
Get all tags and associated filenames of all modules which
have been loaded already.
Definition at line 637 of file BaseFactory.hh.
void BIAS::BaseFactory< BaseClassType, TagType >::GetNearTag | ( | const TagType & | tag, |
TagType & | t1, | ||
TagType & | t2 | ||
) | const |
Definition at line 353 of file BaseFactory.hh.
|
inlinestatic |
Definition at line 151 of file BaseFactory.hh.
|
inlineprotected |
checks if tag is already in map
Definition at line 237 of file BaseFactory.hh.
References BIAS::BaseFactory< BaseClassType, TagType >::Map_.
|
staticprotectedinherited |
|
protected |
This function is onyl meaningfull when shared libraries are used: open file and store handle in DllMap.
Definition at line 468 of file BaseFactory.hh.
References BIAS::BaseFactory< BaseClassType, TagType >::MapEntry::AllocatorFunction_.
|
protected |
Definition at line 284 of file BaseFactory.hh.
void BIAS::BaseFactory< BaseClassType, TagType >::SetPrefix | ( | const std::string & | prefix | ) |
This function only makes sense when shared libraries are used: Set the prefix used i.
Definition at line 315 of file BaseFactory.hh.
|
friend |
|
friend |
the singleton must be able to use the base factory
Definition at line 203 of file BaseFactory.hh.
|
protected |
These members are onyl meaningfull when shared libraries are used.
Definition at line 226 of file BaseFactory.hh.
|
staticprotectedinherited |
static members
Definition at line 98 of file Singleton.hh.
|
protected |
tag - class allocator correspondences are stored in this map
Definition at line 219 of file BaseFactory.hh.
Referenced by BIAS::BaseFactory< BaseClassType, TagType >::IsInMap_(), and BIAS::operator<<().
|
protected |
Definition at line 227 of file BaseFactory.hh.
|
protected |
Definition at line 222 of file BaseFactory.hh.