Factory usage example. More...
#include <Factory.hxx>
Classes | |
class | Creator |
Abstract class for Creator objects which are stored in the Factory::Registry. More... | |
struct | Pair |
class | Registry |
This class is an implementation class of the Factory. More... | |
Public Types | |
typedef AbstractProductType | AbstractProduct |
typedef std::string | RegistryKey |
typedef std::list< Key > | Keys |
typedef std::list< std::string > | Values |
typedef std::list< Pair > | Pairs |
Public Member Functions | |
Factory () | |
~Factory () | |
AbstractProduct * | Create (const RegistryKey name) |
Gives ownership of the new created Product registered with the given name. | |
AbstractProduct * | CreateSafe (const RegistryKey name) throw (ErrFactory) |
Gives ownership of the new created Product registered with the given name. | |
void | Clear () |
void | AddCreator (const RegistryKey name, Creator *creator) |
void | AddCreatorWarningRepetitions (const RegistryKey name, Creator *creator) |
void | AddCreatorSafe (const RegistryKey name, Creator *creator) throw (ErrFactory) |
void | DeleteCreator (const RegistryKey name) |
void | GetRegisteredNames (std::list< std::string > &namesList) |
bool | KeyExists (const RegistryKey &key) |
bool | AttributeExists (const std::string &key, const std::string &attribute) |
Keys | GetKeys (const std::string &attribute, const std::string &value) |
Get all keys that have attribute==value in its metadata. | |
Keys | GetKeys () |
Get all keys in the factory. | |
Pairs | GetPairsFromKey (const std::string &key) |
Return all the metadata available for a product key. | |
Values | GetSetOfValues (const std::string &attribute) |
Get the set of all values present for a given metadata attribute. Example GetSetOfValues("category") could return ["modulators","generators","reverbs"] without repeated items. | |
Values | GetValuesFromAttribute (const std::string &key, const std::string &attribute) |
Return the list of values for a metadata attribute for a product key. | |
Value | GetValueFromAttribute (const std::string &key, const std::string &attribute) |
Return the value for a metadata attribute of product key. If multiple values exist returns the first value. | |
void | AddAttribute (const std::string &key, const std::string &attribute, const std::string &value) |
int | Count () |
Factory usage example.
To define a factory for your types you should create your own factory subclass.
// MyFactory.hxx class MyFactory : public CLAM::Factory<MyAbstractProduct> { public: static MyFactory& GetInstance(); };
You must define GetInstance() method in a .cxx
// MyFactory.cxx #include "MyFactory.hxx" MyFactory& MyFactory::GetInstance() { static MyFactory theInstance; return theInstance; }
To automatically register concrete products into the factory at program loading time (before "main()" starts), declare a registrator object like this:
// put this in a .cxx (not in a header) static CLAM::FactoryRegistrator<MyFactory, MyConcreteProduct> regMyConcreteProduct("MyConcreteProduct");
Definition at line 68 of file Factory.hxx.
typedef AbstractProductType CLAM::Factory< AbstractProductType >::AbstractProduct |
Definition at line 35 of file Factory.hxx.
typedef std::list<Key> CLAM::Factory< AbstractProductType >::Keys |
Definition at line 49 of file Factory.hxx.
typedef std::list<Pair> CLAM::Factory< AbstractProductType >::Pairs |
Definition at line 51 of file Factory.hxx.
typedef std::string CLAM::Factory< AbstractProductType >::RegistryKey |
Definition at line 36 of file Factory.hxx.
typedef std::list<std::string> CLAM::Factory< AbstractProductType >::Values |
Definition at line 50 of file Factory.hxx.
CLAM::Factory< AbstractProductType >::Factory | ( | ) | [inline] |
Definition at line 61 of file Factory.hxx.
CLAM::Factory< AbstractProductType >::~Factory | ( | ) | [inline] |
Definition at line 62 of file Factory.hxx.
void CLAM::Factory< AbstractProductType >::AddAttribute | ( | const std::string & | key, | |
const std::string & | attribute, | |||
const std::string & | value | |||
) | [inline] |
Definition at line 165 of file Factory.hxx.
Referenced by RunTimeLadspaLibraryLoader::SetupLibrary().
void CLAM::Factory< AbstractProductType >::AddCreator | ( | const RegistryKey | name, | |
Creator * | creator | |||
) | [inline] |
Definition at line 97 of file Factory.hxx.
void CLAM::Factory< AbstractProductType >::AddCreatorSafe | ( | const RegistryKey | name, | |
Creator * | creator | |||
) | throw (ErrFactory) [inline] |
Definition at line 107 of file Factory.hxx.
void CLAM::Factory< AbstractProductType >::AddCreatorWarningRepetitions | ( | const RegistryKey | name, | |
Creator * | creator | |||
) | [inline] |
Definition at line 102 of file Factory.hxx.
Referenced by RunTimeLadspaLibraryLoader::SetupLibrary().
bool CLAM::Factory< AbstractProductType >::AttributeExists | ( | const std::string & | key, | |
const std::string & | attribute | |||
) | [inline] |
Definition at line 127 of file Factory.hxx.
void CLAM::Factory< AbstractProductType >::Clear | ( | ) | [inline] |
Definition at line 92 of file Factory.hxx.
int CLAM::Factory< AbstractProductType >::Count | ( | ) | [inline] |
Definition at line 466 of file Factory.hxx.
AbstractProduct* CLAM::Factory< AbstractProductType >::Create | ( | const RegistryKey | name | ) | [inline] |
Gives ownership of the new created Product registered with the given name.
It asserts that the name is in the registry.
Definition at line 74 of file Factory.hxx.
AbstractProduct* CLAM::Factory< AbstractProductType >::CreateSafe | ( | const RegistryKey | name | ) | throw (ErrFactory) [inline] |
Gives ownership of the new created Product registered with the given name.
It throws an ErrFactory if the name isn't found in the registry.
Definition at line 86 of file Factory.hxx.
Referenced by CLAM::ProcessingDefinitionAdapter::LoadFrom().
void CLAM::Factory< AbstractProductType >::DeleteCreator | ( | const RegistryKey | name | ) | [inline] |
Definition at line 112 of file Factory.hxx.
Referenced by RunTimeLibraryLoader::ReLoad().
Keys CLAM::Factory< AbstractProductType >::GetKeys | ( | ) | [inline] |
Get all keys in the factory.
Definition at line 138 of file Factory.hxx.
Keys CLAM::Factory< AbstractProductType >::GetKeys | ( | const std::string & | attribute, | |
const std::string & | value | |||
) | [inline] |
Get all keys that have attribute==value in its metadata.
Definition at line 133 of file Factory.hxx.
Referenced by RunTimeLibraryLoader::ReLoad().
Pairs CLAM::Factory< AbstractProductType >::GetPairsFromKey | ( | const std::string & | key | ) | [inline] |
Return all the metadata available for a product key.
Definition at line 143 of file Factory.hxx.
void CLAM::Factory< AbstractProductType >::GetRegisteredNames | ( | std::list< std::string > & | namesList | ) | [inline] |
Definition at line 117 of file Factory.hxx.
Values CLAM::Factory< AbstractProductType >::GetSetOfValues | ( | const std::string & | attribute | ) | [inline] |
Get the set of all values present for a given metadata attribute. Example GetSetOfValues("category") could return ["modulators","generators","reverbs"] without repeated items.
Definition at line 149 of file Factory.hxx.
Referenced by RunTimeLibraryLoader::GetUsedLibraries().
Value CLAM::Factory< AbstractProductType >::GetValueFromAttribute | ( | const std::string & | key, | |
const std::string & | attribute | |||
) | [inline] |
Return the value for a metadata attribute of product key. If multiple values exist returns the first value.
Definition at line 160 of file Factory.hxx.
Values CLAM::Factory< AbstractProductType >::GetValuesFromAttribute | ( | const std::string & | key, | |
const std::string & | attribute | |||
) | [inline] |
Return the list of values for a metadata attribute for a product key.
Definition at line 154 of file Factory.hxx.
bool CLAM::Factory< AbstractProductType >::KeyExists | ( | const RegistryKey & | key | ) | [inline] |
Definition at line 122 of file Factory.hxx.