xml_internal.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_INTERNAL_HH_
00018 # define XML_INTERNAL_HH_
00019 
00020 # include <deque>
00021 # include <xercesc/dom/DOM.hpp>
00022 # include <xercesc/dom/DOMDocument.hpp>
00023 # include <xercesc/parsers/XercesDOMParser.hpp>
00024 
00025 BEGIN_NS(xml);
00026 
00031 class XMLInternal
00032 {
00033 public:
00034   XMLInternal();
00035   ~XMLInternal();
00036 
00037   /*
00038   ** Parser
00039   */
00040   void parseDocument(const std::string& filename,
00041              const std::string& expected_root);
00042 
00043   void setCurrentNode(const std::string& node_name);
00044   bool setCurrentNodeByAttr(const std::string& node_name,
00045                 const std::string& attr_name,
00046                 const std::string& attr_value);
00047 
00048   std::string getText(const std::string& node_name,
00049               int index);
00050   std::string getAttr(const std::string& node_name,
00051               const std::string& attr_name,
00052               int index);
00053 
00054   bool getFormationAttr(const std::string& id,
00055             const std::string& player_id,
00056             std::string& row,
00057             std::string& col);
00058 
00059   xercesc::DOMElement* findNode(const std::string& node_name,
00060                 int index);
00061 
00062   /*
00063   ** Writer
00064   */
00065   void setCurrentNode(xercesc::DOMElement* elt);
00066   void setXercesParser(xercesc::XercesDOMParser* parser);
00067 
00068   void setData(xercesc::DOMElement* elt,
00069            const std::string& node_name,
00070            const std::string& value);
00071   
00072   void setAttr(xercesc::DOMElement* elt,
00073            const std::string& node_name,
00074            const std::string& attr_name,
00075            const std::string& value);
00076   
00077   void dump(xercesc::XMLFormatTarget* outfile);
00078   void save(const std::string& filename);
00079   void print(std::ostream& os);
00080 
00081   xercesc::DOMElement*      getCurrentNode();
00082   xercesc::XercesDOMParser* getXercesParser();
00083   
00084 private:
00085   xercesc::XercesDOMParser* parser_;
00086   xercesc::DOMElement*      root_;
00087   xercesc::DOMElement*      curr_node_;
00088 
00089   // Keep returned value from str2xml some time, then trash it.
00090   // Otherwise, it will leak.
00091   XMLCh*            str2xml(const std::string& str);
00092   std::deque<XMLCh*>        conv_val_;
00093 };
00094 
00095 END_NS(xml);
00096 
00097 #endif /* !XML_INTERNAL_HH_ */

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