Subversion Repositories HomeAutomation

Rev

Rev 1310 | 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.     string tagName();
  38.     attributeList & attributes();
  39.  
  40.     string operator [](string attributeName);
  41.  
  42.     Node selectFirst();
  43.     Node selectFirst(string tagName);
  44.     Node selectFirst(string tagName, attributeList attributes);
  45.     Node selectFirst(string tagName, attributePair pair1);
  46.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2);
  47.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3);
  48.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4);
  49.     Node selectFirst(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4, attributePair pair5);
  50.  
  51.     nodeList select();
  52.     nodeList select(string tagName);
  53.     nodeList select(string tagName, attributeList attributes);
  54.     nodeList select(string tagName, attributePair pair1);
  55.     nodeList select(string tagName, attributePair pair1, attributePair pair2);
  56.     nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3);
  57.     nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4);
  58.     nodeList select(string tagName, attributePair pair1, attributePair pair2, attributePair pair3, attributePair pair4, attributePair pair5);
  59.  
  60.     string toString();
  61.  
  62. private:
  63.     utils::Logger LOG;
  64.  
  65.     bool myIsEmpty;
  66.     string myTagName;
  67.     attributeList myAttributes;
  68.     nodeList myChildren;
  69.  
  70.     void parse(string filename, string xmlData);
  71.     int parseTag(string filename, string xmlData, unsigned int position);
  72. };
  73.  
  74. }
  75. }
  76.  
  77. #endif /* NODE_H_ */
  78.