Cafu Engine
cf::TypeSys Namespace Reference

The TypeSys ("type system") namespace provides classes for two related, but entirely independent concepts: More...

Classes

class  VarT
 This is a "wrapper" around a normal C++ variable. More...
 
class  VarArrayT
 This is a "wrapper" around a normal C++ variable specifically of type ArrayT<T>. More...
 
class  CreateParamsT
 
class  MethsDocT
 
class  VarsDocT
 
class  TypeInfoT
 This class keeps type information (about an entity class that occurs in the game). More...
 
class  TypeInfoManT
 This class manages the type infos. More...
 
class  VarBaseT
 This is the common base class for the VarT classes. More...
 
class  VisitorT
 This is the base class for the visitors of VarTs. More...
 
class  VisitorConstT
 Like VisitorT, but for const VarTs. More...
 
class  VarManT
 This class is a simple container for pointers to VarBaseTs. More...
 
class  VarVisitorGetToLuaT
 This visitor is used to implement a "get()" function in Lua: It pushes the value(s) of the visited variable onto the Lua stack. More...
 
class  VarVisitorSetFromLuaT
 This visitor is used to implement a "set()" function in Lua: It sets the value of the visited variable to the value(s) taken from the Lua stack. More...
 
class  VarVisitorSetFloatT
 This visitor is used to set float values in variables that are of type float, or composed of float. More...
 
class  VarVisitorToLuaCodeT
 This visitor writes the value of the visited variable into the given std::ostream, formatted as Lua code. More...
 

Detailed Description

The TypeSys ("type system") namespace provides classes for two related, but entirely independent concepts:

  • The TypeInfoT and TypeInfoManT classes provide meta-information about classes and class hierarchies.
  • The Var*T classes provide meta-information about class members. The rest of this text talks about the TypeInfo*T classes only: see the documentation of the Var*T classes for the second point. – TODO: update/revise this text accordingly!

The main purpose of the Type System is to make the programmers life easier when he is working with inheritance hierarchies of C++ classes. In many such cases, "meta" knowledge about the classes is required.

For example, when binding a hierarchy of C++ classes to Lua it is very helpful during Lua state initialization when we can iterate over all classes in the hierarchy (specially ordered so that bases classes always occur before their child classes). Additionally, classes should register themselves automatically in the data-structure for the iteration, so that adding new classes to the hierarchy is easy and doesn't require any changes elsewhere, such as to the Lua init code (a very convenient and important feature for MOD and game developers!). The TypeSys is employed for the game entities hierarchy (BaseEntityT), for which the TypeSys was initially invented, as well as the windows hierarchy of the GuiSys (cf::GuiSys::WindowT), which supports scripting as well.

Other uses directly suggest themselves from the details of the implementation, or were trivially added to the basic system:

  • Auto-assign each type a unique type number, e.g. for sending over the network. The type number is also "robust", i.e. independent of actual static initialization order.
  • Be able to iterate over all types (entity classes), e.g. for early initialization of the Lua state (adding a metatable for each entity class to the registry of the Lua state), or for listing all supported script methods (user help), etc.
  • Factory: Be able to instantiate an entity class by type name (e.g. from map file) or by type number (e.g. as received over the network). ( - Provide a faster means for dynamic_cast<>(). )

The Type System achieves its goals by explicitly modelling an inheritance hierarchy of C++ classes as a graph, which presents a "meta-layer" of information about the hierarchy and thus allows other C++ code to become conciously aware of the inheritance structure.