1#ifndef IV_SRC_FILEHANDLERS_XMLFILE_HPP_
2#define IV_SRC_FILEHANDLERS_XMLFILE_HPP_
6#include "third_party/pugiXML/pugixml.hpp"
14class node :
public pugi::xml_node
19 node(
const pugi::xml_node &_node);
28 [[nodiscard]]
bool isNull()
const;
35 auto attr = pugi::xml_node::attribute(key.data());
37 if constexpr (std::is_same_v<T, double>)
39 return attr.as_double(defaultValue);
41 else if constexpr (std::is_same_v<T, float>)
43 return attr.as_float(defaultValue);
45 else if constexpr (std::is_same_v<T, int32_t> || std::is_same_v<T, int16_t> || std::is_same_v<T, int8_t>)
47 return attr.as_int(defaultValue);
49 else if constexpr (std::is_same_v<T, int64_t>)
51 return attr.as_llong(defaultValue);
53 else if constexpr (std::is_same_v<T, uint32_t> || std::is_same_v<T, uint16_t> || std::is_same_v<T, uint8_t>)
55 return attr.as_uint(defaultValue);
57 else if constexpr (std::is_same_v<T, uint64_t>)
59 return attr.as_ullong(defaultValue);
61 else if constexpr (std::is_same_v<T, bool>)
63 return attr.as_bool(defaultValue);
65 else if constexpr (std::is_same_v<T, std::string>)
67 return std::string(attr.as_string(defaultValue.c_str()));
79 pugi::xml_attribute attribute = pugi::xml_node::append_attribute(key.data());
81 if constexpr (std::is_same_v<T, std::string>)
83 attribute.set_value(value.c_str());
85 else if constexpr (std::is_same_v<T, std::string_view>)
87 attribute.set_value(std::string(value).c_str());
91 attribute.set_value(value);
94 const bool inserted = attribute !=
nullptr;
98 IV_ASSERT_MSG(
"[CFileXML] Attribute '%s' can't inserted in node '%s'.", keyName.c_str(),
99 pugi::xml_node::name());
105 void setText(
const std::string_view text)
const
107 pugi::xml_node::text().set(text.data());
112 return pugi::xml_node::text().as_string();
117 [[nodiscard]]
bool hasChild(std::string_view name)
const;
120 [[nodiscard]] std::vector<node>
getChildren()
const;
133 explicit File(std::string_view pathFile);
141 bool read(
bool checkIntegrity =
true);
142 [[nodiscard]]
bool save();
162 [[nodiscard]] std::string
toString()
const;
166 [[nodiscard]]
bool setMetadata(uint16_t crcValue)
const;
174 static constexpr std::string_view
fileNameTmp =
"/tmp/diamar_serialized.xml";
187 static constexpr std::string
metadata {
"Metadata"};
#define IV_ASSERT_MSG(msg,...)
Definition assert.hpp:152
Definition xmlFile.hpp:128
static File fromString(std::string_view xmlString)
Definition xmlFile.cpp:313
File & operator=(File &&other)=delete
bool prvCheckFileValidation(uint16_t crcValue) const
Definition xmlFile.cpp:333
bool addAttribute(const std::string_view node, std::string_view key, T value)
Definition xmlFile.hpp:157
T getAttribute(const std::string_view node, std::string_view key, T defaultValue) const
Definition xmlFile.hpp:151
bool save()
Definition xmlFile.cpp:124
bool hasChanges() const
Definition xmlFile.cpp:148
File & operator=(const File &other)=delete
File(File &&other)=default
iv::file::xml::node getChild(std::string_view name) const
Definition xmlFile.cpp:170
pugi::xml_document m_xml
Definition xmlFile.hpp:170
bool read(bool checkIntegrity=true)
Definition xmlFile.cpp:99
std::string m_pathFile
Definition xmlFile.hpp:169
iv::file::xml::node setChild(std::string_view name, std::string_view parentName="")
Definition xmlFile.cpp:182
bool setMetadata(uint16_t crcValue) const
Definition xmlFile.cpp:285
File(const File &other)=delete
std::string toString() const
Converts current XML data into string format.
Definition xmlFile.cpp:212
iv::types::timestamp lastTimeEdited() const
Definition xmlFile.cpp:165
uint16_t prvCalculateFileValidation() const
Definition xmlFile.cpp:261
Definition xmlFile.hpp:15
T getAttribute(const std::string_view key, T defaultValue) const
Definition xmlFile.hpp:33
std::string getText() const
Definition xmlFile.hpp:110
void removeAttributes()
Definition xmlFile.cpp:23
bool hasChild(std::string_view name) const
Definition xmlFile.cpp:67
bool isNull() const
Definition xmlFile.cpp:33
iv::file::xml::node getChild(std::string_view name) const
Definition xmlFile.cpp:43
void removeChildren()
Definition xmlFile.cpp:38
node & operator=(node &&other)=default
void setText(const std::string_view text) const
Definition xmlFile.hpp:105
bool addAttribute(const std::string_view key, T value)
Definition xmlFile.hpp:77
void removeChild(std::string_view name)
Definition xmlFile.cpp:28
node(const node &other)=default
std::vector< node > getChildren() const
Definition xmlFile.cpp:77
bool emptyNode() const
Definition xmlFile.cpp:18
node(node &&other)=default
std::string m_nodeName
Definition xmlFile.hpp:124
node & operator=(const node &other)=default
void appendNode(const iv::file::xml::node &_node)
Definition xmlFile.cpp:72
iv::file::xml::node appendChild(std::string_view name)
Definition xmlFile.cpp:53
constexpr bool always_false
Definition assert.hpp:14
Definition xmlFile.cpp:13
uint64_t timestamp
Definition types.hpp:21
Definition xmlFile.hpp:191
static constexpr uint64_t fileIntegrityInvalid
Definition xmlFile.hpp:192
Definition xmlFile.hpp:173
static constexpr std::string_view fileNameTmp
Definition xmlFile.hpp:174
Definition xmlFile.hpp:178
static constexpr std::string_view fileIntegrity
Definition xmlFile.hpp:179
static constexpr std::string_view lastPCEdited
Definition xmlFile.hpp:182
static constexpr std::string_view lastTimeEdited
Definition xmlFile.hpp:180
static constexpr std::string_view lastUserEdited
Definition xmlFile.hpp:181
Definition xmlFile.hpp:186
static constexpr std::string metadata
Definition xmlFile.hpp:187