/* * Copyright 2007-2009 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ /** * \file sigmod/CoinListItem.cpp */ // Header include #include "CoinListItem.h" // Sigmod includes #include "CoinList.h" #include "Game.h" #include "Macros.h" using namespace Sigmod; const QStringList CoinListItem::TypeStr = QStringList() << "Item" << "Team Member"; CoinListItem::CoinListItem(const CoinListItem& item) : Object(item.parent(), item.id()) { *this = item; } CoinListItem::CoinListItem(const CoinList* parent, const int id) : Object(parent, id), m_type(Item), m_object(-1), m_cost(0) { } CoinListItem::CoinListItem(const CoinListItem& item, const CoinList* parent, const int id) : Object(parent, id) { *this = item; } CoinListItem::CoinListItem(const QDomElement& xml, const CoinList* parent, const int id) : Object(parent, id) { initXmlImport(xml, id); load(xml); } void CoinListItem::validate() { testBegin(); TEST(object); TEST(cost); testEnd(); } void CoinListItem::load(const QDomElement& xml) { clear(); loadEnum(xml.firstChildElement("type"), &m_type, TypeStr); loadValue(xml.firstChildElement("object"), &m_object); loadValue(xml.firstChildElement("cost"), &m_cost); } QDomElement CoinListItem::save() const { QDomElement xml = initXmlExport(); xml.appendChild(saveEnum("type", m_type, TypeStr)); xml.appendChild(saveValue("object", m_object)); xml.appendChild(saveValue("cost", m_cost)); return xml; } SETTER(CoinListItem, Type, Type, type) SETTER(CoinListItem, int, Object, object) SETTER(CoinListItem, int, Cost, cost) GETTER(CoinListItem, CoinListItem::Type, type) GETTER(CoinListItem, int, object) GETTER(CoinListItem, int, cost) CHECK(CoinListItem, Type, type) CHECK_BEGIN(CoinListItem, int, object) switch (m_type) { case Item: IBOUNDS(object, game(), item) break; case Species: IBOUNDS(object, game(), species) break; } CHECK_END() CHECK_BOUNDS(CoinListItem, int, cost, 1, INT_MAX) CoinListItem& CoinListItem::operator=(const CoinListItem& rhs) { if (this == &rhs) return *this; m_type = rhs.m_type; m_object = rhs.m_object; m_cost = rhs.m_cost; return *this; }