FreeCAD C++
Public Member Functions | Static Public Member Functions | List of all members
Base::Type Class Reference

#include <Base/Type.h>

Detailed Description

Type system class Many of the classes in the FreeCAD must have their type information registered before any instances are created (including, but not limited to: App::Feature, App::Property, Gui::ViewProvider ). The use of Type to store this information provides lots of various functionality for working with class hierarchies, comparing class types, instantiating objects from classnames, etc etc.

It is for instance possible to do things like this:

void getRightFeature(Base::Base * anode)
{
assert(anode->getTypeId().isDerivedFrom(App::Feature::getClassTypeId()));
if (anode->getTypeId() == Mesh::MeshFeature::getClassTypeId()) {
// do something..
}
else if (anode->getTypeId() == Part::PartFeature::getClassTypeId()) {
// do something..
}
else {
Base::Console().Warning("getRightFeature", "Unknown feature type %s!\n",
anode->getTypeId().getName());
}
}

A notable feature of the Type class is that it is only 16 bits long and therefore should be passed around by value for efficiency reasons.

One important note about the use of Type to register class information: super classes must be registered before any of their derived classes are.

Public Member Functions

 Type (const Type &type)
 Construction.
 
virtual ~Type ()
 Destruction.
 
void * createInstance (void)
 creates a instance of this type
 

Static Public Member Functions

static void * createInstanceByName (const char *TypeName, bool bLoadModule=false)
 creates a instance of the named type