19 #include <pugixml.hpp>
34 #define FOREACH_CHILD(c, p, tag) for (auto c = p.child(tag); !c.empty(); c = c.next_sibling(tag))
50 INFERENCE_ENGINE_API_CPP(
int)
GetIntAttr(
const pugi::xml_node& node,
const char* str);
60 INFERENCE_ENGINE_API_CPP(
int)
GetIntAttr(
const pugi::xml_node& node,
const char* str,
int defVal);
70 INFERENCE_ENGINE_API_CPP(int64_t)
GetInt64Attr(
const pugi::xml_node& node,
const char* str);
81 INFERENCE_ENGINE_API_CPP(int64_t)
GetInt64Attr(
const pugi::xml_node& node,
const char* str, int64_t defVal);
91 INFERENCE_ENGINE_API_CPP(uint64_t)
GetUInt64Attr(
const pugi::xml_node& node,
const char* str);
102 INFERENCE_ENGINE_API_CPP(uint64_t)
GetUInt64Attr(
const pugi::xml_node& node,
const char* str, uint64_t defVal);
112 INFERENCE_ENGINE_API_CPP(
unsigned int)
GetUIntAttr(
const pugi::xml_node& node,
const char* str);
123 INFERENCE_ENGINE_API_CPP(
unsigned int)
GetUIntAttr(
const pugi::xml_node& node,
const char* str,
unsigned int defVal);
133 INFERENCE_ENGINE_API_CPP(std::string)
GetStrAttr(
const pugi::xml_node& node,
const char* str);
144 INFERENCE_ENGINE_API_CPP(std::string)
GetStrAttr(
const pugi::xml_node& node,
const char* str,
const char* def);
154 INFERENCE_ENGINE_API_CPP(
bool)
GetBoolAttr(
const pugi::xml_node& node,
const char* str);
165 INFERENCE_ENGINE_API_CPP(
bool)
GetBoolAttr(
const pugi::xml_node& node,
const char* str,
const bool def);
175 INFERENCE_ENGINE_API_CPP(
float)
GetFloatAttr(
const pugi::xml_node& node,
const char* str);
186 INFERENCE_ENGINE_API_CPP(
float)
GetFloatAttr(
const pugi::xml_node& node,
const char* str,
float defVal);
219 INFERENCE_ENGINE_API_CPP(
int)
GetIntChild(const pugi::xml_node& node, const
char* str,
int defVal);
234 parse_result(std::unique_ptr<pugi::xml_document>&& xml, std::string error_msg)
235 : xml(std::move(xml)), error_msg(std::move(error_msg)) {}
240 std::unique_ptr<pugi::xml_document>
xml;
245 std::string error_msg {};
257 #ifdef ENABLE_UNICODE_PATH_SUPPORT
258 std::wstring wFilePath = FileUtils::multiByteCharToWString(file_path);
259 const wchar_t* resolvedFilepath = wFilePath.c_str();
261 const char* resolvedFilepath = file_path;
265 auto xml = std::unique_ptr<pugi::xml_document> {
new pugi::xml_document {}};
266 const auto load_result = xml->load_file(resolvedFilepath);
268 const auto error_msg = [&]() -> std::string {
269 if (load_result.status == pugi::status_ok)
return {};
271 std::ifstream file_stream(file_path);
272 const auto file = std::string(std::istreambuf_iterator<char> {file_stream}, std::istreambuf_iterator<char> {});
274 const auto error_offset = std::next(file.rbegin(), file.size() - load_result.offset);
275 const auto line_begin = std::find(error_offset, file.rend(),
'\n');
276 const auto line = 1 + std::count(line_begin, file.rend(),
'\n');
277 const auto pos = std::distance(error_offset, line_begin);
279 std::stringstream ss;
280 ss <<
"Error loading XML file: " << file_path <<
":" << line <<
":" << pos <<
": " << load_result.description();
284 return {std::move(xml), error_msg};
285 }
catch(std::exception& e) {
286 return {std::move(
nullptr), std::string(
"Error loading XML file: ") + e.what()};
Basic function to work with file system and UNICODE symbols.
bool GetBoolAttr(const pugi::xml_node &node, const char *str)
Gets the bool attribute from pugi::xml_node
uint64_t GetUInt64Attr(const pugi::xml_node &node, const char *str)
Gets the uint64_t attribute from pugi::xml_node
int GetIntChild(const pugi::xml_node &node, const char *str, int defVal)
Gets the integer value located in a child node.
int64_t GetInt64Attr(const pugi::xml_node &node, const char *str)
Gets the int64_t attribute from pugi::xml_node
std::string GetStrAttr(const pugi::xml_node &node, const char *str)
Gets the string attribute from pugi::xml_node
int GetIntAttr(const pugi::xml_node &node, const char *str)
Gets the integer attribute from pugi::xml_node
unsigned int GetUIntAttr(const pugi::xml_node &node, const char *str)
Gets the unsigned integer attribute from pugi::xml_node
InferenceEngine::Precision GetPrecisionAttr(const pugi::xml_node &node, const char *str)
Gets the Precision attribute from pugi::xml_node
float GetFloatAttr(const pugi::xml_node &node, const char *str)
Gets the float attribute from pugi::xml_node
parse_result ParseXml(const char *file_path)
Parses a file and returns parse_result.
Definition: xml_parse_utils.h:256
Inference Engine Plugin API namespace.
XML helpers function to extract values from pugi::xml_node
Definition: xml_parse_utils.h:40
A XML parse result structure with an error message and the pugi::xml_document document.
Definition: xml_parse_utils.h:227
std::unique_ptr< pugi::xml_document > xml
A XML document.
Definition: xml_parse_utils.h:240
parse_result(std::unique_ptr< pugi::xml_document > &&xml, std::string error_msg)
Constructs parse_result with pugi::xml_document and an error message.
Definition: xml_parse_utils.h:234