2017-04-13 16:19:35 +08:00
|
|
|
#pragma once
|
2017-05-17 21:40:33 +08:00
|
|
|
#include "rapidxml/rapidxml.hpp"
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace MiniEngine
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace XML
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef rapidxml::xml_node<> XNode;
|
|
|
|
typedef rapidxml::xml_attribute<> XAttr;
|
|
|
|
typedef rapidxml::xml_document<> XDoc;
|
|
|
|
|
|
|
|
/// Fwd Decl
|
|
|
|
class Document;
|
|
|
|
|
|
|
|
class Attribute
|
|
|
|
{
|
2017-05-17 23:24:43 +08:00
|
|
|
public:
|
|
|
|
void _set(XAttr*);
|
|
|
|
XAttr* _get() const;
|
|
|
|
void _clear();
|
|
|
|
void _setdoc(Document*);
|
2017-05-18 09:00:27 +08:00
|
|
|
|
2017-05-20 16:00:19 +08:00
|
|
|
Attribute();
|
|
|
|
Attribute(XAttr*);
|
|
|
|
|
2017-05-18 09:00:27 +08:00
|
|
|
std::string getName() const;
|
|
|
|
std::string getValue() const;
|
|
|
|
|
|
|
|
char* getNameRaw() const;
|
|
|
|
char* getValueRaw() const;
|
2017-05-20 16:00:19 +08:00
|
|
|
|
|
|
|
bool hasPrevAttr() const;
|
|
|
|
bool hasNextAttr() const;
|
|
|
|
Attribute getPrevAttr() const;
|
|
|
|
Attribute getNextAttr() const;
|
|
|
|
Attribute getPrevAttr(const std::string& name) const;
|
|
|
|
Attribute getNextAttr(const std::string& name) const;
|
|
|
|
|
2017-05-17 21:40:33 +08:00
|
|
|
private:
|
|
|
|
XAttr* _pattr;
|
|
|
|
Document* _pdoc;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Node
|
|
|
|
{
|
|
|
|
public:
|
2017-05-17 23:24:43 +08:00
|
|
|
void _set(XNode*);
|
2017-05-18 09:00:27 +08:00
|
|
|
XNode* _get() const;
|
2017-05-17 23:24:43 +08:00
|
|
|
void _clear();
|
|
|
|
void _setdoc(Document*);
|
|
|
|
|
|
|
|
Node();
|
|
|
|
Node(XNode*);
|
|
|
|
|
2017-05-18 09:00:27 +08:00
|
|
|
std::string getName() const;
|
|
|
|
std::string getValue() const;
|
|
|
|
|
|
|
|
char* getNameRaw() const;
|
|
|
|
char* getValueRaw() const;
|
|
|
|
|
2017-05-20 16:00:19 +08:00
|
|
|
Node& push_front(const Node&);
|
|
|
|
Node& push_back(const Node&);
|
|
|
|
Node& insert(const Node& where,const Node& val);
|
2017-05-17 21:40:33 +08:00
|
|
|
|
2017-05-20 16:00:19 +08:00
|
|
|
Node& remove_first_node();
|
|
|
|
Node& remove_last_node();
|
|
|
|
Node& remove_node(const Node& todelete);
|
|
|
|
Node& remove_all_node();
|
2017-05-17 21:40:33 +08:00
|
|
|
|
2017-05-20 16:00:19 +08:00
|
|
|
Node& push_front(const Attribute&);
|
|
|
|
Node& push_back(const Attribute&);
|
|
|
|
Node& insert(const Attribute& where,const Attribute& val);
|
2017-05-17 21:40:33 +08:00
|
|
|
|
2017-05-20 16:00:19 +08:00
|
|
|
Node& remove_first_attr();
|
|
|
|
Node& remove_last_attr();
|
|
|
|
Node& remove_attr(const Attribute& todelete);
|
|
|
|
Node& remove_all_attr();
|
2017-05-17 21:40:33 +08:00
|
|
|
|
2017-05-18 09:00:27 +08:00
|
|
|
bool operator == (const Node& node);
|
2017-05-17 21:40:33 +08:00
|
|
|
|
|
|
|
bool hasPrevNode() const;
|
|
|
|
bool hasNextNode() const;
|
|
|
|
bool hasParentNode() const;
|
|
|
|
Node getPrevNode() const;
|
|
|
|
Node getNextNode() const;
|
|
|
|
Node getParentNode() const;
|
2017-05-20 16:00:19 +08:00
|
|
|
Node getPrevNode(const std::string& name) const;
|
|
|
|
Node getNextNode(const std::string& name) const;
|
|
|
|
|
|
|
|
Node getChild() const;
|
|
|
|
Node getChild(const std::string& nodename) const;
|
2017-05-17 21:40:33 +08:00
|
|
|
|
2017-05-18 09:00:27 +08:00
|
|
|
bool valid();
|
2017-05-17 23:24:43 +08:00
|
|
|
|
2017-05-17 21:40:33 +08:00
|
|
|
private:
|
|
|
|
XNode* _pnode;
|
|
|
|
Document* _pdoc;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Document
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Document();
|
|
|
|
Document(const std::string& filename);
|
|
|
|
int loadFrom(const std::string& filename,bool clearCurrent=true);
|
|
|
|
int saveTo(const std::string& filename);
|
|
|
|
bool ready();
|
|
|
|
Node newNode(const std::string& name,const std::string& value);
|
|
|
|
Attribute newAttr(const std::string& name,const std::string& value);
|
2017-05-18 09:00:27 +08:00
|
|
|
Node cloneNode(const Node&);
|
|
|
|
void clear();
|
|
|
|
|
2017-05-17 21:40:33 +08:00
|
|
|
protected:
|
|
|
|
char* _allocate_string(const std::string& str);
|
|
|
|
char* _allocate_string(const char* pstr,int sz);
|
|
|
|
private:
|
|
|
|
XDoc _doc;
|
|
|
|
bool _is_ready;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine::XML
|
|
|
|
|
|
|
|
}/// End of namespace MiniEngine
|
2017-04-13 16:19:35 +08:00
|
|
|
|