Subversion Repositories HomeAutomation

Rev

Rev 1309 | Rev 1314 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*
  2.  * Node.h
  3.  *
  4.  *  Created on: Apr 26, 2009
  5.  *      Author: Mattias Runge
  6.  */
  7.  
  8. #ifndef NODE_H_
  9. #define NODE_H_
  10.  
  11. #include <string>
  12. #include <map>
  13. #include <stdexcept>
  14. #include <utility>
  15. #include "../utils/Logger.h"
  16. #include "../utils/Utils.h"
  17. #include "../Exception.hpp"
  18. #include <boost/algorithm/string/trim.hpp>
  19.  
  20. namespace atom {
  21. namespace xml {
  22.  
  23. using namespace std;
  24. using namespace boost::algorithm;
  25.  
  26. class Node
  27. {
  28. public:
  29.     typedef std::map<std::string, std::string> attributeList;
  30.     typedef std::pair<std::string, std::string> attributePair;
  31.     typedef std::vector<Node> nodeList;
  32.  
  33.     Node();
  34.     Node(string filename);
  35.     Node(string filename, string xmlData);
  36.  
  37.     void load(string filename);
  38.     void parse(string filename, string xmlData);
  39.  
  40.     string tagName();
  41.     attributeList & attributes();
  42.  
  43.     string operator [](string attributeName);
  44.  
  45.     Node selectFirst();
  46.     Node selectFirst(string tagName);
  47.     Node selectFirst(string tagName, attributeList attributes);
  48.     Node selectFirst(string tagName, attributePair pair1);
  49.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2);
  50.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3);
  51.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4);
  52.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4, attributePair pair5);
  53.  
  54.     nodeList select();
  55.     nodeList select(string tagName);
  56.     nodeList select(string tagName, attributeList attributes);
  57.     nodeList select(string tagName, attributePair pair1);
  58.     nodeList select(string tagName, attributePair pair1, attributePair pair2);
  59.     nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3);
  60.     nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4);
  61.     nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4, attributePair pair5);
  62.  
  63.     string toString();
  64.  
  65. private:
  66.     utils::Logger LOG;
  67.  
  68.     bool myIsEmpty;
  69.     string myTagName;
  70.     attributeList myAttributes;
  71.     nodeList myChildren;
  72.  
  73.     int parseTag(string filename, string xmlData, unsigned int position);
  74. };
  75.  
  76. }
  77. }
  78.  
  79. #endif /* NODE_H_ */
  80.