xml.hh

00001 /*
00002 ** TowBowlTactics, a turn-based strategy football game.
00003 **
00004 ** Copyright (C) 2006-2010 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 # include "tools.hh"
00021 
00022 BEGIN_NS(xml);
00023 
00024 class XMLInternal;
00025 
00030 class XMLError : public Exception
00031 {
00032 public:
00033   XMLError(const std::string& reason);
00034 };
00035 
00057 class XML
00058 {
00059 public:
00063   virtual void parse(const std::string& filename);
00064 
00068   void save();
00069 
00071   friend std::ostream& operator<< (std::ostream& os, const XML& xml);
00072 
00075   void setNodeAppend(bool enabled);
00076   
00081   //    @c string are supported.
00082   template <typename T>
00083   T getData(const std::string& node_name, int index = 0) const;
00084 
00093   template <typename T>
00094   T getAttr(const std::string& node_name,
00095         const std::string& attr_name,
00096         int index = 0) const;
00097 
00100   template <typename T>
00101   void setData(const std::string& node_name,
00102            const T& value);
00103 
00106   template <typename T>
00107   void setAttr(const std::string& node_name,
00108            const std::string& attr_name,
00109            const T& value);
00110 
00111 protected:
00112   XML();
00113   virtual ~XML();
00114 
00116   virtual const char* getExpectedRoot() const = 0;
00117 
00119   virtual void initXMLInternal();
00120 
00121   mutable XMLInternal* xml_internal_;
00122 
00123   std::string filename_;
00124 
00125 private:
00126   // Do not allow copies of this object.
00127   XML(const XML&);
00128   XML& operator= (const XML&);
00129 
00130   static int inst_count_;
00131   mutable int append_node_;
00132 };
00133 
00134 END_NS(xml);
00135 
00136 #endif /* !XML_HH_ */
Generated on Mon Apr 5 21:17:14 2010 for Stechec/TBT by  doxygen 1.6.3