Finished base for new datamodel
This commit is contained in:
65
Instance.cpp
65
Instance.cpp
@@ -15,7 +15,10 @@ Instance::Instance(void)
|
|||||||
|
|
||||||
Instance::~Instance(void)
|
Instance::~Instance(void)
|
||||||
{
|
{
|
||||||
name = "Default Game Instance";
|
for(size_t i = 0; i < children.size(); i++)
|
||||||
|
{
|
||||||
|
delete children.at(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Instance::getClassName()
|
std::string Instance::getClassName()
|
||||||
@@ -23,6 +26,66 @@ std::string Instance::getClassName()
|
|||||||
return className;
|
return className;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<Instance* > Instance::getChildren()
|
||||||
|
{
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Instance* > Instance::getAllChildren()
|
||||||
|
{
|
||||||
|
std::vector<Instance* > totalchildren = children;
|
||||||
|
for(size_t i = 0; i < children.size(); i++)
|
||||||
|
{
|
||||||
|
std::vector<Instance* > subchildren = children.at(i)->getAllChildren();
|
||||||
|
totalchildren.insert(totalchildren.end(), subchildren.begin(), subchildren.end());
|
||||||
|
}
|
||||||
|
return totalchildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
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::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 name)
|
||||||
|
{
|
||||||
|
Instance* child = NULL;
|
||||||
|
for(size_t i = 0; i < children.size(); i++)
|
||||||
|
{
|
||||||
|
if(children.at(i)->name == name)
|
||||||
|
{
|
||||||
|
child = children.at(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ public:
|
|||||||
Instance* parent; // Another pointer.
|
Instance* parent; // Another pointer.
|
||||||
std::vector<Instance*> children; // All children.
|
std::vector<Instance*> children; // All children.
|
||||||
std::string getClassName();
|
std::string getClassName();
|
||||||
|
Instance* findFirstChild(std::string);
|
||||||
|
std::vector<Instance* > getChildren();
|
||||||
|
std::vector<Instance* > getAllChildren();
|
||||||
|
void setParent(Instance*);
|
||||||
|
void addChild(Instance*);
|
||||||
|
void removeChild(Instance*);
|
||||||
|
Instance* getParent();
|
||||||
protected:
|
protected:
|
||||||
std::string className;
|
std::string className;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user