initial commit, lordsawar source, slightly modified
[lordsawar] / src / prodslot.cpp
1 //  Copyright (C) 2008, Ben Asselstine
2 //
3 //  This program is free software; you can redistribute it and/or modify
4 //  it under the terms of the GNU General Public License as published by
5 //  the Free Software Foundation; either version 3 of the License, or
6 //  (at your option) any later version.
7 //
8 //  This program is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 //  GNU Library General Public License for more details.
12 //
13 //  You should have received a copy of the GNU General Public License
14 //  along with this program; if not, write to the Free Software
15 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
16 //  02110-1301, USA.
17
18 #include "prodslot.h"
19
20 #include "armyprodbase.h"
21 #include "xmlhelper.h"
22
23 std::string ProdSlot::d_tag = "slot";
24
25 //#define debug(x) {std::cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<std::endl<<std::flush;}
26 //#define debug(x)
27
28 ProdSlot::ProdSlot()
29 {
30   d_armyprodbase = NULL;
31 }
32
33 ProdSlot::ProdSlot(const ProdSlot& object)
34 {
35   if (object.d_armyprodbase != NULL)
36     d_armyprodbase = new ArmyProdBase(*object.d_armyprodbase);
37   else
38     d_armyprodbase = NULL;
39 }
40
41 ProdSlot::ProdSlot(XML_Helper* helper)
42 {
43   d_armyprodbase = NULL;
44   helper->registerTag(ArmyProdBase::d_tag, 
45                       sigc::mem_fun(this, &ProdSlot::load));
46
47 }
48
49 bool ProdSlot::load(std::string tag, XML_Helper *helper)
50 {
51   if (tag == ArmyProdBase::d_tag)
52     {
53       d_armyprodbase = new ArmyProdBase(helper);
54       return true;
55     }
56   return false;
57 }
58
59 ProdSlot::~ProdSlot()
60 {
61   if (d_armyprodbase)
62     {
63       delete d_armyprodbase;
64       d_armyprodbase = NULL;
65     }
66 }
67
68 bool ProdSlot::save(XML_Helper *helper) const
69 {
70   bool retval = true;
71   retval &= helper->openTag(ProdSlot::d_tag);
72   if (d_armyprodbase)
73     retval &= d_armyprodbase->save(helper);
74   retval &= helper->closeTag();
75   return retval;
76 }
77     
78 void ProdSlot::clear()
79 {
80   if (d_armyprodbase) 
81     delete d_armyprodbase; 
82   d_armyprodbase = NULL;
83 };