This class stores metadata about the classes in the library. The stored information goes well beyond the standard 'type_info'. More...

#include <utils.h>

Inheritance diagram for frepple::utils::MetaClass:

Public Types

typedef Object *(* creatorDefault )()
 
typedef Object *(* creatorString )(const string &)
 

Public Member Functions

void connect (Functor *c, Signal a) const
 
void disconnect (Functor *c, Signal a) const
 
 MetaClass (const string &cat, const string &cls, bool def=false)
 
 MetaClass (const string &cat, const string &cls, creatorDefault f, bool def=false)
 
 MetaClass (const string &cat, const string &cls, creatorString f, bool def=false)
 
 MetaClass ()
 
bool operator!= (const MetaClass &b) const
 
bool operator< (const MetaClass &b) const
 
bool operator== (const MetaClass &b) const
 
bool raiseEvent (Object *v, Signal a) const
 
void registerClass (const string &, const string &, bool=false, creatorDefault=NULL)
 
virtual ~MetaClass ()
 

Static Public Member Functions

static Action decodeAction (const char *)
 
static Action decodeAction (const AttributeList &)
 
static const MetaClassfindClass (const char *)
 
static void printClasses ()
 

Public Attributes

union {
   creatorDefault   factoryMethodDefault
 
   creatorString   factoryMethodString
 
}; 
 
const MetaCategorycategory
 
PyTypeObject * pythonClass
 
string type
 
const Keywordtypetag
 

Friends

template<class T , class U >
class FunctorInstance
 
template<class T , class U >
class FunctorStatic
 
class MetaCategory
 

Additional Inherited Members

- Protected Member Functions inherited from frepple::utils::NonCopyable
 NonCopyable ()
 
 ~NonCopyable ()
 

Detailed Description

This class stores metadata about the classes in the library. The stored information goes well beyond the standard 'type_info'.

A MetaClass instance represents metadata for a specific instance type. A MetaCategory instance represents metadata for a category of object. For instance, 'Resource' is a category while 'ResourceDefault' and 'ResourceInfinite' are specific classes.
The metadata class also maintains subscriptions to certain events. Registered classes and objects will receive callbacks when objects are being created, changed or deleted.
The proper usage is to include the following code snippet in every class:

In the header file:
class X : public Object
{
public:
virtual const MetaClass& getType() {return *metadata;}
static const MetaClass *metadata;
}
In the implementation file:
const MetaClass *X::metadata;

Creating a MetaClass object isn't sufficient. It needs to be registered, typically in an initialization method:

void initialize()
{
...
Y::metadata = new MetaCategory("Y","Ys", reader_method, writer_method);
X::metadata = new MetaClass("Y","X", factory_method);
...
}
See Also
MetaCategory

Definition at line 946 of file utils.h.

Member Typedef Documentation

typedef Object*(* frepple::utils::MetaClass::creatorDefault)()

Type definition for a factory method calling the default constructor..

Definition at line 955 of file utils.h.

typedef Object*(* frepple::utils::MetaClass::creatorString)(const string &)

Type definition for a factory method calling the constructor that takes a string as argument.

Definition at line 959 of file utils.h.

Constructor & Destructor Documentation

virtual frepple::utils::MetaClass::~MetaClass ( )
inlinevirtual

Destructor.

Definition at line 982 of file utils.h.

frepple::utils::MetaClass::MetaClass ( const string &  cat,
const string &  cls,
bool  def = false 
)
inline

This constructor registers the metadata of a class.

Definition at line 989 of file utils.h.

frepple::utils::MetaClass::MetaClass ( const string &  cat,
const string &  cls,
creatorDefault  f,
bool  def = false 
)
inline

This constructor registers the metadata of a class, with a factory method that uses the default constructor of the class.

Definition at line 997 of file utils.h.

frepple::utils::MetaClass::MetaClass ( const string &  cat,
const string &  cls,
creatorString  f,
bool  def = false 
)
inline

This constructor registers the metadata of a class, with a factory method that uses a constructor with a string argument.

Definition at line 1006 of file utils.h.

frepple::utils::MetaClass::MetaClass ( )
inline

Default constructor.

Definition at line 1088 of file utils.h.

Member Function Documentation

void frepple::utils::MetaClass::connect ( Functor c,
Signal  a 
) const
inline

Connect a new subscriber to the class.

Definition at line 1072 of file utils.h.

Action frepple::utils::MetaClass::decodeAction ( const char *  x)
static

This function will analyze the string being passed, and return the appropriate action. The string is expected to be one of the following:

  • 'A' for action ADD
  • 'C' for action CHANGE
  • 'AC' for action ADD_CHANGE
  • 'R' for action REMOVE
  • Any other value will result in a data exception

Definition at line 471 of file utils/library.cpp.

Action frepple::utils::MetaClass::decodeAction ( const AttributeList atts)
static

This method picks up the attribute named "ACTION" from the list and calls the method decodeAction(const XML_Char*) to analyze it.

See Also
decodeAction(const XML_Char*)

Definition at line 483 of file utils/library.cpp.

void frepple::utils::MetaClass::disconnect ( Functor c,
Signal  a 
) const
inline

Disconnect a subscriber from the class.

Definition at line 1076 of file utils.h.

const MetaClass * frepple::utils::MetaClass::findClass ( const char *  c)
static

Find a particular class by its name. If it can't be located the return value is NULL.

Definition at line 434 of file utils/library.cpp.

bool frepple::utils::MetaClass::operator!= ( const MetaClass b) const
inline

Compare two metaclass objects. We are not always sure that only a single instance of a metadata object exists in the system, and a pointer comparison is therefore not appropriate.

See Also
operator ==
operator <

Definition at line 1057 of file utils.h.

bool frepple::utils::MetaClass::operator< ( const MetaClass b) const
inline

Sort two metaclass objects. This is used to sort entities on their type information in a stable and platform independent way.

See Also
operator !=
operator ==

Definition at line 1035 of file utils.h.

bool frepple::utils::MetaClass::operator== ( const MetaClass b) const
inline

Compare two metaclass objects. We are not always sure that only a single instance of a metadata object exists in the system, and a pointer comparison is therefore not appropriate.

See Also
operator !=
operator <

Definition at line 1046 of file utils.h.

void frepple::utils::MetaClass::printClasses ( )
static

Print all registered factory methods to the standard output for debugging purposes.

Definition at line 450 of file utils/library.cpp.

bool frepple::utils::MetaClass::raiseEvent ( Object v,
Signal  a 
) const

This method should be called whenever objects of this class are being created, updated or deleted. It will run the callback method of all subscribers.
If the function returns true, all callback methods approved of the event. If false is returned, one of the callbacks disapproved it and the event action should be allowed to execute.

Definition at line 491 of file utils/library.cpp.

void frepple::utils::MetaClass::registerClass ( const string &  a,
const string &  b,
bool  def = false,
creatorDefault  f = NULL 
)

Initialize the data structure and register the class.

Definition at line 323 of file utils/library.cpp.

Friends And Related Function Documentation

template<class T , class U >
friend class FunctorInstance
friend

Definition at line 950 of file utils.h.

template<class T , class U >
friend class FunctorStatic
friend

Definition at line 949 of file utils.h.

friend class MetaCategory
friend

Definition at line 948 of file utils.h.

Member Data Documentation

union { ... }
const MetaCategory* frepple::utils::MetaClass::category

The category of this class.

Definition at line 969 of file utils.h.

creatorDefault frepple::utils::MetaClass::factoryMethodDefault

Definition at line 977 of file utils.h.

creatorString frepple::utils::MetaClass::factoryMethodString

Definition at line 978 of file utils.h.

PyTypeObject* frepple::utils::MetaClass::pythonClass

A pointer to the Python type.

Definition at line 972 of file utils.h.

string frepple::utils::MetaClass::type

A string specifying the object type, i.e. the subclass within the category.

Definition at line 963 of file utils.h.

const Keyword* frepple::utils::MetaClass::typetag

A reference to an Keyword of the base string.

Definition at line 966 of file utils.h.


The documentation for this class was generated from the following files: