7#ifndef MYGUI_XML_DOCUMENT_H_
8#define MYGUI_XML_DOCUMENT_H_
43 return a.mValue == b.mValue;
47 return a.mValue != b.mValue;
83 return getValueName(mValue);
87 std::string_view getValueName(
int _index)
const
89 if (_index < 0 || _index >=
MAX)
91 static const std::string_view values[
MAX] = {
92 "Failed to open XML file",
93 "Failed to create XML file",
94 "XML file contain incorrect content",
95 "XML file contain not closed elements",
96 "XML file without declaration",
97 "XML file contain closed but not opened element",
98 "XML file contain inconsistent elements",
99 "XML file contain more than one declaration",
100 "XML file contain more than one root element",
101 "XML file contain incorrect attribute"};
102 return values[_index];
125 ElementEnumerator(VectorElement::iterator _begin, VectorElement::iterator _end);
129 bool next(std::string_view _name);
135#ifndef MYGUI_DONT_USE_OBSOLETE
142 MYGUI_OBSOLETE(
"use : bool ElementEnumerator::next(std::string_view _name)")
157 VectorElement::iterator m_current, m_end;
170 std::string_view _name,
173 std::string_view _content = {});
177 void save(std::ostream& _stream,
size_t _level);
181 std::string_view _name,
182 std::string_view _content = {},
186 template<
typename T,
typename = std::enable_if_t<!std::is_convertible_v<T, std::
string_view>>>
192 void addAttribute(std::string_view _key, std::string_view _value);
194 void removeAttribute(std::string_view _key);
196 void setAttribute(std::string_view _key, std::string_view _value);
198 template<
typename T,
typename = std::enable_if_t<!std::is_convertible_v<T, std::
string_view>>>
204 void addContent(std::string_view _content);
206 template<
typename T,
typename = std::enable_if_t<!std::is_convertible_v<T, std::
string_view>>>
212 void setContent(std::string_view _content);
216 bool findAttribute(std::string_view _name, std::string& _value);
217 std::string_view findAttribute(std::string_view _name);
219 const std::string& getName()
const;
221 const std::string& getContent()
const;
231 std::unique_ptr<Element> createCopy();
234#ifndef MYGUI_DONT_USE_OBSOLETE
238 "use : template <typename T> void Element::addAttribute(const std::string &_key, const T& _value)")
243 MYGUI_OBSOLETE(
"use : void Element::addAttribute(std::string_view _key, std::string_view _value)")
250 MYGUI_OBSOLETE(
"use : template <typename T> void Element::addContent(const T& _content)")
255 MYGUI_OBSOLETE(
"use : void Element::addContent(std::string_view _content)")
261 MYGUI_OBSOLETE(
"use : template <typename T> void Element::setContent(const T& _content)")
266 MYGUI_OBSOLETE(
"use : void Element::setContent(std::string_view _content)")
277 MYGUI_OBSOLETE(
"use : ElementEnumerator Element::getElementEnumerator()")
287 std::string mContent;
301 bool open(
const std::string& _filename);
304 bool open(
const std::wstring& _filename);
307 bool open(std::istream& _stream);
314 bool save(
const std::string& _filename);
317 bool save(
const std::wstring& _filename);
319 bool save(std::ostream& _stream);
335#ifndef MYGUI_DONT_USE_OBSOLETE
338 "use : ElementPtr Document::createDeclaration(std::string_view _version, std::string_view _encoding)")
347 void setLastFileError(std::string_view _filename);
348 void setLastFileError(
const std::wstring& _filename);
350 bool parseTag(
ElementPtr& _currentNode, std::string _content);
352 bool checkPair(std::string& _key, std::string& _value);
354 bool parseLine(std::string& _line,
ElementPtr& _element);
357 size_t find(std::string_view _text,
char _char,
size_t _start = 0);
359 void clearDeclaration();
363 std::unique_ptr<Element> mRoot;
364 std::unique_ptr<Element> mDeclaration;
366 std::string mLastErrorFile;
#define MYGUI_OBSOLETE(text)
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
bool save(const std::string &_filename)
std::string getLastError() const
ElementPtr getRoot() const
ElementPtr createRoot(std::string_view _name)
ElementPtr createDeclaration(std::string_view _version="1.0", std::string_view _encoding="UTF-8")
bool open(const std::string &_filename)
ElementPtr createInfo(std::string_view _version="1.0", std::string_view _encoding="UTF-8")
ElementPtr operator->() const
const std::string & getContent() const
ElementEnumerator getNodeIterator()
ElementEnumerator getElementEnumerator()
Element(Element &&)=default
const std::string & getBody() const
Element(std::string_view _name, ElementPtr _parent, ElementType _type=ElementType::Normal, std::string_view _content={})
void addBody(const T &_content)
void addAttribute(std::string_view _key, const T &_value)
void addAttributes(std::string_view _key, const T &_value)
void setContent(const T &_content)
void setBody(const T &_content)
void addContent(const T &_content)
ElementPtr createChild(std::string_view _name, std::string_view _content={}, ElementType _type=ElementType::Normal)
std::string toString(T _value)
std::pair< std::string, std::string > PairAttribute
std::vector< PairAttribute > VectorAttributes
std::vector< std::unique_ptr< Element > > VectorElement
friend bool operator==(ElementType const &a, ElementType const &b)
friend bool operator!=(ElementType const &a, ElementType const &b)
ElementType(Enum _value=MAX)
std::string_view print() const
@ MoreThanOneXMLDeclaration
@ InconsistentOpenCloseElements
ErrorType(Enum _value=MAX)