55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
#ifndef XML_OPERT_HEADER
|
|
#define XML_OPERT_HEADER
|
|
|
|
#include <string>
|
|
#include <tinyxml2.h>
|
|
#include <vector>
|
|
#include "../public_def.h"
|
|
|
|
struct SKeyValue {
|
|
SKeyValue(const char* pkey, const char* pvalue);
|
|
std::string key;
|
|
std::string value;
|
|
};
|
|
|
|
typedef tinyxml2::XMLElement Element_t;
|
|
typedef std::vector<SKeyValue> Property_t;
|
|
class CXmlOpr
|
|
{
|
|
public:
|
|
CXmlOpr();
|
|
~CXmlOpr();
|
|
|
|
public:
|
|
bool open(const std::string& xml_path);
|
|
void set_baseinfo(const OprBase& base);
|
|
bool parse_xml(std::vector<Element_t*>& vec);
|
|
void copy_and_del(std::vector<Element_t*>& vec, std::vector<Element_t*>& out);
|
|
void insert_brother_node(Element_t* brother, Element_t* newer);
|
|
void del_element(Element_t* ele);
|
|
bool check_key_exists(const Property_t& property);
|
|
bool save();
|
|
|
|
public:
|
|
Element_t* copy_element(Element_t* ele);
|
|
// 检查 xml 格式合法性
|
|
bool check_valid_xml_data(const std::string& data);
|
|
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
|
bool check_same_struct(const std::string& data);
|
|
// 不检查 xml 格式合法性,请自行调用 check_valid_xml_data
|
|
bool import_newer_data(const std::vector<std::string>& vec);
|
|
|
|
public:
|
|
void get_key_value(Element_t* ele, Property_t& vec);
|
|
void key_value_to_element(Element_t* ele, const Property_t& vec);
|
|
|
|
private:
|
|
tinyxml2::XMLDocument doc_{};
|
|
OprBase opr_base_{};
|
|
std::string xml_path_{};
|
|
Element_t* parent_node_{};
|
|
std::vector<std::string> keys_{};
|
|
};
|
|
|
|
#endif
|