func:可以基本显示目标结果。

This commit is contained in:
2024-05-15 10:59:43 +08:00
parent 5cd8cec2a3
commit faa64d7ba2
16 changed files with 5670 additions and 8 deletions

38
src/config.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include "config.h"
#include <filesystem>
namespace fs = std::filesystem;
bool ConfigIni::set_work_exe(const std::string& dir)
{
work_dir_ = dir;
auto ini_path = fs::path(work_dir_).parent_path().append("xmlopr.ini");
if (!fs::exists(ini_path)) {
return false;
}
ini_path_ = ini_path.string();
if (!parse_ini()) {
return false;
}
return true;
}
OprBase ConfigIni::get_config()
{
return opr_base_;
}
bool ConfigIni::parse_ini()
{
if (ini_.LoadFile(ini_path_.c_str()) != SI_OK) {
return false;
}
opr_base_.node_path = ini_.GetValue("Basic", "oper_node");
opr_base_.purpose = ini_.GetValue("Basic", "purpose");
opr_base_.the_node = ini_.GetValue("Basic", "the_node");
opr_base_.xml_path = ini_.GetValue("Basic", "xml_path");
return true;
}

34
src/config.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef CONIFG_HEADER
#define CONIFG_HEADER
#include <string>
#include <SimpleIni.h>
#include "../public_def.h"
/*
[Basic]
oper_node=IODEF/ITEMS
*/
class ConfigIni
{
public:
ConfigIni() = default;
~ConfigIni() = default;
public:
bool set_work_exe(const std::string& dir);
OprBase get_config();
private:
bool parse_ini();
private:
std::string work_dir_{};
std::string ini_path_{};
CSimpleIni ini_{};
OprBase opr_base_{};
};
#endif

47
src/xml_opr.cpp Normal file
View File

@@ -0,0 +1,47 @@
#include "xml_opr.h"
CXmlOpr::CXmlOpr() = default;
CXmlOpr::~CXmlOpr() = default;
bool CXmlOpr::open(const std::string &xml_path)
{
if (doc_.LoadFile(xml_path.c_str()) != tinyxml2::XML_SUCCESS) {
return false;
}
return true;
}
void CXmlOpr::set_baseinfo(const OprBase& base)
{
opr_base_ = base;
}
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) {
if (item.empty()) {
continue;
}
if (node == nullptr) {
node = doc_.FirstChildElement(item.c_str());
}
else {
node = node->FirstChildElement(item.c_str());
}
}
vec.clear();
tinyxml2::XMLElement* purpose_node = node->FirstChildElement(opr_base_.the_node.c_str());
while (purpose_node)
{
vec.push_back(purpose_node);
purpose_node = purpose_node->NextSiblingElement();
}
return true;
}

25
src/xml_opr.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef XML_OPERT_HEADER
#define XML_OPERT_HEADER
#include <string>
#include <tinyxml2.h>
#include <vector>
#include "../public_def.h"
class CXmlOpr
{
public:
CXmlOpr();
~CXmlOpr();
public:
bool open(const std::string& xml_path);
void set_baseinfo(const OprBase& base);
bool parse_xml(std::vector<tinyxml2::XMLElement*>& vec);
private:
tinyxml2::XMLDocument doc_{};
OprBase opr_base_{};
};
#endif