32 : name(e.name), data(e.data)
33 , children(e.children), attributes(e.attributes) {}
38 template<
typename String>
40 : name(std::forward<String>(name_)) {}
42 template<
typename String1,
typename String2>
44 : name(std::forward<String1>(name_)), data(std::forward<String2>(data_)) {}
47 [[nodiscard]]
const std::string&
getName()
const {
return name; }
50 template<
typename String>
51 void setName(String&& name_) { name = std::forward<String>(name_); }
54 [[nodiscard]]
const std::string&
getData()
const {
return data; }
56 template<
typename String>
58 assert(children.empty());
59 data = std::forward<String>(data_);
63 template<
typename String1,
typename String2>
66 attributes.emplace_back(std::forward<String1>(attrName),
67 std::forward<String2>(value));
70 template<
typename String1,
typename String2>
72 auto it = getAttributeIter(attrName);
73 if (it !=
end(attributes)) {
74 it->second = std::forward<String2>(value);
76 attributes.emplace_back(std::forward<String1>(attrName),
77 std::forward<String2>(value));
82 [[nodiscard]]
bool hasAttribute(std::string_view name)
const;
83 [[nodiscard]]
const std::string&
getAttribute(std::string_view attrName)
const;
84 [[nodiscard]] std::string_view
getAttribute(std::string_view attrName,
85 std::string_view defaultValue)
const;
87 [[nodiscard]]
const std::string*
findAttribute(std::string_view attrName)
const;
93 template<
typename String>
95 return children.emplace_back(std::forward<String>(childName));
98 template<
typename String1,
typename String2>
100 return children.emplace_back(std::forward<String1>(childName),
101 std::forward<String2>(childData));
106 [[nodiscard]]
bool hasChildren()
const {
return !children.empty(); }
114 bool defaultValue =
false)
const;
116 int defaultValue = 0)
const;
118 unsigned& result)
const;
127 std::string_view childName, std::string_view attrName,
128 std::string_view attValue)
const;
130 std::string_view childName, std::string_view attrName,
131 std::string_view attValue);
133 size_t& fromIndex)
const;
135 [[nodiscard]] std::vector<const XMLElement*>
getChildren(std::string_view childName)
const;
137 template<
typename String>
139 if (
auto* result =
findChild(childName)) {
142 return addChild(std::forward<String>(childName));
145 template<
typename String1,
typename String2>
147 if (
auto* result =
findChild(childName)) {
150 return addChild(std::forward<String1>(childName),
151 std::forward<String2>(defaultValue));
154 template<
typename String1,
typename String2,
typename String3>
156 String1&& childName, String2&& attrName, String3&& attValue)
161 auto& result =
addChild(std::forward<String1>(childName));
162 result.addAttribute(std::forward<String2>(attrName),
163 std::forward<String3>(attValue));
167 [[nodiscard]]
const std::string&
getChildData(std::string_view childName)
const;
168 [[nodiscard]] std::string_view
getChildData(std::string_view childName,
169 std::string_view defaultValue)
const;
171 bool defaultValue =
false)
const;
173 int defaultValue = 0)
const;
175 template<
typename String1,
typename String2>
177 if (
auto* child =
findChild(childName)) {
178 child->setData(std::forward<String2>(value));
180 addChild(std::forward<String1>(childName),
181 std::forward<String2>(value));
188 [[nodiscard]] std::string
dump()
const;
189 [[nodiscard]]
static std::string
XMLEscape(std::string_view str);
191 template<
typename Archive>
192 void serialize(Archive& ar,
unsigned version);
198 using Attribute = std::pair<std::string, std::string>;
199 using Attributes = std::vector<Attribute>;
200 [[nodiscard]] Attributes::iterator getAttributeIter(std::string_view attrName);
201 [[nodiscard]] Attributes::const_iterator getAttributeIter(std::string_view attrName)
const;
202 void dump(std::string& result,
unsigned indentNum)
const;
207 Attributes attributes;
static std::string XMLEscape(std::string_view str)
static std::unique_ptr< FileContext > getLastSerializedFileContext()
void serialize(Archive &ar, unsigned version)
XMLElement & addChild(String1 &&childName, String2 &&childData)
void removeAttribute(std::string_view name)
void addAttribute(String1 &&attrName, String2 &&value)
XMLElement & addChild(String &&childName)
void setAttribute(String1 &&attrName, String2 &&value)
const XMLElement * findChild(std::string_view childName) const
const std::string & getName() const
const Children & getChildren() const
XMLElement(XMLElement &x)
XMLElement(XMLElement &&)=default
const XMLElement * findNextChild(std::string_view name, size_t &fromIndex) const
std::vector< XMLElement > Children
int getAttributeAsInt(std::string_view attrName, int defaultValue=0) const
void setName(String &&name_)
void setData(String &&data_)
const std::string & getData() const
bool findAttributeInt(std::string_view attrName, unsigned &result) const
bool hasAttribute(std::string_view name) const
XMLElement & operator=(XMLElement &&)=default
const std::string & getChildData(std::string_view childName) const
XMLElement(const XMLElement &e)
void removeChild(const XMLElement &child)
XMLElement & getCreateChild(String1 &&childName, String2 &&defaultValue)
const XMLElement & getChild(std::string_view childName) const
const XMLElement * findChildWithAttribute(std::string_view childName, std::string_view attrName, std::string_view attValue) const
bool getAttributeAsBool(std::string_view attrName, bool defaultValue=false) const
int getChildDataAsInt(std::string_view childName, int defaultValue=0) const
void setChildData(String1 &&childName, String2 &&value)
XMLElement & getCreateChild(String &&childName)
XMLElement & getCreateChildWithAttribute(String1 &&childName, String2 &&attrName, String3 &&attValue)
XMLElement(String1 &&name_, String2 &&data_)
XMLElement(String &&name_)
bool getChildDataAsBool(std::string_view childName, bool defaultValue=false) const
const std::string & getAttribute(std::string_view attrName) const
XMLElement & operator=(const XMLElement &)=default
const std::string * findAttribute(std::string_view attrName) const
This file implemented 3 utility functions:
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
constexpr KeyMatrixPosition x
Keyboard bindings.
constexpr auto end(const zstring_view &x)