OpenLexocad  27.1
Base::Type Class Reference

#include <Type.h>

Public Types

typedef void *(* instantiationMethod) (void)
 

Public Member Functions

 Type (const Type &type)
 Construction. More...
 
 Type (void)
 
virtual ~Type ()
 Destruction. More...
 
void * createInstance (void)
 creates a instance of this type More...
 
const Type getParent (void) const
 
void getChildren (std::set< Type > &children) const
 
void getAllChildren (std::set< Type > &children) const
 
bool isDerivedFrom (const Type type) const
 
bool isDerivedFrom (const std::vector< Base::Type > &types) const
 
unsigned int getKey (void) const
 
bool isBad (void) const
 
const std::string & getName (void) const
 
void operator= (const Type type)
 
bool operator== (const Type type) const
 
bool operator!= (const Type type) const
 
bool operator< (const Type type) const
 
bool operator<= (const Type type) const
 
bool operator>= (const Type type) const
 
bool operator> (const Type type) const
 

Static Public Member Functions

static void * createInstanceByName (const char *TypeName, bool bLoadModule=false)
 creates a instance of the named type More...
 
static Type fromName (const char *name)
 
static int getAllDerivedFrom (const Type type, std::vector< Type > &List)
 Returns all types derived from type. More...
 
static std::vector< TypegetAllDerivedFrom (const Type type)
 
static std::string getHierarchyAsString (Base::Type t)
 Returns the hierarchy of type t in backward order as a string. More...
 
static int getNumTypes (void)
 
static const Type createType (const Type parent, const char *name, instantiationMethod method=0)
 
static const Type badType (void)
 
static void init (void)
 

Static Protected Member Functions

static std::string getModuleName (const char *ClassName)
 

Detailed Description

Type system class Many of the classes in the Lexocad must have their type information registered before any instances are created (including, but not limited to: Object, Property... ). 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->isDerivedFrom<App::Feature>());
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.

Member Typedef Documentation

◆ instantiationMethod

typedef void*(* Base::Type::instantiationMethod) (void)

Constructor & Destructor Documentation

◆ Type() [1/2]

Base::Type::Type ( const Type type)

Construction.

◆ Type() [2/2]

Base::Type::Type ( void  )

◆ ~Type()

virtual Base::Type::~Type ( )
virtual

Destruction.

Member Function Documentation

◆ badType()

static const Type Base::Type::badType ( void  )
inlinestatic

◆ createInstance()

void* Base::Type::createInstance ( void  )

creates a instance of this type

◆ createInstanceByName()

static void* Base::Type::createInstanceByName ( const char *  TypeName,
bool  bLoadModule = false 
)
static

creates a instance of the named type

◆ createType()

static const Type Base::Type::createType ( const Type  parent,
const char *  name,
instantiationMethod  method = 0 
)
static

◆ fromName()

static Type Base::Type::fromName ( const char *  name)
static

◆ getAllChildren()

void Base::Type::getAllChildren ( std::set< Type > &  children) const
inline

◆ getAllDerivedFrom() [1/2]

static int Base::Type::getAllDerivedFrom ( const Type  type,
std::vector< Type > &  List 
)
static

Returns all types derived from type.

◆ getAllDerivedFrom() [2/2]

static std::vector<Type> Base::Type::getAllDerivedFrom ( const Type  type)
static

◆ getChildren()

void Base::Type::getChildren ( std::set< Type > &  children) const
inline

◆ getHierarchyAsString()

static std::string Base::Type::getHierarchyAsString ( Base::Type  t)
static

Returns the hierarchy of type t in backward order as a string.

◆ getKey()

unsigned int Base::Type::getKey ( void  ) const
inline

◆ getModuleName()

static std::string Base::Type::getModuleName ( const char *  ClassName)
staticprotected

◆ getName()

const std::string& Base::Type::getName ( void  ) const

◆ getNumTypes()

static int Base::Type::getNumTypes ( void  )
static

◆ getParent()

const Type Base::Type::getParent ( void  ) const
inline

◆ init()

static void Base::Type::init ( void  )
static

◆ isBad()

bool Base::Type::isBad ( void  ) const
inline

◆ isDerivedFrom() [1/2]

bool Base::Type::isDerivedFrom ( const Type  type) const
inline

◆ isDerivedFrom() [2/2]

bool Base::Type::isDerivedFrom ( const std::vector< Base::Type > &  types) const
inline

◆ operator!=()

bool Base::Type::operator!= ( const Type  type) const
inline

◆ operator<()

bool Base::Type::operator< ( const Type  type) const
inline

◆ operator<=()

bool Base::Type::operator<= ( const Type  type) const
inline

◆ operator=()

void Base::Type::operator= ( const Type  type)
inline

◆ operator==()

bool Base::Type::operator== ( const Type  type) const
inline

◆ operator>()

bool Base::Type::operator> ( const Type  type) const
inline

◆ operator>=()

bool Base::Type::operator>= ( const Type  type) const
inline

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