xml.hh

00001 /*
00002 ** TowBowlTactics, an adaptation of the tabletop game Blood Bowl.
00003 **
00004 ** Copyright (C) 2006 The TBT Team.
00005 **
00006 ** This program is free software; you can redistribute it and/or
00007 ** modify it under the terms of the GNU General Public License
00008 ** as published by the Free Software Foundation; either version 2
00009 ** of the License, or (at your option) any later version.
00010 **
00011 ** The complete GNU General Public Licence Notice can be found as the
00012 ** `NOTICE' file in the root directory.
00013 **
00014 ** The TBT Team consists of people listed in the `AUTHORS' file.
00015 */
00016 
00017 #ifndef XML_HH_
00018 # define XML_HH_
00019 
00020 BEGIN_NS(xml);
00021 
00022 class XMLInternal;
00023 
00028 class XMLError : public Exception
00029 {
00030 public:
00031   XMLError(const std::string& reason);
00032 };
00033 
00055 class XML
00056 {
00057 public:
00061   virtual void parse(const std::string& filename);
00062 
00066   void save();
00067 
00069   friend std::ostream& operator<< (std::ostream& os, const XML& xml);
00070 
00073   void setNodeAppend(bool enabled);
00074   
00078   //    @c string are supported.
00079   template <typename T>
00080   T getData(const std::string& node_name, int index = 0) const;
00081 
00088   template <typename T>
00089   T getAttr(const std::string& node_name,
00090         const std::string& attr_name,
00091         int index = 0) const;
00092 
00095   template <typename T>
00096   void setData(const std::string& node_name,
00097            const T& value);
00098 
00101   template <typename T>
00102   void setAttr(const std::string& node_name,
00103            const std::string& attr_name,
00104            const T& value);
00105 
00106 protected:
00107   XML();
00108   virtual ~XML();
00109 
00111   virtual const char* getExpectedRoot() const = 0;
00112 
00113   mutable XMLInternal* xml_internal_;
00114 
00115   std::string filename_;
00116 
00117 private:
00118   // Do not allow copies of this object.
00119   XML(const XML&);
00120   XML& operator= (const XML&);
00121 
00122   static int inst_count_;
00123   mutable int append_node_;
00124 };
00125 
00126 END_NS(xml);
00127 
00128 #endif /* !XML_HH_ */

Generated on Sat Jun 23 16:07:24 2007 for Stechec/TBT by  doxygen 1.4.7