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:

List of all members.

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)
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

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 939 of file utils.h.


Member Typedef Documentation

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

Definition at line 948 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 952 of file utils.h.


Constructor & Destructor Documentation

virtual frepple::utils::MetaClass::~MetaClass ( ) [inline, virtual]

Destructor.

Definition at line 975 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 982 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 990 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 999 of file utils.h.

frepple::utils::MetaClass::MetaClass ( ) [inline, protected]

Default constructor.

Definition at line 1082 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 1065 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 466 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 478 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 1069 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 429 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 1050 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 1028 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 1039 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 445 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 486 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 318 of file utils/library.cpp.


Friends And Related Function Documentation

friend class FunctorInstance [friend]

Definition at line 943 of file utils.h.

friend class FunctorStatic [friend]

Definition at line 942 of file utils.h.

friend class MetaCategory [friend]

Definition at line 941 of file utils.h.


Member Data Documentation

union { ... }

A factory method for the registered class.

The category of this class.

Definition at line 962 of file utils.h.

A pointer to the Python type.

Definition at line 965 of file utils.h.

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

Definition at line 956 of file utils.h.

A reference to an Keyword of the base string.

Definition at line 959 of file utils.h.


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

Documentation generated for frePPLe by  doxygen