func:基本添加复制功能,无GUI。
This commit is contained in:
@@ -21,7 +21,6 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
|
||||
{
|
||||
std::string next_node{};
|
||||
std::string node_path = opr_base_.node_path;
|
||||
tinyxml2::XMLElement* node = nullptr;
|
||||
|
||||
auto nodes = splitString(opr_base_.node_path, "/");
|
||||
for (const auto& item : nodes) {
|
||||
@@ -30,15 +29,15 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (node == nullptr) {
|
||||
node = doc_.FirstChildElement(item.c_str());
|
||||
if (parent_node_ == nullptr) {
|
||||
parent_node_ = doc_.FirstChildElement(item.c_str());
|
||||
}
|
||||
else {
|
||||
node = node->FirstChildElement(item.c_str());
|
||||
parent_node_ = parent_node_->FirstChildElement(item.c_str());
|
||||
}
|
||||
}
|
||||
vec.clear();
|
||||
tinyxml2::XMLElement* purpose_node = node->FirstChildElement(opr_base_.the_node.c_str());
|
||||
element* purpose_node = parent_node_->FirstChildElement(opr_base_.the_node.c_str());
|
||||
while (purpose_node)
|
||||
{
|
||||
vec.push_back(purpose_node);
|
||||
@@ -47,6 +46,28 @@ bool CXmlOpr::parse_xml(std::vector<tinyxml2::XMLElement*>& vec)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CXmlOpr::insert_brother_node(element* brother, element* newer)
|
||||
{
|
||||
if (!brother || !newer) {
|
||||
return;
|
||||
}
|
||||
parent_node_->InsertAfterChild(brother, newer);
|
||||
}
|
||||
|
||||
element* CXmlOpr::copy_element(element* ele)
|
||||
{
|
||||
if (!ele) {
|
||||
return nullptr;
|
||||
}
|
||||
element* ret = doc_.NewElement(ele->Name());
|
||||
const auto* attribute = ele->FirstAttribute();
|
||||
while (attribute) {
|
||||
ret->SetAttribute(attribute->Name(), attribute->Value());
|
||||
attribute = attribute->Next();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CXmlOpr::save()
|
||||
{
|
||||
auto ret = doc_.SaveFile(xml_path_.c_str());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
#include "../public_def.h"
|
||||
|
||||
typedef tinyxml2::XMLElement element;
|
||||
class CXmlOpr
|
||||
{
|
||||
public:
|
||||
@@ -13,15 +14,18 @@ public:
|
||||
~CXmlOpr();
|
||||
|
||||
public:
|
||||
bool open(const std::string& xml_path);
|
||||
void set_baseinfo(const OprBase& base);
|
||||
bool parse_xml(std::vector<tinyxml2::XMLElement*>& vec);
|
||||
bool save();
|
||||
bool open(const std::string& xml_path);
|
||||
void set_baseinfo(const OprBase& base);
|
||||
bool parse_xml(std::vector<element*>& vec);
|
||||
void insert_brother_node(element* brother, element* newer);
|
||||
element* copy_element(element* ele);
|
||||
bool save();
|
||||
|
||||
private:
|
||||
tinyxml2::XMLDocument doc_{};
|
||||
OprBase opr_base_{};
|
||||
std::string xml_path_{};
|
||||
element* parent_node_{};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user