/***************************************************************************
* Copyright (C) 2004 - 2005 by Raphael Langerhorst *
* raphael-langerhorst@gmx.at *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
* OTHER DEALINGS IN THE SOFTWARE. *
***************************************************************************/
#include "GObject.h"
#include "GElementID.h"
#include "GEnergy.h"
#include "GForm.h"
#include "GWorldData.h"
#include <qdom.h>
namespace GCS
{
GObject::GObject(GEnergy* energy,
GForm* form,
const GElementID& parent,
const GElementID& ID,
const GElementID& connection,
QDomDocument* element_data,
const GWorldData* world_data)
: Energy(energy),
Form(form),
Parent(parent),
ID(ID),
Connection(connection),
ElementData(element_data),
WorldData(world_data)
{
}
GObject::~GObject()
{
if (hasEnergy())
{
delete Energy;
Energy = NULL;
}
if (hasForm())
{
delete Form;
Form = NULL;
}
if (hasElementData())
{
delete ElementData;
ElementData = NULL;
}
}
// read methods:
bool GObject::hasEnergy() const
{
return Energy ? true : false;
}
GEnergy* GObject::getEnergy()
{
Q_CHECK_PTR(Energy);
return Energy;
}
const GEnergy* GObject::getEnergy() const
{
Q_CHECK_PTR(Energy);
return Energy;
}
bool GObject::hasForm() const
{
return Form ? true : false;
}
GForm* GObject::getForm()
{
Q_CHECK_PTR(Form);
return Form;
}
const GForm* GObject::getForm() const
{
Q_CHECK_PTR(Form);
return Form;
}
const GElementID& GObject::getParent() const
{
return Parent;
}
const GElementID& GObject::getID() const
{
return ID;
}
const GElementID& GObject::getConnection() const
{
return Connection;
}
bool GObject::hasElementData() const
{
return ElementData ? true : false;
}
const QDomDocument* GObject::getElementData() const
{
Q_CHECK_PTR(ElementData);
return ElementData;
}
QDomDocument* GObject::getElementData()
{
Q_CHECK_PTR(ElementData);
return ElementData;
}
bool GObject::hasWorldData() const
{
return WorldData ? true : false;
}
const GWorldData* GObject::getWorldData() const
{
Q_CHECK_PTR(WorldData);
return WorldData;
}
void GObject::reparent(const GElementID& new_parent)
{
this->Parent = new_parent;
}
bool GObject::isChild(const GElementID& childID) const
{
return this->getChildren().contains(childID);
}
QValueList<GElementID> GObject::getChildren() const
{
if (this->hasWorldData())
{
return this->WorldData->getChildren(this->getID().getID());
}
else
{
return QValueList<GElementID>();
}
}
}
syntax highlighted by Code2HTML, v. 0.9.1