15#ifndef XSD_CXX_TREE_ELEMENTS_HXX
16#define XSD_CXX_TREE_ELEMENTS_HXX
18#include <xsd/cxx/config.hxx>
32#include <xercesc/dom/DOMNode.hpp>
33#include <xercesc/dom/DOMAttr.hpp>
34#include <xercesc/dom/DOMElement.hpp>
35#include <xercesc/dom/DOMDocument.hpp>
36#include <xercesc/dom/DOMNamedNodeMap.hpp>
38#include <xercesc/util/XercesVersion.hpp>
40#include <xsd/cxx/xml/elements.hxx>
41#include <xsd/cxx/xml/dom/auto-ptr.hxx>
42#include <xsd/cxx/xml/dom/wildcard-source.hxx>
44#include <xsd/cxx/tree/facet.hxx>
46#include <xsd/cxx/tree/istream-fwd.hxx>
47#include <xsd/cxx/tree/containers-wildcard.hxx>
49#if _XERCES_VERSION < 30000
50# error Xerces-C++ 2-series is not supported
86 static const unsigned long keep_dom = 0x00000100UL;
96 static const unsigned long own_dom = 0x00000200UL;
130 static const unsigned long base = 0x01000000UL;
159 operator unsigned long ()
const
172 return flags (a.x_ | b.x_);
183 return flags (a.x_ | b);
194 return flags (a | b.x_);
204 template <
typename C>
252 struct user_data_keys_template
256 static const XMLCh node[21];
259 typedef user_data_keys_template<0> user_data_keys;
275 before (
const identity&)
const = 0;
278 throw_duplicate_id ()
const = 0;
281 identity (
const identity&);
284 operator= (
const identity&);
325 assert (map_.get () == 0 || map_->size () == 0);
349 template <
typename C>
379 return new type (*
this, f, c);
392 template <
typename S>
403 _type (
const xercesc::DOMElement& e,
426 template <
typename C>
427 _type (
const std::basic_string<C>& s,
428 const xercesc::DOMElement* e,
445 if (x.content_.get () == 0)
448 content_ = x.content_->clone ();
462 typedef element_optional dom_content_optional;
474 const dom_content_optional&
485 dom_content_optional&
534 const xercesc::DOMDocument&
546 xercesc::DOMDocument&
575 return x.content_.get () != 0 &&
576 x.content_->compare (y.content_.get ());
637 XSD_AUTO_PTR<map>& m (dr ? dr->map_ : map_);
641 if (c != 0 && map_.get () != 0)
647 m->insert (map_->begin (), map_->end ());
653 m = std::move (map_);
664 if (sr->map_.get () != 0)
668 for (map::iterator i (sr->map_->begin ()), e (sr->map_->end ());
672 for (; x !=
this && x != sr; x = x->
_container ()) ;
682 sr->map_->erase (i++);
704 for (
const container* c (r); c != 0; c = c->container_)
721 for (
container* c (r); c != 0; c = c->container_)
736 const xercesc::DOMNode*
739 return dom_info_.get () ? dom_info_->node() : 0;
751 return dom_info_.get () ? dom_info_->node () : 0;
769 return "DOM node is not an attribute node or element node";
788 switch (n->getNodeType ())
790 case xercesc::DOMNode::ELEMENT_NODE:
795 assert (
_root ()->
_node ()->getOwnerDocument () ==
796 n->getOwnerDocument ());
800 dom_info_factory::create (
801 *
static_cast<xercesc::DOMElement*
> (n),
807 case xercesc::DOMNode::ATTRIBUTE_NODE:
809 assert (container_ != 0);
811 assert (
_root ()->
_node ()->getOwnerDocument () ==
812 n->getOwnerDocument ());
815 dom_info_factory::create (
816 *
static_cast<xercesc::DOMAttr*
> (n),
832 _register_id (
const identity& i,
type* t)
836 assert (container_ == 0);
838 if (map_.get () == 0)
839 map_.reset (
new map);
842 std::pair<const identity*, type*> (&i, t)).second)
844 i.throw_duplicate_id ();
850 struct not_registered: std::exception
853 what ()
const throw ()
855 return "attempt to unregister non-existent id";
860 _unregister_id (
const identity&
id)
864 assert (container_ == 0);
866 if (map_.get () == 0 || map_->erase (&
id) == 0)
867 throw not_registered ();
871 _lookup_id (
const identity&
id)
const
875 map::const_iterator it (map_->find (&
id));
877 if (it != map_->end ())
896 virtual XSD_AUTO_PTR<dom_info>
897 clone (type& tree_node, container*)
const = 0;
899 virtual xercesc::DOMNode*
903 dom_info (
const dom_info&);
904 dom_info& operator= (
const dom_info&);
907 struct dom_element_info:
public dom_info
909 dom_element_info (xercesc::DOMElement& e, type& n,
bool root)
912 e_.setUserData (user_data_keys::node, &n, 0);
920 XSD_DOM_AUTO_PTR<xercesc::DOMDocument>* pd (
921 reinterpret_cast<XSD_DOM_AUTO_PTR<xercesc::DOMDocument>*
> (
922 e.getOwnerDocument ()->getUserData (user_data_keys::node)));
925 assert (pd->get () == e.getOwnerDocument ());
929 doc_ = std::move (*pd);
936 virtual XSD_AUTO_PTR<dom_info>
937 clone (type& tree_node, container* c)
const
946 return XSD_AUTO_PTR<dom_info> (
949 : new dom_element_info (*doc_, tree_node));
955 using xercesc::DOMNode;
957 DOMNode* cn (c->_node ());
960 return XSD_AUTO_PTR<dom_info> ();
966 using xercesc::DOMElement;
968 DOMNode& pn (*e_.getParentNode ());
969 assert (pn.getNodeType () == DOMNode::ELEMENT_NODE);
971 DOMNode* sn (pn.getFirstChild ());
972 DOMNode* dn (cn->getFirstChild ());
980 for (; sn != 0 && !e_.isSameNode (sn);)
982 sn = sn->getNextSibling ();
983 dn = dn->getNextSibling ();
990 assert (dn->getNodeType () == DOMNode::ELEMENT_NODE);
992 return XSD_AUTO_PTR<dom_info> (
993 new dom_element_info (
static_cast<DOMElement&
> (*dn),
999 virtual xercesc::DOMNode*
1006 dom_element_info (
const xercesc::DOMDocument& d, type& n)
1007 : doc_ (static_cast<xercesc::DOMDocument*> (
1008 d.cloneNode (true))),
1009 e_ (*doc_->getDocumentElement ())
1011 e_.setUserData (user_data_keys::node, &n, 0);
1015 XSD_DOM_AUTO_PTR<xercesc::DOMDocument> doc_;
1016 xercesc::DOMElement& e_;
1020 struct dom_attribute_info:
public dom_info
1022 dom_attribute_info (xercesc::DOMAttr& a, type& n)
1025 a_.setUserData (user_data_keys::node, &n, 0);
1028 virtual XSD_AUTO_PTR<dom_info>
1029 clone (type& tree_node, container* c)
const
1038 return XSD_AUTO_PTR<dom_info> ();
1044 using xercesc::DOMNode;
1046 DOMNode* cn (c->_node ());
1049 return XSD_AUTO_PTR<dom_info> ();
1054 using xercesc::DOMAttr;
1055 using xercesc::DOMElement;
1056 using xercesc::DOMNamedNodeMap;
1058 DOMElement& p (*a_.getOwnerElement ());
1059 DOMNamedNodeMap& nl (*p.getAttributes ());
1061 XMLSize_t size (nl.getLength ()), i (0);
1067 for ( ;i < size && !a_.isSameNode (nl.item (i)); ++i);
1073 DOMNode& n (*cn->getAttributes ()->item (i));
1074 assert (n.getNodeType () == DOMNode::ATTRIBUTE_NODE);
1076 return XSD_AUTO_PTR<dom_info> (
1077 new dom_attribute_info (
static_cast<DOMAttr&
> (n), tree_node));
1080 virtual xercesc::DOMNode*
1087 xercesc::DOMAttr& a_;
1092 struct dom_info_factory;
1093 friend struct _type::dom_info_factory;
1095 struct dom_info_factory
1097 static XSD_AUTO_PTR<dom_info>
1098 create (
const xercesc::DOMElement& e, type& n,
bool root)
1100 return XSD_AUTO_PTR<dom_info> (
1101 new dom_element_info (
1102 const_cast<xercesc::DOMElement&
> (e), n, root));
1105 static XSD_AUTO_PTR<dom_info>
1106 create (
const xercesc::DOMAttr& a, type& n)
1108 return XSD_AUTO_PTR<dom_info> (
1109 new dom_attribute_info (
1110 const_cast<xercesc::DOMAttr&
> (a), n));
1116 XSD_AUTO_PTR<dom_info> dom_info_;
1125 struct identity_comparator
1127 bool operator () (
const identity* x,
const identity* y)
const
1129 return x->before (*y);
1136 std::map<const identity*, type*, identity_comparator>
1139 XSD_AUTO_PTR<map> map_;
1154 virtual XSD_AUTO_PTR<content_type>
1158 compare (
const content_type*)
const = 0;
1161 content_type (
const content_type&);
1162 content_type& operator= (
const content_type&);
1165 struct dom_content_type: content_type
1168 : doc (xml::dom::create_document<char> ()), dom (*doc) {}
1171 dom_content_type (
const xercesc::DOMElement& e)
1172 : doc (xml::dom::create_document<char> ()), dom (e, *doc) {}
1175 dom_content_type (xercesc::DOMElement* e)
1176 : doc (xml::dom::create_document<char> ()), dom (e, *doc) {}
1179 dom_content_type (
const dom_content_optional& d)
1180 : doc (xml::dom::create_document<char> ()), dom (d, *doc) {}
1182 virtual XSD_AUTO_PTR<content_type>
1185 return XSD_AUTO_PTR<content_type> (
new dom_content_type (dom));
1189 compare (
const content_type* c)
const
1191 if (
const dom_content_type* dc =
1192 dynamic_cast<const dom_content_type*
> (c))
1193 return dom == dc->dom;
1199 XSD_DOM_AUTO_PTR<xercesc::DOMDocument> doc;
1200 dom_content_optional dom;
1203 mutable XSD_AUTO_PTR<content_type> content_;
1217 template <
typename C,
typename B>
1286 template <
typename S>
1325 const xercesc::DOMElement* e,
1339 const std::basic_string<C>&
1348 std::basic_string<C>&
1362 typedef typename B::content_type content_type;
1364 struct text_content_type: content_type
1366 text_content_type () {}
1369 text_content_type (
const std::basic_string<C>& t): text (t) {}
1372 text_content_type (
const C* t): text (t) {}
1374 virtual XSD_AUTO_PTR<content_type>
1377 return XSD_AUTO_PTR<content_type> (
new text_content_type (text));
1381 compare (
const content_type* c)
const
1383 if (
const text_content_type* tc =
1384 dynamic_cast<const text_content_type*
> (c))
1385 return text == tc->text;
1396 std::basic_string<C> text;
1410 template <
typename C,
typename T>
1438 virtual const std::basic_string<C>&
1448 virtual const std::basic_string<C>&
1491 template <
typename T,
1493 schema_type::value ST = schema_type::other>
1498 static XSD_AUTO_PTR<T>
1499 create (
const xercesc::DOMElement& e, flags f, container* c)
1501 return XSD_AUTO_PTR<T> (
new T (e, f, c));
1504 static XSD_AUTO_PTR<T>
1505 create (
const xercesc::DOMAttr& a, flags f, container* c)
1507 return XSD_AUTO_PTR<T> (
new T (a, f, c));
1510 static XSD_AUTO_PTR<T>
1511 create (
const std::basic_string<C>& s,
1512 const xercesc::DOMElement* e,
1516 return XSD_AUTO_PTR<T> (
new T (s, e, f, c));
1522 template <
typename S>
1523 static XSD_AUTO_PTR<T>
1524 create (istream<S>& s, flags f, container* c)
1526 return XSD_AUTO_PTR<T> (
new T (s, f, c));
1530 template <
typename B,
1532 schema_type::value ST>
1533 struct traits<simple_type<C, B>, C, ST>
1535 typedef simple_type<C, B>
type;
1537 static XSD_AUTO_PTR<type>
1538 create (
const xercesc::DOMElement& e, flags f, container* c)
1540 return XSD_AUTO_PTR<type> (
1541 new type (e, f | flags::extract_content, c));
1544 static XSD_AUTO_PTR<type>
1545 create (
const xercesc::DOMAttr& a, flags f, container* c)
1547 return XSD_AUTO_PTR<type> (
1548 new type (a, f | flags::extract_content, c));
1551 static XSD_AUTO_PTR<type>
1552 create (
const std::basic_string<C>& s,
1553 const xercesc::DOMElement* e,
1557 return XSD_AUTO_PTR<type> (
1558 new type (s, e, f | flags::extract_content, c));
1561 template <
typename S>
1562 static XSD_AUTO_PTR<type>
1563 create (istream<S>& s, flags f, container* c)
1565 return XSD_AUTO_PTR<type> (
1566 new type (s, f | flags::extract_content, c));
1578 template <
typename T,
1581 schema_type::value ST = schema_type::other>
1594 : facet_table_ (0), x_ ()
1604 : facet_table_ (0), x_ (x)
1621 : B (x, f, c), facet_table_ (0), x_ (x.x_)
1654 template <
typename S>
1691 const xercesc::DOMElement* e,
1719 operator const T& ()
const
1738#ifdef XSD_TREE_EXTRA_FUND_CONV
1745 template <
typename T2>
1746 operator T2 ()
const
1756 template <
typename T2>
1772 return facet_table_;
1788 const facet* facet_table_;
1802 template <
typename T,
typename C,
typename B, schema_type::value ST>
1817 template <
typename T,
typename C,
typename B, schema_type::value ST>
1832 template <
typename C>
1833 struct enum_comparator
1835 enum_comparator (
const C*
const* table)
1841 operator() (std::size_t i,
const std::basic_string<C>& s)
const
1843 return table_[i] < s;
1847 operator() (
const std::basic_string<C>& s, std::size_t i)
const
1849 return s < table_[i];
1859 operator() (std::size_t i, std::size_t j)
const
1861 return std::basic_string<C> (table_[i]) < table_[j];
1866 const C*
const* table_;
1874#include <xsd/cxx/tree/elements.ixx>
1875#include <xsd/cxx/tree/elements.txx>
Exception indicating that a DOM node cannot be associated with an object model node.
Definition elements.hxx:759
virtual const char * what() const
Get exception description.
Definition elements.hxx:767
Class corresponding to the XML Schema anyType built-in type.
Definition elements.hxx:318
container * _container()
Get a pointer to container, an object model node that contains this instance.
Definition elements.hxx:613
void _node(xercesc::DOMNode *n)
Manually set a DOM node associated with this object model node.
Definition elements.hxx:786
friend bool operator!=(const type &x, const type &y)
Comparison operator. It uses DOM (anyType) or text (anySimpleType) content if present....
Definition elements.hxx:587
virtual type * _clone(flags f=0, container *c=0) const
Copy the instance polymorphically.
Definition elements.hxx:377
xercesc::DOMDocument & dom_content_document()
Return a read-write reference to the DOM document associated with this anyType instance.
const xercesc::DOMDocument & dom_content_document() const
Return a read-only (constant) reference to the DOM document associated with this anyType instance.
void dom_content(xercesc::DOMElement *e)
Set the anyType DOM content.
void dom_content(const xercesc::DOMElement &e)
Set the anyType DOM content.
_type(const xercesc::DOMAttr &a, flags f=0, container *c=0)
Create an instance from a DOM Attribute.
container * _root()
Get a pointer to object model's root node.
Definition elements.hxx:717
_type(const type &x, flags f=0, container *c=0)
Copy constructor.
const container * _container() const
Get a constant pointer to container, an object model node that contains this instance.
Definition elements.hxx:600
type & operator=(const type &x)
Copy assignment operator.
Definition elements.hxx:441
void dom_content(const dom_content_optional &d)
Set the anyType DOM content.
_type(istream< S > &s, flags f=0, container *c=0)
Create an instance from a data representation stream.
bool null_content() const
Check for absence of DOM (anyType) and text (anySimpleType) content.
const xercesc::DOMNode * _node() const
Get a constant pointer to a DOM node associated with this object model node.
Definition elements.hxx:737
_type(const xercesc::DOMElement &e, flags f=flags::extract_content, container *c=0)
Create an instance from a DOM element.
xercesc::DOMNode * _node()
Get a pointer to a DOM node associated with this object model node.
Definition elements.hxx:749
_type()
Default constructor.
const container * _root() const
Get a constant pointer to object model's root node.
Definition elements.hxx:700
_type(const C *s)
Create an instance from a C string.
friend bool operator==(const type &x, const type &y)
Comparison operator. It uses DOM (anyType) or text (anySimpleType) content if present....
Definition elements.hxx:573
_type(const std::basic_string< C > &s, const xercesc::DOMElement *e, flags f=0, container *c=0)
Create an instance from a string fragment.
const dom_content_optional & dom_content() const
Return a read-only (constant) reference to the anyType DOM content.
virtual void _container(container *c)
Set this instance's new container, an object model node that contains this instance.
Definition elements.hxx:625
dom_content_optional & dom_content()
Return a read-write reference to the anyType DOM content.
Base class for element types.
Definition elements.hxx:1412
virtual T * _value()=0
Return the element value.
virtual element_type * _clone(flags f=0) const =0
Copy the instance polymorphically.
virtual const std::basic_string< C > & _namespace() const =0
Return the element namespace.
virtual const std::basic_string< C > & _name() const =0
Return the element name.
virtual const T * _value() const =0
Return the element value.
Parsing and serialization flags.
Definition elements.hxx:76
static const unsigned long dont_validate
Turn off XML Schema validation in the underlying XML parser.
Definition elements.hxx:102
static const unsigned long extract_content
Extract XML content for anyType or anySimpleType. Normally you don't need to specify this flag explic...
Definition elements.hxx:108
static const unsigned long dont_pretty_print
Do not add extra spaces or new lines that make the resulting XML easier to read.
Definition elements.hxx:124
friend flags operator|(const flags &a, const flags &b)
Combine two flags.
Definition elements.hxx:170
flags(unsigned long x=0)
Initialize an instance with an integer value.
Definition elements.hxx:149
static const unsigned long dont_initialize
Do not initialize the Xerces-C++ runtime.
Definition elements.hxx:113
static const unsigned long own_dom
Assume ownership of the DOM document.
Definition elements.hxx:96
static const unsigned long keep_dom
Keep DOM association in the resulting tree.
Definition elements.hxx:86
static const unsigned long no_xml_declaration
Do not write XML declaration during serialization.
Definition elements.hxx:118
Class template that emulates inheritance from a fundamental C++ type.
Definition elements.hxx:1583
fundamental_base(istream< S > &s, flags f=0, container *c=0)
Create an instance from a data representation stream.
fundamental_base & operator=(const T &x)
Assign an underlying type value to the instance.
Definition elements.hxx:1704
fundamental_base(T x)
Initialize an instance with an underlying type value.
Definition elements.hxx:1603
void _facet_table(const facet *ft)
Set the facet table associated with this type.
Definition elements.hxx:1782
virtual fundamental_base * _clone(flags f=0, container *c=0) const
Copy the instance polymorphically.
fundamental_base(const std::basic_string< C > &s, const xercesc::DOMElement *e, flags f=0, container *c=0)
Create an instance from a string fragment.
const facet * _facet_table() const
Get the facet table associated with this type.
Definition elements.hxx:1770
fundamental_base()
Default constructor.
Definition elements.hxx:1593
fundamental_base(const xercesc::DOMAttr &a, flags f=0, container *c=0)
Create an instance from a DOM Attribute.
fundamental_base(const xercesc::DOMElement &e, flags f=0, container *c=0)
Create an instance from a DOM element.
fundamental_base(const fundamental_base &x, flags f=0, container *c=0)
Copy constructor.
Definition elements.hxx:1618
Class corresponding to the XML Schema ID built-in type.
Definition types.hxx:1931
Definition elements.hxx:206
Class corresponding to the XML Schema anySimpleType built-in type.
Definition elements.hxx:1219
const std::basic_string< C > & text_content() const
Return a read-only (constant) reference to the anySimpleType text content.
simple_type(istream< S > &s, flags f=flags::extract_content, container *c=0)
Create an instance from a data representation stream.
void text_content(const std::basic_string< C > &t)
Set the anySimpleType text content.
simple_type(const xercesc::DOMElement &e, flags f=flags::extract_content, container *c=0)
Create an instance from a DOM element.
simple_type(const std::basic_string< C > &s)
Create an instance from a string.
virtual simple_type * _clone(flags f=0, container *c=0) const
Copy the instance polymorphically.
simple_type(const xercesc::DOMAttr &a, flags f=flags::extract_content, container *c=0)
Create an instance from a DOM Attribute.
simple_type(const simple_type &x, flags f=0, container *c=0)
Copy constructor.
std::basic_string< C > & text_content()
Return a read-write reference to the anySimpleType text content.
simple_type()
Default constructor.
simple_type(const std::basic_string< C > &s, const xercesc::DOMElement *e, flags f=flags::extract_content, container *c=0)
Create an instance from a string fragment.
simple_type(const C *s)
Create an instance from a C string.
Contains exception definitions for the C++/Tree mapping.
_type type
Class corresponding to the XML Schema anyType built-in type.
Definition elements.hxx:301
bool operator==(const buffer< C > &a, const buffer< C > &b)
buffer comparison operator.
Definition buffer.hxx:311
bool operator!=(const buffer< C > &a, const buffer< C > &b)
buffer comparison operator.
Definition buffer.hxx:325
_type container
Container type.
Definition elements.hxx:307
Content order sequence entry.
Definition elements.hxx:215
std::size_t id
Content id.
Definition elements.hxx:230
std::size_t index
Content index.
Definition elements.hxx:235
content_order(std::size_t id, std::size_t index=0)
Initialize an instance with passed id and index.
Definition elements.hxx:222