VCF::Class Class Reference
Class is the base class for all RTTI in the Framework.
More...
#include <vcf/FoundationKit/Class.h>
List of all members.
Detailed Description
Class is the base class for all RTTI in the Framework.
Class was written because C++ RTTI is shockingly primitive, and many of these features are found in other OO languages (i.e. ObjectPascal, ObjectiveC, SmallTalk, Java, et. al) and are immensely useful and powerful.
Class is an abstract base class that template class's derive from. Classes provide the following information:
- the name of the Class - this is stored in a member variable rather than relying on typeid().name() to retreive the class name. Not all compiler's support the typeid().name() function (i.e. MSVC 6.0 does, Borland probably does, but GCC does not)
- the Class ID - this represents a UUID for the class. This will prove useful when distributed features creep in.
- the ability to discover all the properties of a Class at runtime. A property is defined as some class attribute that is provided access to via getter and setter methods. Properties can be primitive types (int, long double, etc) or Object derived types, or enums. Properties can also be collections of other properties.
- retreiving the super class of the class.
- the ability to create a new instance of the class the Class object represents. This of course assumes a default constructor is available.
In order for the RTTI to work in the Framework developers of derived classes must do three things for their classes to participate in the Framework. Failure to implement these steps will mean their classes will not have correct RTTI. A series of macros (defined in
ClassInfo.h) have been written to make this easier.
The first step is (obviously) making sure that your class is derived from a Framework object. For example:
class Foo : public VCF::Object {
...
};
class Foo {
...
};
Next you should define a class id (as a string) for your class. If you are on winblows use guidgen.exe to create UUID's for you. The define should look something like this:
#define FOO_CLASSID "1E8CBE21-2915-11d4-8E88-00207811CFAB"
The next step is to add to macros to your class defintion (.h/.hpp file). These are required for the basic RTTI info (class-super class relation ships) and to make sure you'll inherit any properties of your super class. For example:
The macros create a public nested class used to register your class that you're writing. The above macros generate the following inline code for the developer of the Foo class.
class Foo : public VCF::Object {
class Foo_rtti_ClassInfo : public VCF::ClassInfo<Foo> {
public:
typedef Foo RttiClassType;
Foo_rtti_ClassInfo ():
VCF::ClassInfo<RttiClassType>( VCF::StringUtils::getClassNameFromTypeInfo(typeid(Foo)),
"VCF::Object",
"1E8CBE21-2915-11d4-8E88-00207811CFAB" ){
VCF::String tmpClassName = VCF::StringUtils::getClassNameFromTypeInfo(typeid(Foo));
if ( isClassRegistered() ){
}
}
};
...
};
The next step is to add any properties to the class. This is optional and is only neccessary if the you want to expose the properties of the class you're writing. Adding properties is also done through macros and looks like this:
class Foo : public VCF::Object {
_class_rtti_(Foo, "VCF::Object", FOO_CLASSID)
_property_( double, "fooVal", getFooVal, setFooVal, "The foo value property" )
_class_rtti_end_
...
double getFooVal();
void setFooVal( const double& val );
...
};
If the properties are
Object derived properties then the following can be done:
class Foo : public VCF::Object {
_class_rtti_(Foo, "VCF::Object", FOO_CLASSID)
_property_object_( Foo, "fooObj", getFoo, setFoo, "The Foo object property" )
_class_rtti_end_(Foo)
...
Foo* getFoo();
void setFoo( Foo* val );
...
};
- Author:
- Jim Crafton
- Version:
- 1.0
Constructor & Destructor Documentation
| VCF::Class::Class |
( |
const String & |
className, |
|
|
const String & |
classID, |
|
|
const String & |
superClass |
|
) |
|
|
|
|
the constructor for a new Class.
- Parameters:
-
| String | the class name of the class |
| String | the class id for the class. This MUST be a string that represents unique ID as returned by a UUID function/algorithm the format is this: 96B6A350-2873-11d4-8E88-00207811CFAB |
| String | the name of the class's super class |
|
| virtual VCF::Class::~Class |
( |
|
) |
[virtual] |
|
Member Function Documentation
|
|
Adds an event to the Class.
- Parameters:
-
|
| void VCF::Class::addField |
( |
Field * |
field |
) |
|
|
|
|
adds a new property to the Class's property map.
|
| void VCF::Class::addMethod |
( |
Method * |
method |
) |
|
|
|
|
adds a new property to the Class's property map.
|
| void VCF::Class::addProperty |
( |
Property * |
property |
) |
|
|
|
|
adds a new property to the Class's property map.
|
| virtual bool VCF::Class::compareObject |
( |
const Object * |
object |
) |
const [pure virtual] |
|
|
|
Used to compare the object instance passed in with the class type.
Implemented in the template derived class so a type safe compare is made. |
| virtual Object* VCF::Class::createInstance |
( |
|
) |
const [pure virtual] |
|
|
|
creates a new instance of an Object based on the Class Type.
Actual implementation is performed by the template instance of the class. |
| String VCF::Class::getClassName |
( |
|
) |
const |
|
|
|
returns the class name for the Class
|
| static String VCF::Class::getClassNameForProperty |
( |
Property * |
property |
) |
[static] |
|
|
|
returns the class name of a Property.
This will also return the correct type for C++ basic pritives (i.e. int, bool, etc) |
|
|
Returns an DelegateProperty by name.
- Parameters:
-
| String | the event delegate to return |
|
|
|
returns an enumerator containing the DelegateProperty values.
the enumerator does not reflect the order in which the events were added. |
| Field* VCF::Class::getField |
( |
const String & |
fieldName |
) |
const |
|
|
|
gets the field (or member variable) specified by fieldName, if the class has that field.
- Parameters:
-
| String | the name of the field to try and retrieve |
- Returns:
- Field a pointer to a field of the class.
|
| uint32 VCF::Class::getFieldCount |
( |
|
) |
const |
|
|
|
the number of fields the Class has
|
|
|
returns an enumerator containing the Field values the enumerator does not reflect the order in which the fields were added.
|
| String VCF::Class::getID |
( |
|
) |
const |
|
|
|
returns the class id for the class.
Class's may have the same name so to prevent this, an ID is provided. This is ID MUST be generated using some algorithm that guarantees a valid UUID |
| uint32 VCF::Class::getInterfaceCount |
( |
|
) |
const |
|
|
|
Returns an enumeration of interfaces implemented by this class.
|
| Method* VCF::Class::getMethod |
( |
const String & |
methodName |
) |
const |
|
|
|
gets the method specified by methodName, if the class has that method.
- Parameters:
-
| String | the name of the method to try and retrieve |
- Returns:
- Method a pointer to a method of the class.
|
| uint32 VCF::Class::getMethodCount |
( |
|
) |
const |
|
|
|
the number of methods the Class has
|
|
|
returns an enumerator containing the Methods of the Class the enumerator does not reflect the order in which the properties were added.
|
|
|
returns an enumerator containing the Property values the enumerator does not reflect the order in which the properties were added.
|
| Property* VCF::Class::getProperty |
( |
const String & |
propertyName |
) |
const |
|
|
|
gets the property specified by propertyName, if the class has that property.
- Parameters:
-
| String | the name of the property to try and retrieve |
- Returns:
- Property a pointer to a property of the class.
|
| uint32 VCF::Class::getPropertyCount |
( |
|
) |
const |
|
|
|
the number of properties the Class has
|
| Class* VCF::Class::getSuperClass |
( |
|
) |
const |
|
| bool VCF::Class::hasDelegate |
( |
const String & |
delegateName |
) |
const |
|
|
|
does the Class have this particular event handler ?
- Returns:
- bool returns true if the Class has an event handler by this name
|
| bool VCF::Class::hasField |
( |
const String & |
fieldName |
) |
const |
|
|
|
does the Class have a have a particular property ?
- Parameters:
-
| String | the name of the property to find |
- Returns:
- bool true if the class has the specified property, otherwise false
|
| bool VCF::Class::hasInterface |
( |
const String & |
interfaceName |
) |
const |
|
| bool VCF::Class::hasInterfaceID |
( |
const String & |
interfaceID |
) |
const |
|
| bool VCF::Class::hasMethod |
( |
const String & |
methodName |
) |
const |
|
|
|
does the Class have a have a particular property ?
- Parameters:
-
| String | the name of the property to find |
- Returns:
- bool true if the class has the specified property, otherwise false
|
| bool VCF::Class::hasProperty |
( |
const String & |
propertyName |
) |
const |
|
|
|
does the Class have a have a particular property ?
- Parameters:
-
| String | the name of the property to find |
- Returns:
- bool true if the class has the specified property, otherwise false
|
| virtual bool VCF::Class::isEqual |
( |
const Object * |
object |
) |
const [inline, virtual] |
|
|
|
compares an object to the stored object instance.
This uses typeid which is OK in GCC. The actual compare is made in compareObject() which is implemented in the derived Template classes - Parameters:
-
- Returns:
- bool true if the object's typeid is equal to this' typeid
|
| void VCF::Class::setSource |
( |
const Object * |
source |
) |
|
|
| void VCF::Class::setSource |
( |
Object * |
source |
) |
|
|
|
|
sets the source of all properties in the Class to source.
- Parameters:
-
| Object | the source to which the properties are set |
|
| uint32 VCF::Class::sizeOf |
( |
|
) |
const |
|
The documentation for this class was generated from the following file: