diff --git a/src/include/Reflection/Reflection.h b/src/include/Reflection/Reflection.h index ed4a424..f592c95 100644 --- a/src/include/Reflection/Reflection.h +++ b/src/include/Reflection/Reflection.h @@ -1,4 +1,6 @@ #pragma once +#include "ErrorFunctions.h" + namespace B3D{ namespace Reflection{ enum ReflectionType { diff --git a/src/include/Reflection/ReflectionDataTable.h b/src/include/Reflection/ReflectionDataTable.h index 511ca23..7e7afaf 100644 --- a/src/include/Reflection/ReflectionDataTable.h +++ b/src/include/Reflection/ReflectionDataTable.h @@ -15,10 +15,12 @@ namespace B3D{ ~ReflectionDataTable(void); std::string ReflectionDataTable::getClassName(void); + + void mapProperty(std::string key, ReflectionProperty* prop); private: //Perhaps not stored here? std::string className; - std::map*> propertyTable; + std::map*> propertyTable; Instance * parentInstance; }; } diff --git a/src/include/Reflection/ReflectionProperty.h b/src/include/Reflection/ReflectionProperty.h index c2ef4ac..1726051 100644 --- a/src/include/Reflection/ReflectionProperty.h +++ b/src/include/Reflection/ReflectionProperty.h @@ -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; diff --git a/src/include/ReflectionProperty_imp.h b/src/include/ReflectionProperty_imp.h index 80d1bbd..4d1ad50 100644 --- a/src/include/ReflectionProperty_imp.h +++ b/src/include/ReflectionProperty_imp.h @@ -1,7 +1,7 @@ using namespace B3D::Reflection; template -ReflectionProperty::ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable) +ReflectionProperty::ReflectionProperty(std::string key, T * value, ReflectionType type, ReflectionDataTable * containerTable) { this->value = value; this->type = type; @@ -9,6 +9,7 @@ ReflectionProperty::ReflectionProperty(T * value, ReflectionType type, Reflec this->locked = locked; this->archivable = archivable; this->propertyHidden = propertyHidden; + containerTable->mapProperty(key, (ReflectionProperty*)this); } template @@ -19,4 +20,11 @@ ReflectionProperty::ReflectionProperty(void) template ReflectionProperty::~ReflectionProperty(void) { +} + +template +void ReflectionProperty::dispose() +{ + delete value; + value = NULL; } \ No newline at end of file diff --git a/src/source/DataModelV3/Instance.cpp b/src/source/DataModelV3/Instance.cpp index bf7d444..2ab004d 100644 --- a/src/source/DataModelV3/Instance.cpp +++ b/src/source/DataModelV3/Instance.cpp @@ -6,7 +6,8 @@ Instance::Instance(std::string className) { this->parent = NULL; this->dataTable = new Reflection::ReflectionDataTable(this, className); - this->name = Reflection::ReflectionProperty(new std::string("Default Game Instance"), Reflection::TYPE_STRING, dataTable); + this->name = Reflection::ReflectionProperty("Name", new std::string("Level"), Reflection::TYPE_STRING, dataTable); + Reflection::ReflectionProperty("Name", new std::string("Level"), Reflection::TYPE_STRING, dataTable); } Instance::Instance(void) diff --git a/src/source/Reflection/ReflectionDataTable.cpp b/src/source/Reflection/ReflectionDataTable.cpp index 7268c03..37c8ee6 100644 --- a/src/source/Reflection/ReflectionDataTable.cpp +++ b/src/source/Reflection/ReflectionDataTable.cpp @@ -14,9 +14,23 @@ ReflectionDataTable::ReflectionDataTable(void) ReflectionDataTable::~ReflectionDataTable(void) { + std::map*>::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* prop) +{ + if(propertyTable.find(key) != propertyTable.end()) + { + throw std::string("Reflection error: Key") + key + std::string("already defined!"); + } + propertyTable[key] = prop; } \ No newline at end of file