frepple::utils::MetaClass Class Reference
This class stores metadata about the classes in the library. The stored information goes well beyond the standard 'type_info'.
More...
#include <utils.h>
List of all members.
Public Types |
typedef Object *(* | creatorDefault )() |
typedef Object *(* | creatorString )(const string &) |
typedef void(* | processorXMLInstruction )(const char *d) |
Public Member Functions |
void | connect (Functor *c, Signal a) const |
void | disconnect (Functor *c, Signal a) const |
| MetaClass (const string &cat, const string &cls, processorXMLInstruction f, bool def=false) |
| MetaClass (const string &cat, const string &cls, creatorString f, bool def=false) |
| MetaClass (const string &cat, const string &cls, creatorDefault f, bool def=false) |
| MetaClass (const string &cat, const string &cls, bool def=false) |
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 AttributeList &) |
static Action | decodeAction (const char *) |
static const MetaClass * | findClass (const char *) |
static void | printClasses () |
Public Attributes |
union { |
creatorDefault factoryMethodDefault |
creatorString factoryMethodString |
processorXMLInstruction processingInstruction |
}; | |
const MetaCategory * | category |
PyTypeObject * | pythonClass |
string | type |
const Keyword * | typetag |
Protected Member Functions |
| MetaClass () |
Friends |
class | FunctorInstance |
class | FunctorStatic |
class | MetaCategory |
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 1022 of file utils.h.
Member Typedef Documentation
Type definition for a factory method calling the default constructor..
Definition at line 1031 of file utils.h.
Type definition for a factory method calling the constructor that takes a string as argument.
Definition at line 1035 of file utils.h.
Type definition for a method called to process an XML processing instruction.
Definition at line 1039 of file utils.h.
Constructor & Destructor Documentation
virtual frepple::utils::MetaClass::~MetaClass |
( |
|
) |
[inline, virtual] |
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 1070 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 1078 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 1087 of file utils.h.
frepple::utils::MetaClass::MetaClass |
( |
const string & |
cat, |
|
|
const string & |
cls, |
|
|
processorXMLInstruction |
f, |
|
|
bool |
def = false | |
|
) |
| | [inline] |
This constructor registers the metadata of a class as an XML processing instruction.
Definition at line 1096 of file utils.h.
frepple::utils::MetaClass::MetaClass |
( |
|
) |
[inline, protected] |
Default constructor.
Definition at line 1179 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 1162 of file utils.h.
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 380 of file utils/library.cpp.
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 368 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 1166 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 331 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 1147 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 1125 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 1136 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 347 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 388 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 220 of file utils/library.cpp.
Friends And Related Function Documentation
Member Data Documentation
A factory method for the registered class.
The category of this class.
Definition at line 1049 of file utils.h.
A pointer to the Python type.
Definition at line 1052 of file utils.h.
A string specifying the object type, i.e. the subclass within the category.
Definition at line 1043 of file utils.h.
The documentation for this class was generated from the following files: