Shadowrun: Awakened 29 September 2011 - Build 871
Classes | Static Public Member Functions | Static Private Attributes
TypeManager Class Reference

#include <Reflection.h>

List of all members.

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 ITypeGetType (const char *typeId)
static ITypeGetType (IReflect *object)
template<class ClassType >
static ITypeGetType ()
template<class ClassType >
static const char * GetTypeId ()
static void Release ()

Static Private Attributes

static std::vector< IType * > _types

Detailed Description

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.


Member Function Documentation

template<class ClassType >
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);
    }
template<class ClassType >
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().

    {
        Type<ClassType> type;

        for(size_t i=0; i<_types.size(); ++i)
            if(strcmp(_types[i]->getTypeId(), type.getTypeId) == 0)
                return true;

        return false;
    }
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().

    {
        IType* type = GetType(object);
        if(type == NULL)
            return 0;
        return type->getSize();
    }
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.

    {
        for(size_t i=0; i<_types.size(); ++i)
            if(strcmp(_types[i]->getTypeId(), typeId) == 0)
                return _types[i];

        return NULL;
    }
static IType* TypeManager::GetType ( IReflect object) [inline, static]

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());
    }
template<class ClassType >
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;
    }
template<class ClassType >
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]

Releases the resources held by this singleton

Definition at line 126 of file Reflection.h.

References _types.

    {
        for(size_t i=0; i<_types.size(); ++i)
        {
            IType* t = _types[i];
            delete t;
        }
    }

Member Data Documentation

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().


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

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net