1#ifndef AMPGEN_FACTORY_H
2#define AMPGEN_FACTORY_H
10#define REGISTER( BASE_CLASS, DERIVED_CLASS ) \
11 std::string DERIVED_CLASS::_id = AmpGen::Factory<BASE_CLASS>::Register( #DERIVED_CLASS, new DERIVED_CLASS() )
12#define REGISTER_WITH_KEY( BASE_CLASS, DERIVED_CLASS, KEY, KEY_TYPE ) \
13 KEY_TYPE DERIVED_CLASS::_id = AmpGen::Factory<BASE_CLASS, KEY_TYPE>::Register( KEY, new DERIVED_CLASS() )
20 template <
class TYPE,
class KEY_TYPE = std::
string>
32 static TYPE*
get(
const KEY_TYPE& type,
const bool quiet =
false )
34 auto ptrToStatic =
getMe();
35 auto raw_base = ptrToStatic->m_terms.find( type );
36 if ( raw_base == ptrToStatic->m_terms.end() ) {
40 auto objectToReturn = raw_base->second->create();
41 return objectToReturn;
43 static KEY_TYPE
Register(
const KEY_TYPE& key, TYPE*
object )
45 getMe()->m_terms[key] = object;
50 template <
class TYPE,
class KEY_TYPE>
Static factory to construct classes from a hierarchy based on a key (normally std::string)
static Factory< TYPE, KEY_TYPE > * getMe()
static TYPE * get(const KEY_TYPE &type, const bool quiet=false)
static Factory< TYPE, KEY_TYPE > * gImpl
pointer to static implementation
static KEY_TYPE Register(const KEY_TYPE &key, TYPE *object)
std::map< KEY_TYPE, TYPE * > m_terms
map of objected made by this factory
#define ERROR(X)
Used for printing errors messages, and will always be printed.
std::string type_string()
Utility classes for compile-time metaprogramming, such as identifying the types of arguments for gene...