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>

Inheritance diagram for frepple::utils::MetaClass:
frepple::utils::NonCopyable frepple::utils::MetaCategory

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 MetaClassfindClass (const char *)
static void printClasses ()

Public Attributes

union {
   creatorDefault   factoryMethodDefault
   creatorString   factoryMethodString
   processorXMLInstruction   processingInstruction
}; 
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 1193 of file utils.h.


Member Typedef Documentation

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

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

Type definition for a method called to process an XML processing instruction.

Definition at line 1210 of file utils.h.


Constructor & Destructor Documentation

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

Destructor.

Definition at line 1234 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 1241 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 1249 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 1258 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 1267 of file utils.h.

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

Default constructor.

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

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 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 1337 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 1318 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 1296 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 1307 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

friend class FunctorInstance [friend]

Definition at line 1197 of file utils.h.

friend class FunctorStatic [friend]

Definition at line 1196 of file utils.h.

friend class MetaCategory [friend]

Definition at line 1195 of file utils.h.


Member Data Documentation

union { ... }

A factory method for the registered class.

The category of this class.

Definition at line 1220 of file utils.h.

Definition at line 1228 of file utils.h.

Definition at line 1229 of file utils.h.

Definition at line 1230 of file utils.h.

A pointer to the Python type.

Definition at line 1223 of file utils.h.

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

Definition at line 1214 of file utils.h.

A reference to an Keyword of the base string.

Definition at line 1217 of file utils.h.


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

Generated on 21 Mar 2010 for frePPLe by  doxygen 1.6.1