![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
#include <Reflection.h>
Classes | |
| class | Type |
Static Public Member Functions | |
| template<class ClassType > | |
| static ClassType | CastType (void *object) |
| template<class ClassType > | |
| static bool | ContainsType () |
| static size_t | GetSize (IReflect *object) |
| static IType * | GetType (const char *typeId) |
| static IType * | GetType (IReflect *object) |
| template<class ClassType > | |
| static IType * | GetType () |
| template<class ClassType > | |
| static const char * | GetTypeId () |
| static void | Release () |
Static Private Attributes | |
| static std::vector< IType * > | _types |
This is a static class which manages registration of reflective types To use a reflective type: 1) Create a class that inherits from IReflect 2) Call GetType passing in the class type, which registers the type 3) Use TypeManager to identify the type by its string name elsewhere in your program 4) Be sure to call "Release" to deallocate resources created during the registration process
Definition at line 60 of file Reflection.h.
| static ClassType TypeManager::CastType | ( | void * | object | ) | [inline, static] |
Casts the given void ptr into the template type NOTE: This returns null if the void ptr does not point to an object of the given type
Definition at line 230 of file Reflection.h.
{
if(object == NULL)
return NULL;
ClassType ret = (ClassType)object;
return dynamic_cast<ClassType>(ret);
}
| static bool TypeManager::ContainsType | ( | ) | [inline, static] |
Returns true if the type manager has the corresponding type already registered
Definition at line 139 of file Reflection.h.
References _types, and TypeManager::Type< ClassType >::getTypeId().
| static size_t TypeManager::GetSize | ( | IReflect * | object | ) | [inline, static] |
Gets the size of the given object instance NOTE: Must have been previously registered to be found NOTE: If type not found, returns 0
Definition at line 216 of file Reflection.h.
References IType::getSize(), and GetType().
| static IType* TypeManager::GetType | ( | const char * | typeId | ) | [inline, static] |
Gets the IType interface corresponding to the given typeId string NOTE: Type must be previously registered to be found NOTE: If type not found, returns NULL
Definition at line 178 of file Reflection.h.
References _types.
Gets the IType interface corresponding to the given object's type NOTE: Type must have been previously registed to be found NOTE: If type not found, returns NULL
Definition at line 192 of file Reflection.h.
References GetType().
{
const std::type_info& typeInfo = typeid(*object);
return GetType(typeInfo.name());
}
| static IType* TypeManager::GetType | ( | ) | [inline, static] |
Gets the IType interface corresponding to the given ClassType NOTE: This registers the type in this serializer, also preparing to use the type in future save/load actions
Definition at line 156 of file Reflection.h.
References _types, and TypeManager::Type< ClassType >::getTypeId().
Referenced by GetSize(), and GetType().
{
Type<ClassType>* type = new Type<ClassType>();
for(size_t i=0; i<_types.size(); ++i)
if(strcmp(_types[i]->getTypeId(), type->getTypeId()) == 0)
{
//delete type we created, we already have one
delete type;
return _types[i];
}
IType* ptr = dynamic_cast<IType*>(type);
//do not delete type, because now it's going into the vector
_types.push_back(ptr);
return ptr;
}
| static const char* TypeManager::GetTypeId | ( | ) | [inline, static] |
Gets the typeID of a given type NOTE: This does NOT register the type in the type manager This is intended to help with types unable to be captured in an IType
Definition at line 205 of file Reflection.h.
{
const std::type_info& typeInfo = typeid(ClassType);
return typeInfo.name();
}
| static void TypeManager::Release | ( | ) | [inline, static] |
std::vector< IType * > TypeManager::_types [static, private] |
This allocates the types vector (just declaring it in the .h is not enough)
Definition at line 63 of file Reflection.h.
Referenced by ContainsType(), GetType(), and Release().
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.