1 // Copyright (C) 2004, 2005 Ulf Lorenz
2 // Copyright (C) 2007, 2008 Ben Asselstine
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Library General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #include <sigc++/functors/mem_fun.h>
26 std::string Itemlist::d_tag = "itemlist";
28 Itemlist* Itemlist::d_instance = 0;
30 Itemlist* Itemlist::getInstance()
33 d_instance = new Itemlist();
38 Itemlist* Itemlist::getInstance(XML_Helper *helper)
41 d_instance = new Itemlist();
43 d_instance = new Itemlist(helper);
47 void Itemlist::createStandardInstance()
51 XML_Helper helper(File::getItemDescription(), std::ios::in, false);
52 d_instance = new Itemlist(&helper);
56 std::cerr <<_("Could not parse items description file. Exiting!\n");
62 void Itemlist::deleteInstance()
71 Itemlist::Itemlist(XML_Helper* helper)
73 helper->registerTag(ItemProto::d_tag, sigc::mem_fun(*this, &Itemlist::loadItemProto));
85 bool Itemlist::loadItemProto(std::string tag, XML_Helper* helper)
87 if (tag != ItemProto::d_tag)
90 ItemProto* i = new ItemProto(helper);
91 i->setTypeId((*this).size());
92 (*this)[(*this).size()] = i;
97 void Itemlist::flErase(iterator it)
103 void Itemlist::flClear()
109 bool Itemlist::save(XML_Helper* helper) const
113 retval &= helper->openTag(d_tag);
115 for (const_iterator it = begin(); it != end(); it++)
116 (*it).second->save(helper);
118 retval &= helper->closeTag();
123 void Itemlist::remove(ItemProto *itemproto)
126 for (iterator it = begin(); it != end(); it++)
128 if ((*it).second == itemproto)