2013-09-28 03:24:46 +00:00
|
|
|
#ifndef BML_PARSER_H
|
|
|
|
#define BML_PARSER_H
|
|
|
|
|
|
|
|
#include <vector>
|
2013-10-26 16:00:59 +00:00
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2013-09-28 03:24:46 +00:00
|
|
|
|
|
|
|
class Bml_Node
|
|
|
|
{
|
|
|
|
char * name;
|
|
|
|
char * value;
|
|
|
|
|
|
|
|
std::vector<Bml_Node> children;
|
|
|
|
|
|
|
|
static Bml_Node emptyNode;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Bml_Node();
|
2013-10-26 16:00:59 +00:00
|
|
|
Bml_Node(char const* name, size_t max_length = ~0UL);
|
2013-09-28 03:24:46 +00:00
|
|
|
Bml_Node(Bml_Node const& in);
|
|
|
|
|
|
|
|
~Bml_Node();
|
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
2013-10-26 16:00:59 +00:00
|
|
|
void setLine(const char * line, size_t max_length = ~0UL);
|
|
|
|
Bml_Node& addChild(Bml_Node const& child);
|
2013-09-28 03:24:46 +00:00
|
|
|
|
|
|
|
const char * getName() const;
|
|
|
|
const char * getValue() const;
|
2013-10-26 16:00:59 +00:00
|
|
|
|
|
|
|
void setValue(char const* value);
|
2013-09-28 03:24:46 +00:00
|
|
|
|
|
|
|
size_t getChildCount() const;
|
|
|
|
Bml_Node const& getChild(size_t index) const;
|
|
|
|
|
2013-10-26 16:00:59 +00:00
|
|
|
Bml_Node & walkToNode( const char * path, bool use_indexes = false );
|
2013-09-28 03:24:46 +00:00
|
|
|
Bml_Node const& walkToNode( const char * path ) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Bml_Parser
|
|
|
|
{
|
|
|
|
Bml_Node document;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Bml_Parser() { }
|
|
|
|
|
2013-10-26 16:00:59 +00:00
|
|
|
void parseDocument(const char * document, size_t max_length = ~0UL);
|
2013-09-28 03:24:46 +00:00
|
|
|
|
2013-10-26 16:00:59 +00:00
|
|
|
const char * enumValue(std::string const& path) const;
|
|
|
|
|
|
|
|
void setValue(std::string const& path, long value);
|
|
|
|
void setValue(std::string const& path, const char * value);
|
2013-09-28 03:24:46 +00:00
|
|
|
|
2013-10-26 16:00:59 +00:00
|
|
|
void serialize(std::string & out);
|
|
|
|
private:
|
|
|
|
void serialize(std::ostringstream & out, Bml_Node const* node, unsigned int indent) const;
|
2013-09-28 03:24:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BML_PARSER_H
|