2013-10-30 11:46:18 +00:00
|
|
|
#include "BaseDefinition.h"
|
|
|
|
|
2013-11-03 12:00:31 +00:00
|
|
|
#include "PackStream.h"
|
|
|
|
|
2013-10-30 11:46:18 +00:00
|
|
|
BaseDefinition::BaseDefinition(BaseDefinition* parent):
|
|
|
|
parent(parent)
|
|
|
|
{
|
2013-10-30 14:39:56 +00:00
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
root = parent->root;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
root = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseDefinition::~BaseDefinition()
|
|
|
|
{
|
|
|
|
QListIterator<BaseDefinition*> it(children);
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
delete it.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-31 16:59:18 +00:00
|
|
|
void BaseDefinition::setName(QString name)
|
2013-10-30 14:39:56 +00:00
|
|
|
{
|
2013-10-31 16:59:18 +00:00
|
|
|
this->name = name;
|
2013-10-30 14:39:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 19:07:35 +00:00
|
|
|
void BaseDefinition::save(PackStream* pack) const
|
2013-10-30 14:39:56 +00:00
|
|
|
{
|
2013-10-31 16:59:18 +00:00
|
|
|
pack->write(name);
|
2013-10-30 14:39:56 +00:00
|
|
|
QListIterator<BaseDefinition*> it(children);
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
it.next()->save(pack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseDefinition::load(PackStream* pack)
|
|
|
|
{
|
2013-10-31 16:59:18 +00:00
|
|
|
name = pack->readString();
|
2013-10-30 14:39:56 +00:00
|
|
|
QListIterator<BaseDefinition*> it(children);
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
it.next()->load(pack);
|
|
|
|
}
|
2013-10-30 11:46:18 +00:00
|
|
|
}
|
2013-10-31 16:59:18 +00:00
|
|
|
|
2013-11-13 19:07:35 +00:00
|
|
|
void BaseDefinition::copy(BaseDefinition* destination) const
|
2013-10-31 16:59:18 +00:00
|
|
|
{
|
2013-10-31 23:09:51 +00:00
|
|
|
destination->setName(name);
|
|
|
|
// can't copy children as we don't know their types...
|
2013-10-31 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseDefinition::validate()
|
|
|
|
{
|
|
|
|
QListIterator<BaseDefinition*> it(children);
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
|
|
|
it.next()->validate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseDefinition::addChild(BaseDefinition* child)
|
|
|
|
{
|
|
|
|
if (not children.contains(child))
|
|
|
|
{
|
|
|
|
children.append(child);
|
|
|
|
child->parent = this;
|
|
|
|
child->root = this->root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseDefinition::removeChild(BaseDefinition* child)
|
|
|
|
{
|
|
|
|
children.removeOne(child);
|
|
|
|
}
|