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)
|
||||
{
|
||||
name = "Default Game Instance";
|
||||
for(size_t i = 0; i < children.size(); i++)
|
||||
{
|
||||
delete children.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Instance::getClassName()
|
||||
@@ -23,6 +26,66 @@ std::string Instance::getClassName()
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user