/* * 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/Time.cpp */ // Header include #include "Time.h" // Sigmod includes #include "Game.h" #include "Macros.h" using namespace Sigcore; using namespace Sigmod; Time::Time(const Time& time) : Object(time.parent(), time.id()) { *this = time; } Time::Time(const Game* parent, const int id) : Object(parent, id), m_name(""), m_hour(0), m_minute(0), m_script("", "") { } Time::Time(const Time& time, const Game* parent, const int id) : Object(parent, id) { *this = time; } Time::Time(const QDomElement& xml, const Game* parent, const int id) : Object(parent, id) { initXmlImport(xml, id); load(xml); } void Time::validate() { testBegin(); if (m_name.isEmpty()) emit(error("Name is empty")); TEST(hour); TEST(minute); testEnd(); } void Time::load(const QDomElement& xml) { clear(); loadValue(xml.firstChildElement("name"), &m_name); loadValue(xml.firstChildElement("hour"), &m_hour); loadValue(xml.firstChildElement("minute"), &m_minute); loadValue(xml.firstChildElement("script"), &m_script); } QDomElement Time::save() const { QDomElement xml = initXmlExport(); xml.appendChild(saveValue("name", m_name)); xml.appendChild(saveValue("hour", m_hour)); xml.appendChild(saveValue("minute", m_minute)); xml.appendChild(saveValue("script", m_script)); return xml; } SETTER(Time, QString&, Name, name) SETTER(Time, int, Hour, hour) SETTER(Time, int, Minute, minute) SETTER(Time, Script&, Script, script) GETTER(Time, QString, name) GETTER(Time, int, hour) GETTER(Time, int, minute) GETTER(Time, Script, script) CHECK(Time, QString&, name) CHECK_BOUNDS(Time, int, hour, 0, 23) CHECK_BOUNDS(Time, int, minute, 0, 59) CHECK(Time, Script&, script) Time& Time::operator=(const Time& rhs) { if (this == &rhs) return *this; m_name = rhs.m_name; m_hour = rhs.m_hour; m_minute = rhs.m_minute; m_script = rhs.m_script; return *this; }