Fixed template

This commit is contained in:
Vulpovile
2023-11-03 23:56:59 -07:00
parent 25d34d28ee
commit 26398f0586
7 changed files with 245 additions and 16 deletions

View File

@@ -683,6 +683,22 @@
>
</File>
</Filter>
<Filter
Name="Reflection"
>
<File
RelativePath=".\src\source\Reflection\ReflectionDataTable.cpp"
>
</File>
</Filter>
<Filter
Name="DataModelV3"
>
<File
RelativePath=".\src\source\DataModelV3\Instance.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Header Files"
@@ -956,6 +972,34 @@
>
</File>
</Filter>
<Filter
Name="Reflection"
>
<File
RelativePath=".\src\include\Reflection\Reflection.h"
>
</File>
<File
RelativePath=".\src\include\Reflection\ReflectionDataTable.h"
>
</File>
<File
RelativePath=".\src\include\Reflection\ReflectionProperty.h"
>
</File>
<File
RelativePath=".\src\include\ReflectionProperty_imp.h"
>
</File>
</Filter>
<Filter
Name="DataModelV3"
>
<File
RelativePath=".\src\include\DataModelV3\Instance.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Resource Files"

View File

@@ -0,0 +1,49 @@
#pragma once
#define WINVER 0x0400
#include "Reflection/Reflection.h"
#include "Reflection/ReflectionDataTable.h"
#include "Reflection/ReflectionProperty.h"
#include <G3DAll.h>
namespace B3D
{
class Instance
{
public:
//Constructors
Instance(void);
Instance(const Instance&);
virtual ~Instance(void);
//Virtual Functions
virtual void render(RenderDevice*);
virtual void renderName(RenderDevice*);
virtual void update();
virtual void setParent(Instance*);
virtual Instance* clone() const { return new Instance(*this); }
//Functions
std::vector<Instance*> children; // All children.
std::string getClassName();
Instance* findFirstChild(std::string);
std::vector<Instance* > getChildren();
std::vector<Instance* > getAllChildren();
void setName(std::string newName);
void addChild(Instance*);
void removeChild(Instance*);
void clearChildren();
Instance* getParent();
//Variables
Reflection::ReflectionProperty<std::string> name;
protected:
//Constructor
//Used specifically to identify an instance class by an instance class,
//NOT for use outside of Instance and decendants!
Instance(std::string className);
//Variables
Reflection::ReflectionDataTable * dataTable;
Instance * parent;
};
}

View File

@@ -4,14 +4,13 @@
#include <map>
#include "ReflectionProperty.h"
namespace B3D{
namespace Instance{
class Instance;
}
class Instance;
namespace Reflection{
class ReflectionDataTable
{
public:
ReflectionDataTable(Instance::Instance * parentInstance, std::string className);
ReflectionDataTable(Instance * parentInstance, std::string className);
ReflectionDataTable::ReflectionDataTable(void);
~ReflectionDataTable(void);
@@ -20,7 +19,7 @@ namespace B3D{
//Perhaps not stored here?
std::string className;
std::map<std::string, B3D::Reflection::ReflectionProperty<void*>*> propertyTable;
Instance::Instance * parentInstance;
Instance * parentInstance;
};
}
}

View File

@@ -8,13 +8,13 @@ namespace B3D{
namespace Reflection{
class ReflectionDataTable;
template<typename T>
template<class T>
class ReflectionProperty
{
public:
T * value;
ReflectionType type;
ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable, bool archivable = true, bool locked = false, bool propertyHidden = false);
ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable);
ReflectionProperty(void);
~ReflectionProperty(void);
private:
@@ -25,4 +25,7 @@ namespace B3D{
ReflectionDataTable * containerTable;
};
}
}
}
//***really*** wanted to avoid implementing this inside of the header
#include "ReflectionProperty_imp.h"

View File

@@ -1,8 +1,7 @@
#include "Reflection\ReflectionProperty.h"
using namespace B3D::Reflection;
template<typename T>
ReflectionProperty<T>::ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable, bool archivable = true, bool locked = false, bool propertyHidden = false)
template<class T>
ReflectionProperty<T>::ReflectionProperty(T * value, ReflectionType type, ReflectionDataTable * containerTable)
{
this->value = value;
this->type = type;
@@ -12,12 +11,12 @@ ReflectionProperty<T>::ReflectionProperty(T * value, ReflectionType type, Reflec
this->propertyHidden = propertyHidden;
}
template<typename T>
template<class T>
ReflectionProperty<T>::ReflectionProperty(void)
{
}
template<typename T>
template<class T>
ReflectionProperty<T>::~ReflectionProperty(void)
{
}
}

View File

@@ -0,0 +1,135 @@
#include "DataModelV3/Instance.h"
using namespace B3D;
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);
}
Instance::Instance(void)
{
Instance::Instance("BaseInstance");
}
Instance::~Instance(void)
{
for(size_t i = 0; i < children.size(); i++)
{
delete children.at(i);
}
delete dataTable;
}
Instance::Instance(const Instance &oinst)
{
//CLONE WITH REFLECTION!!!
}
//Perhaps should be separated
void Instance::render(RenderDevice* rd)
{
for(size_t i = 0; i < children.size(); i++)
{
children[i]->render(rd);
}
}
void Instance::renderName(RenderDevice* rd)
{
for(size_t i = 0; i < children.size(); i++)
{
children[i]->renderName(rd);
}
}
void Instance::update()
{
}
void Instance::setName(std::string newName)
{
*name.value = newName;
}
std::string Instance::getClassName()
{
return dataTable->getClassName();
}
std::vector<Instance* > Instance::getChildren()
{
return children;
}
std::vector<Instance* > Instance::getAllChildren()
{
if(!children.empty())
{
std::vector<Instance* > totalchildren = children;
for(size_t i = 0; i < children.size(); i++)
{
std::vector<Instance* > subchildren = children.at(i)->getAllChildren();
if(!subchildren.empty())
totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end());
}
return totalchildren;
}
return children;
}
void Instance::setParent(Instance* newParent)
{
if(parent != NULL)
{
parent->removeChild(this);
}
parent = newParent;
if(newParent != NULL)
{
newParent->addChild(this);
}
}
Instance* Instance::getParent()
{
return parent;
}
void Instance::addChild(Instance* newChild)
{
children.push_back(newChild);
}
void Instance::clearChildren()
{
for (size_t i = 0; i < children.size(); i++)
{
delete children.at(i);
}
children.clear();
}
void Instance::removeChild(Instance* oldChild)
{
for(size_t i = 0; i < children.size(); i++)
{
if(children.at(i) == oldChild)
{
children.erase(children.begin() + i);
}
}
}
Instance* Instance::findFirstChild(std::string searchName)
{
for(size_t i = 0; i < children.size(); i++)
{
if(children.at(i)->name.value->compare(searchName) == 0)
{
return children.at(i);
}
}
return NULL;
}

View File

@@ -1,8 +1,8 @@
#include "Reflection\ReflectionDataTable.h"
#include "Reflection/ReflectionDataTable.h"
using namespace B3D::Reflection;
ReflectionDataTable::ReflectionDataTable(B3D::Instance::Instance * parentInstance, std::string className)
ReflectionDataTable::ReflectionDataTable(B3D::Instance * parentInstance, std::string className)
{
this->parentInstance = parentInstance;
this->className = className;