5#include "../extern/tinyxml2.hpp"
9#include <unordered_map>
11namespace adul {
namespace atm {
20template <
typename keyT,
typename valueT>
class XMLMap {
22 std::unordered_map<keyT, valueT>
map;
24 void saveMapToXMLElement(adul::xml::XMLElement *
const pElement, adul::xml::XMLDocument *
const xmlDoc)
const {
25 adul::xml::XMLElement *pSubEl =
nullptr;
27 for (
auto cur =
map.begin(); cur !=
map.end(); cur++) {
28 pSubEl = xmlDoc->NewElement(
"mapElement");
30 pSubEl->SetAttribute(
"key",
32 pSubEl->SetAttribute(
"value",
35 pElement->InsertEndChild(pSubEl);
40 const adul::xml::XMLElement *pSubEl =
41 pElement->FirstChildElement(
"mapElement");
43 while (pSubEl !=
nullptr) {
44 const char* keyAttr = pSubEl->Attribute(
"key");
45 const char* valueAttr = pSubEl->Attribute(
"value");
46 if (!keyAttr || !valueAttr) {
52 pSubEl = pSubEl->NextSiblingElement(
"mapElement");
57 adul::xml::XMLDocument document;
58 adul::xml::XMLElement *pRoot = document.NewElement(
"root");
61 document.InsertFirstChild(pRoot);
63 if (document.SaveFile(dir) != adul::xml::XMLError::XML_SUCCESS)
68 adul::xml::XMLDocument document;
70 if (document.LoadFile(dir) != adul::xml::XMLError::XML_SUCCESS)
73 adul::xml::XMLElement *pRoot = document.FirstChildElement(
"root");
this class is wrapper for STL container std::unordered_map
Definition XMLMap.hpp:20
void saveMapToXMLFile(const char *dir)
Definition XMLMap.hpp:56
void loadMapFromXMLFile(const char *dir)
Definition XMLMap.hpp:67
std::unordered_map< keyT, valueT > map
Definition XMLMap.hpp:22
void saveMapToXMLElement(adul::xml::XMLElement *const pElement, adul::xml::XMLDocument *const xmlDoc) const
Definition XMLMap.hpp:24
void loadMapFromXMLElement(const adul::xml::XMLElement *const pElement)
Definition XMLMap.hpp:39
represents failure with reading from XML file
Definition exceptions.hpp:58
represents failure with writing to XML file
Definition exceptions.hpp:71
modified std::exception class The only difference is that you define message by yourself when create...
Definition exceptions.hpp:27
T convert_string(const std::string &str)
converts std::string into other type
Definition smallUtils.hpp:23
std::string convert_string< std::string >(const std::string &str)
Definition smallUtils.hpp:33
project api's namespace
Definition atm.hpp:4