Added reflection memory cleanup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
#include "ErrorFunctions.h"
|
||||
|
||||
namespace B3D{
|
||||
namespace Reflection{
|
||||
enum ReflectionType {
|
||||
|
||||
@@ -15,10 +15,12 @@ namespace B3D{
|
||||
~ReflectionDataTable(void);
|
||||
|
||||
std::string ReflectionDataTable::getClassName(void);
|
||||
|
||||
void mapProperty(std::string key, ReflectionProperty<void*>* prop);
|
||||
private:
|
||||
//Perhaps not stored here?
|
||||
std::string className;
|
||||
std::map<std::string, B3D::Reflection::ReflectionProperty<void*>*> propertyTable;
|
||||
std::map<std::string, ReflectionProperty<void*>*> propertyTable;
|
||||
Instance * parentInstance;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,11 +12,14 @@ namespace B3D{
|
||||
class ReflectionProperty
|
||||
{
|
||||
public:
|
||||
//Could be private?
|
||||
std::string key;
|
||||
T * value;
|
||||
ReflectionType type;
|
||||
ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable);
|
||||
ReflectionProperty(std::string key, T * value, ReflectionType type, ReflectionDataTable * containerTable);
|
||||
ReflectionProperty(void);
|
||||
~ReflectionProperty(void);
|
||||
void dispose();
|
||||
private:
|
||||
std::string propertyName;
|
||||
bool archivable;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using namespace B3D::Reflection;
|
||||
|
||||
template<class T>
|
||||
ReflectionProperty<T>::ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable)
|
||||
ReflectionProperty<T>::ReflectionProperty(std::string key, T * value, ReflectionType type, ReflectionDataTable * containerTable)
|
||||
{
|
||||
this->value = value;
|
||||
this->type = type;
|
||||
@@ -9,6 +9,7 @@ ReflectionProperty<T>::ReflectionProperty(T * value, ReflectionType type, Reflec
|
||||
this->locked = locked;
|
||||
this->archivable = archivable;
|
||||
this->propertyHidden = propertyHidden;
|
||||
containerTable->mapProperty(key, (ReflectionProperty<void*>*)this);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@@ -19,4 +20,11 @@ ReflectionProperty<T>::ReflectionProperty(void)
|
||||
template<class T>
|
||||
ReflectionProperty<T>::~ReflectionProperty(void)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void ReflectionProperty<T>::dispose()
|
||||
{
|
||||
delete value;
|
||||
value = NULL;
|
||||
}
|
||||
@@ -6,7 +6,8 @@ Instance::Instance(std::string className)
|
||||
{
|
||||
this->parent = NULL;
|
||||
this->dataTable = new Reflection::ReflectionDataTable(this, className);
|
||||
this->name = Reflection::ReflectionProperty<std::string>(new std::string("Default Game Instance"), Reflection::TYPE_STRING, dataTable);
|
||||
this->name = Reflection::ReflectionProperty<std::string>("Name", new std::string("Level"), Reflection::TYPE_STRING, dataTable);
|
||||
Reflection::ReflectionProperty<std::string>("Name", new std::string("Level"), Reflection::TYPE_STRING, dataTable);
|
||||
}
|
||||
|
||||
Instance::Instance(void)
|
||||
|
||||
@@ -14,9 +14,23 @@ ReflectionDataTable::ReflectionDataTable(void)
|
||||
|
||||
ReflectionDataTable::~ReflectionDataTable(void)
|
||||
{
|
||||
std::map<std::string, ReflectionProperty<void*>*>::iterator it;
|
||||
for (it = propertyTable.begin(); it != propertyTable.end(); it++)
|
||||
{
|
||||
it->second->dispose();
|
||||
}
|
||||
}
|
||||
|
||||
std::string ReflectionDataTable::getClassName(void)
|
||||
{
|
||||
return className;
|
||||
}
|
||||
|
||||
void ReflectionDataTable::mapProperty(std::string key, ReflectionProperty<void*>* prop)
|
||||
{
|
||||
if(propertyTable.find(key) != propertyTable.end())
|
||||
{
|
||||
throw std::string("Reflection error: Key") + key + std::string("already defined!");
|
||||
}
|
||||
propertyTable[key] = prop;
|
||||
}
|
||||
Reference in New Issue
Block a user