1 #ifndef BML_PARSER_H 2 #define BML_PARSER_H 3 4 #include <vector> 5 #include <string> 6 #include <sstream> 7 8 class Bml_Node 9 { 10 char * name; 11 char * value; 12 13 std::vector<Bml_Node> children; 14 15 static Bml_Node emptyNode; 16 17 public: 18 Bml_Node(); 19 Bml_Node(char const* name, size_t max_length = ~0UL); 20 Bml_Node(Bml_Node const& in); 21 22 ~Bml_Node(); 23 24 void clear(); 25 26 void setLine(const char * line, size_t max_length = ~0UL); 27 Bml_Node& addChild(Bml_Node const& child); 28 29 const char * getName() const; 30 const char * getValue() const; 31 32 void setValue(char const* value); 33 34 size_t getChildCount() const; 35 Bml_Node const& getChild(size_t index) const; 36 37 Bml_Node & walkToNode( const char * path, bool use_indexes = false ); 38 Bml_Node const& walkToNode( const char * path ) const; 39 }; 40 41 class Bml_Parser 42 { 43 Bml_Node document; 44 45 public: Bml_Parser()46 Bml_Parser() { } 47 48 void parseDocument(const char * document, size_t max_length = ~0UL); 49 50 const char * enumValue(std::string const& path) const; 51 52 void setValue(std::string const& path, long value); 53 void setValue(std::string const& path, const char * value); 54 55 void serialize(std::string & out) const; 56 57 private: 58 void serialize(std::ostringstream & out, Bml_Node const* node, unsigned int indent) const; 59 }; 60 61 #endif // BML_PARSER_H 62