2024-05-15 10:59:43 +08:00
|
|
|
#ifndef XML_OPERT_HEADER
|
|
|
|
#define XML_OPERT_HEADER
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <tinyxml2.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "../public_def.h"
|
|
|
|
|
2024-05-15 23:06:48 +08:00
|
|
|
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;
|
2024-05-15 10:59:43 +08:00
|
|
|
class CXmlOpr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CXmlOpr();
|
|
|
|
~CXmlOpr();
|
|
|
|
|
|
|
|
public:
|
2024-05-15 23:06:48 +08:00
|
|
|
bool open(const std::string& xml_path);
|
|
|
|
void set_baseinfo(const OprBase& base);
|
|
|
|
bool parse_xml(std::vector<Element_t*>& vec);
|
|
|
|
void insert_brother_node(Element_t* brother, Element_t* newer);
|
|
|
|
Element_t* copy_element(Element_t* ele);
|
|
|
|
void del_element(Element_t* ele);
|
2024-05-16 12:18:20 +08:00
|
|
|
bool check_key_exists(const Property_t& property);
|
2024-05-15 23:06:48 +08:00
|
|
|
bool save();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void get_key_value(Element_t* ele, Property_t& vec);
|
|
|
|
void key_value_to_element(Element_t* ele, const Property_t& vec);
|
2024-05-15 10:59:43 +08:00
|
|
|
|
|
|
|
private:
|
2024-05-16 12:18:20 +08:00
|
|
|
tinyxml2::XMLDocument doc_{};
|
|
|
|
OprBase opr_base_{};
|
|
|
|
std::string xml_path_{};
|
|
|
|
Element_t* parent_node_{};
|
|
|
|
std::vector<std::string> keys_{};
|
2024-05-15 10:59:43 +08:00
|
|
|
};
|
|
|
|
|
2024-05-17 22:46:33 +08:00
|
|
|
#endif
|