ContRap-Core
|
This file contains the meta information and meta registration implementation. More...
#include <string>
#include <list>
#include <map>
#include "core/error.h"
#include "core/coreexports.h"
#include "core/pointer.h"
#include <iostream>
#include <vector>
#include <typeinfo>
Data Structures | |
class | crp::ObjectFactory |
Object factory provides an interface for instantiating objects from a string holding the type. More... | |
Namespaces | |
namespace | crp |
The namespace crp is the namespace for all ContRap core components and libraries. | |
Defines | |
#define | CONTRAP_STRING_(a) #a |
Subsitution macro. | |
#define | CONTRAP_STRING(a) CONTRAP_STRING_(a) |
#define | CONTRAP_OBJECT(_name, _base, _mangle) |
Meta implementation macro for objects. | |
#define | CONTRAP_OBJECT_NOASSIGN(_name, _base, _mangle) |
Meta implementation macro for non assignable object. | |
#define | CONTRAP_OBJECT_DESTRUCTOR(_name, _base, _release, _mangle) |
Meta implementation macro for objects which require a different destructor function, like containers of pointers. | |
#define | CONTRAP_STRUCT(_name, _release, _mangle) |
Meta implementation macro for structures. | |
#define | CONTRAP_STRUCT_ASSIGN(_name, _construct, _copy, _release, _mangle) |
Meta implementation macro for structures with a custom assignment procedure. | |
#define | CONTRAP_TYPE(_name, _release, _mangle) |
Meta implementation macro for other types, e.g. | |
#define | CONTRAP_TYPE_NODESTR(_name, _release) |
Meta implementation macro for types which should not be destroyed. | |
Functions | |
CONTRAP_CORE_API void | crp::dummy_destructor (void *) |
Dummy destructor function which does nothing. |
This file contains the meta information and meta registration implementation.
This file is a part of ContRap.
Copyright (c) 2009-2010 by Aless Lasaruk. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of ContRap nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define CONTRAP_OBJECT | ( | _name, | |
_base, | |||
_mangle | |||
) |
bool _new_ ## _mangle(void* _object) { return true; } \ bool _copy_ ## _mangle(const void* rvalue, void* lvalue) \ { *reinterpret_cast<_name*>(lvalue) = *reinterpret_cast<const _name*>(rvalue); return true; } \ bool _cast_ ## _mangle(const void* _object) { \ return dynamic_cast<const _name*>(reinterpret_cast<const _base*>(_object)); } \ void _destroy_ ## _mangle(const void* data) { if (data) delete (reinterpret_cast<const _name*>(data)); } \ static crp::MetaInfo _mangle ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_base), \ _new_ ## _mangle, _copy_ ## _mangle, _cast_ ## _mangle, _destroy_ ## _mangle);
Meta implementation macro for objects.
_name | Name of the class which should be registered for usage with ContRap |
_base | Absolute base class of the the given class |
_mangle | Name of the prefix used to define the meta methods. This is fortunately needed to effectively use namespaces. |
NOTICE: The meta cast function can only be called if the two objects are in the same hierarchy
#define CONTRAP_OBJECT_DESTRUCTOR | ( | _name, | |
_base, | |||
_release, | |||
_mangle | |||
) |
bool _new_ ## _mangle(void* object) { return true; } \ bool _copy_ ## _mangle(const void* rvalue, void* lvalue) { *((_name*)lvalue) = *((_name*)rvalue); return true; } \ bool _cast_ ## _mangle(const void* _object) { return (dynamic_cast<_name*>((_base*)_object)); } \ void _destroy_ ## _mangle(const void* data) { if (data) { _release((_name*)data); delete ((_name*)data); } } \ static crp::MetaInfo _mangle ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_base), \ _new_ ## _mangle, _copy_ ## _mangle, _cast_ ## _mangle, _destroy_ ## _mangle);
Meta implementation macro for objects which require a different destructor function, like containers of pointers.
_name | Name of the class which should be registered for usage with ContRap |
_base | Absolute base class of the the given class |
_release | Function which takes a pointer to the structure and releases its contents |
_mangle | Name of the prefix used to define the meta methods. This is fortunately needed to effectively use namespaces and modifiers. |
#define CONTRAP_OBJECT_NOASSIGN | ( | _name, | |
_base, | |||
_mangle | |||
) |
bool _new_ ## _mangle(void* object) { return true; } \ bool _copy_ ## _mangle(const void* rvalue, void* lvalue) { return false; } \ bool _cast_ ## _mangle(const void* _object) { return (dynamic_cast<_name*>((_base*)_object)); } \ void _destroy_ ## _mangle(const void* data) { if (data) delete ((_name*)data); } \ static crp::MetaInfo _mangle ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_base), \ _new_ ## _mangle, _copy_ ## _mangle, _cast_ ## _mangle, _destroy_ ## _mangle);
Meta implementation macro for non assignable object.
_name | Name of the class which should be registered for usage with ContRap |
_base | Absolute base class of the the given class |
_mangle | Name of the prefix used to define the meta methods. This is fortunately needed to effectively use namespaces. |
#define CONTRAP_STRING | ( | a | ) | CONTRAP_STRING_(a) |
#define CONTRAP_STRING_ | ( | a | ) | #a |
Subsitution macro.
#define CONTRAP_STRUCT | ( | _name, | |
_release, | |||
_mangle | |||
) |
bool _new_ ## _mangle(void* object) { return true; } \ void _destroy_ ## _mangle(const void* data) { if (data) { _release((_name*)data); delete ((_name*)data); } } \ bool _copy_ ## _mangle(const void* rvalue, void* lvalue) { *((_name*)lvalue) = *((_name*)rvalue); return true; } \ bool _cast_ ## _mangle(const void* _object) { return (dynamic_cast<_name*>((_name*)_object)); } \ static crp::MetaInfo _mangle ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_name), \ _new_ ## _mangle, _copy_ ## _mangle, _cast_ ## _mangle, _destroy_ ## _mangle);
Meta implementation macro for structures.
_name | Name of the structure |
_release | Function which takes a pointer to the structure and releases its contents |
_mangle | Name of the prefix used to define the meta methods. This is fortunately needed to effectively use namespaces and modifiers. |
#define CONTRAP_STRUCT_ASSIGN | ( | _name, | |
_construct, | |||
_copy, | |||
_release, | |||
_mangle | |||
) |
bool _new_ ## _mangle(void* object) { _construct(reinterpret_cast<_name*>(object)); return true; } \ bool _copy_ ## _mangle(const void* rvalue, void* lvalue) { _copy((_name*)rvalue,(_name*)lvalue); return true; } \ bool _cast_ ## _mangle(const void* _object) { return (dynamic_cast<_name*>((_name*)_object)); } \ void _destroy_ ## _mangle(const void* data) { if (data) { _release((_name*)data); delete ((_name*)data); } } \ static crp::MetaInfo _mangle ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_name), \ _new_ ## _mangle, _copy_ ## _mangle, _cast_ ## _mangle, _destroy_ ## _mangle);
Meta implementation macro for structures with a custom assignment procedure.
_name | Name of the structure |
_construct | Construction function of the struct |
_assign | Copy method for the structure |
_release | Function which takes a pointer to the structure and releases its contents |
_mangle | Name of the prefix used to define the meta methods. This is fortunately needed to effectively use namespaces and modifiers. |
#define CONTRAP_TYPE | ( | _name, | |
_release, | |||
_mangle | |||
) |
bool _new_ ## _mangle(void* object) { return true; } \ bool _copy_ ## _mangle(const void* rvalue, void* lvalue) { *((_name*)lvalue) = *((_name*)rvalue); return true;} \ bool _cast_ ## _mangle(const void* _object) { return true; } \ void _destroy_ ## _mangle(const void* data) { if (data) { _release((_name*)data); delete ((_name*)data); } } \ static crp::MetaInfo _mangle ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_name), \ _new_ ## _mangle, _copy_ ## _mangle, _cast_ ## _mangle, _destroy_ ## _mangle);
Meta implementation macro for other types, e.g.
C-types, which can not be dynamically casted
_name | Name of the structure |
_release | Function which takes a pointer to the structure and releases its contents |
_mangle | Name of the prefix used to define the meta methods. This is fortunately needed to effectively use namespaces and modifiers. |
#define CONTRAP_TYPE_NODESTR | ( | _name, | |
_release | |||
) |
bool _new_ ## _name(void* object) { return true; } \ bool _copy_ ## _name(const void* rvalue, void* lvalue) { *((_name*)lvalue) = *((_name*)rvalue); return true;} \ bool _cast_ ## _name(const void* _object) { return true; } \ void _destroy_ ## _name(const void* data) { if (data) { _release((_name*)data); } } \ static crp::MetaInfo _name ## _meta_info(# _name, sizeof(_name), &typeid(_name), &typeid(_name), \ _new_ ## _name, _copy_ ## _name, _cast_ ## _name, _destroy_ ## _name);
Meta implementation macro for types which should not be destroyed.
_name | Name of the structure |
_release | Function which takes a pointer to the structure and releases its contents |