53#define NEOLIB_XML_USE_POOL_ALLOCATOR
57 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
69 typedef std::list<node_ptr, typename std::allocator_traits<allocator_type>::template rebind_alloc<node_ptr>> node_list;
81 iterator(
const iterator& aOther) : iNode(aOther.iNode), iIterator(aOther.iIterator), iFilter(aOther.iFilter) {}
82 iterator&
operator=(
const iterator& aOther) { iNode = aOther.iNode; iIterator = aOther.iIterator; iFilter = aOther.iFilter;
return *
this; }
90 while (*
this != endIterator && !((*iIterator)->type() & iFilter))
98 while (*
this != beginIterator && !((*iIterator)->type() & iFilter))
106 typename node::node_list::iterator
base()
const {
return iIterator; }
109 typename node::node_list::iterator iIterator;
128 while (*
this != endIterator && !((*iIterator)->type() & iFilter))
136 while (*
this != beginIterator && !((*iIterator)->type() & iFilter))
144 typename node::node_list::const_iterator
base()
const {
return iIterator; }
147 typename node::node_list::const_iterator iIterator;
160 bool empty()
const {
return iContent.empty(); }
161 const node&
back()
const {
return *iContent.back(); }
168 std::optional<const_iterator>
find_maybe(
const string& aName)
const;
169 template <
typename Exception>
172 std::optional<iterator>
find_maybe(
const string& aName);
174 template <
typename Exception>
179 std::unique_ptr<node> newNode(aNode);
180 iContent.push_back(0);
181 iContent.back() = newNode.release();
185 std::unique_ptr<node> newNode(aNode);
186 typename node_list::iterator i = iContent.insert(aIterator.
base(), 0);
187 *i = newNode.release();
192 delete *aIterator.
base();
193 iContent.erase(aIterator.
base());
197 for (
typename node_list::iterator i = iContent.begin(); i != iContent.end(); ++i)
204 const node_list& content()
const {
return iContent; }
205 node_list& content() {
return iContent; }
207 xml_node& operator=(
const xml_node&);
215 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
220 static void*
operator new(std::size_t) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_element>().allocate(1); }
221 static void operator delete(
void* ptr) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_element>().deallocate(
static_cast<xml_element*
>(ptr), 1); }
229 typedef std::map<string, string, std::less<string>,
typename std::allocator_traits<allocator_type>::template rebind_alloc<attribute>>
attribute_list;
254 const string&
name()
const {
return iName; }
262 const string&
attribute_value(
const string& aNewAttributeName,
const string& aOldAttributeName)
const;
267 const string&
text()
const;
269 string&
name() {
return iName; }
271 void set_attribute(
const string& aAttributeName,
const string& aAttributeValue);
279 mutable string iText;
280 bool iUseEmptyElementTag;
283 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
288 static void*
operator new(std::size_t) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_text>().allocate(1); }
289 static void operator delete(
void* ptr) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_text>().deallocate(
static_cast<xml_text*
>(ptr), 1); }
302 const string&
content()
const {
return iContent; }
310 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
315 static void*
operator new(std::size_t) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_comment>().allocate(1); }
316 static void operator delete(
void* ptr) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_comment>().deallocate(
static_cast<xml_comment*
>(ptr), 1); }
329 const string&
content()
const {
return iContent; }
337 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
342 static void*
operator new(std::size_t) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_declaration>().allocate(1); }
343 static void operator delete(
void* ptr) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_declaration>().deallocate(
static_cast<xml_declaration*
>(ptr), 1); }
356 const string&
content()
const {
return iContent; }
364 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
369 static void*
operator new(std::size_t) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_cdata>().allocate(1); }
370 static void operator delete(
void* ptr) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_cdata>().deallocate(
static_cast<xml_cdata*
>(ptr), 1); }
383 const string&
content()
const {
return iContent; }
391 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
396 static void*
operator new(std::size_t) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_dtd>().allocate(1); }
397 static void operator delete(
void* ptr) {
return typename std::allocator_traits<Alloc>::template rebind_alloc<xml_dtd>().deallocate(
static_cast<xml_dtd*
>(ptr), 1); }
410 const string&
content()
const {
return iContent; }
418 template <
typename CharT,
typename Alloc = std::allocator<CharT> >
435 typedef std::pair<string, string>
entity;
436 typedef std::list<entity, typename std::allocator_traits<allocator_type>::template rebind_alloc<entity>>
entity_list;
445 basic_xml(
bool aStripWhitespace =
false);
446 basic_xml(
const std::string& aPath,
bool aStripWhitespace =
false);
456 typename node::iterator
insert(
node& aParent,
typename node::iterator aPosition,
const CharT* aName);
458 void erase(
node& aParent,
typename node::iterator aPosition);
459 typename node::const_iterator
find(
const node& aParent,
const CharT* aName)
const;
460 typename node::iterator
find(
node& aParent,
const CharT* aName);
462 bool read(std::basic_istream<CharT>& aStream);
463 bool write(std::basic_ostream<CharT>& aStream);
464 bool error()
const {
return iError; }
465 void set_indent(CharT aIndentChar, std::size_t aIndentCount = 1);
470 struct tag : std::pair<typename string::view_const_iterator, typename string::view_const_iterator>
473 tag() : iType(
node::Element) {}
482 return basic_xml<CharT, Alloc>::sCommentEnd.size();
484 return basic_xml<CharT, Alloc>::sDeclarationEnd.size();
486 return basic_xml<CharT, Alloc>::sCdataEnd.size();
488 return basic_xml<CharT, Alloc>::sDtdEnd.size();
494 struct token : std::pair<typename string::view_const_iterator, typename string::view_const_iterator>
497 token() : iHasEntities(false) {}
499 tag next_tag(
typename string::view_const_iterator aNext,
typename string::view_const_iterator aDocumentEnd);
500 typename string::view_const_iterator parse(
node& aNode,
const tag& aStartTag,
typename string::view_const_iterator aDocumentEnd);
503 std::basic_ostream<CharT>& iStream;
504 bool iLastWasNewLine;
505 node_writer(std::basic_ostream<CharT>& aStream) : iStream(aStream), iLastWasNewLine(false) {}
506 template <
typename T>
510 node_writer& operator=(
const node_writer&);
512 void write_node(node_writer& aStream,
const node& aNode, std::size_t aIndent)
const;
513 string parse_entities(
const string& aString)
const;
514 string generate_entities(
const string& aString)
const;
515 void strip(
string& aString)
const;
516 void strip_if(
string& aString)
const;
517 token next_token(
const basic_character_map<CharT>& aDelimeters,
bool aIgnoreWhitespace,
typename string::view_const_iterator aCurrent,
typename string::view_const_iterator aEnd)
const;
521 std::basic_ostream<CharT>& (&endl)(std::basic_ostream<CharT>&);
525 string iDocumentText;
527 std::size_t iIndentCount;
528 bool iStripWhitespace;
530 static const basic_character_map<CharT> sNameDelimeter;
531 static const basic_character_map<CharT> sNameBadDelimeter;
532 static const basic_character_map<CharT> sAttributeValueDelimeter;
533 static const basic_character_map<CharT> sAttributeValueInvalidOne;
534 static const basic_character_map<CharT> sAttributeValueInvalidTwo;
535 static const basic_character_map<CharT> sTagDelimeter;
536 static const basic_character_map<CharT> sWhitespace;
537 static const string sCommentStart;
538 static const string sCommentEnd;
539 static const string sCdataStart;
540 static const string sCdataEnd;
541 static const string sDtdStart;
542 static const string sDtdEnd;
543 static const string sDeclarationStart;
544 static const string sDeclarationEnd;
545 static const string sEmptyTagWithAttributes;
546 static const string sEmptyTag;
549 #ifndef NEOLIB_XML_USE_POOL_ALLOCATOR
550 typedef basic_xml<char>
xml;
551 typedef basic_xml<wchar_t>
wxml;
const element & root() const
std::list< entity, typename std::allocator_traits< allocator_type >::template rebind_alloc< entity > > entity_list
xml_declaration< CharT, allocator_type > declaration
element::attribute_list attribute_list
xml_node< CharT, allocator_type > node
node::const_iterator find(const node &aParent, const CharT *aName) const
bool write(std::basic_ostream< CharT > &aStream)
xml_element< CharT, allocator_type > element
std::pair< string, string > entity
node::iterator insert(node &aParent, typename node::iterator aPosition, const CharT *aName)
node::iterator find_or_append(node &aParent, const CharT *aName)
void set_strip_whitespace(bool aStripWhitespace)
element & append(node &aParent, const CharT *aName)
xml_cdata< CharT, allocator_type > cdata
bool read(std::basic_istream< CharT > &aStream)
xml_dtd< CharT, allocator_type > dtd
element::attribute attribute
const node & document() const
void set_indent(CharT aIndentChar, std::size_t aIndentCount=1)
xml_text< CharT, allocator_type > text
xml_comment< CharT, allocator_type > comment
void erase(node &aParent, typename node::iterator aPosition)
xml_node< CharT, Alloc > node
const string & content() const
xml_cdata(const string &aContent=string())
const string & content() const
xml_declaration(const string &aContent=string())
xml_node< CharT, Alloc > node
xml_dtd(const string &aContent=string())
const string & content() const
xml_node< CharT, Alloc > node
const xml_element * operator->() const
const xml_element & operator*() const
const_iterator(const iterator &aIterator)
const_iterator(typename node::const_iterator aIterator)
xml_element * operator->() const
xml_element & operator*() const
iterator(typename node::iterator aIterator)
attribute_list & attributes()
const string & name() const
xml_element(const CharT *aName)
node::allocator_type allocator_type
xml_element & append(const CharT *aName)
xml_element(const string &aName)
xml_element & append(const std::string &aName)
void set_use_empty_element_tag(bool aUseEmptyElementTag)
node::iterator insert(typename node::iterator aPosition, const CharT *aName)
const string & text() const
bool has_attribute(const string &aAttributeName) const
const_iterator end() const
const attribute_list & attributes() const
xml_node< CharT, Alloc > node
void set_attribute(const string &aAttributeName, const string &aAttributeValue)
std::map< string, string, std::less< string >, typename std::allocator_traits< allocator_type >::template rebind_alloc< attribute > > attribute_list
void append_text(const string &aText)
bool use_empty_element_tag() const
const string & attribute_value(const string &aAttributeName) const
const_iterator begin() const
std::pair< const string, string > attribute
const_iterator & operator=(const const_iterator &aOther)
const_iterator(const iterator aIterator)
const_iterator operator--(int)
const_iterator(const const_iterator &aOther)
const node * operator->() const
const node & operator*() const
const_iterator & operator++()
bool operator==(const const_iterator &aOther) const
bool operator!=(const const_iterator &aOther) const
node::node_list::const_iterator base() const
const_iterator operator++(int)
const_iterator & operator--()
const_iterator & operator=(const iterator &aOther)
const_iterator(const node &aNode, typename node::node_list::const_iterator aIterator, typename node::type_e aFilter=node::All)
node * operator->() const
bool operator!=(const iterator &aOther) const
bool operator==(const iterator &aOther) const
node::node_list::iterator base() const
iterator(const iterator &aOther)
iterator & operator=(const iterator &aOther)
iterator(node &aNode, typename node::node_list::iterator aIterator, typename node::type_e aFilter=node::All)
iterator find_or_append(const string &aName)
const_iterator find_or_throw(const string &aName) const
void push_back(node_ptr aNode)
void erase(iterator aIterator)
iterator insert(iterator aIterator, node_ptr aNode)
std::optional< const_iterator > find_maybe(const string &aName) const
const_iterator find(const string &aName) const
xml_node(type_e aType=Document)
const_iterator end(type_e aFilter=All) const
const node & back() const
const_iterator begin(type_e aFilter=All) const
xml_node< CharT, allocator_type > node
basic_quick_string< CharT > string
const string & content() const
xml_text(const string &aContent=string())
xml_node< CharT, Alloc > node
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &aStream, const basic_point< T > &aPoint)
basic_xml< wchar_t, pool_allocator< char > > wxml
basic_xml< char, pool_allocator< char > > xml