From f0510d2f90467de8e8f260b47d79a9baaf9bef17 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Sep 2009 07:15:29 +0200 Subject: Start tracking XSD with git --- libxsd/xsd/cxx/tree/types.txx | 610 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 610 insertions(+) create mode 100644 libxsd/xsd/cxx/tree/types.txx (limited to 'libxsd/xsd/cxx/tree/types.txx') diff --git a/libxsd/xsd/cxx/tree/types.txx b/libxsd/xsd/cxx/tree/types.txx new file mode 100644 index 0000000..799c5fa --- /dev/null +++ b/libxsd/xsd/cxx/tree/types.txx @@ -0,0 +1,610 @@ +// file : xsd/cxx/tree/types.txx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include +#include +#include + +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + + // string + // + template + string* string:: + _clone (flags f, container* c) const + { + return new string (*this, f, c); + } + + + // normalized_string + // + template + normalized_string* normalized_string:: + _clone (flags f, container* c) const + { + return new normalized_string (*this, f, c); + } + + + // token + // + template + token* token:: + _clone (flags f, container* c) const + { + return new token (*this, f, c); + } + + + // nmtoken + // + template + nmtoken* nmtoken:: + _clone (flags f, container* c) const + { + return new nmtoken (*this, f, c); + } + + + // nmtokens + // + template + nmtokens* nmtokens:: + _clone (flags f, container* c) const + { + return new nmtokens (*this, f, c); + } + + + // name + // + template + name* name:: + _clone (flags f, container* c) const + { + return new name (*this, f, c); + } + + + // ncname + // + template + ncname* ncname:: + _clone (flags f, container* c) const + { + return new ncname (*this, f, c); + } + + + // language + // + template + language* language:: + _clone (flags f, container* c) const + { + return new language (*this, f, c); + } + + + // identity_impl + // + template + bool identity_impl:: + before (const identity& y) const + { + return id_ < static_cast (y).id_; + } + + template + void identity_impl:: + throw_duplicate_id () const + { + throw duplicate_id (id_); + } + + + // id + // + template + id* id:: + _clone (flags f, container* c) const + { + return new id (*this, f, c); + } + + template + id& id:: + operator= (C c) + { + unregister_id (); + base () = c; + register_id (); + + return *this; + } + + template + id& id:: + operator= (const C* s) + { + unregister_id (); + base () = s; + register_id (); + + return *this; + } + + template + id& id:: + operator= (const std::basic_string& s) + { + unregister_id (); + base () = s; + register_id (); + + return *this; + } + + template + id& id:: + operator= (const id& x) + { + unregister_id (); + base () = x; + register_id (); + + return *this; + } + + // It would have been cleaner to mention empty and _container + // with the using-declaration but HP aCC3 can't handle it in + // some non-trivial to track down cases. So we are going to use + // the old-n-ugly this-> techniques. + // + template + void id:: + _container (container* c) + { + B::_container (c); + register_id (); + } + + template + void id:: + register_id () + { + container* c (this->_container ()); + + if (c != 0 && !this->empty ()) + { + //std::cerr << "registering " << c + // << " as '" << *this + // << "' on " << c << std::endl; + + c->_register_id (identity_, c); + } + } + + template + void id:: + unregister_id () + { + container* c (this->_container ()); + + if (c != 0 && !this->empty ()) + { + //std::cerr << "un-registering " << c + // << " as '" << *this + // << "' on " << c << std::endl; + + c->_unregister_id (identity_); + } + } + + + // idref + // + template + idref* idref:: + _clone (flags f, container* c) const + { + return new idref (*this, f, c); + } + + // It would have been cleaner to mention empty, _root, etc. with + // the using-declaration but HP aCC3 can't handle it in some + // non-trivial to track down cases. So we are going to use the + // old-n-ugly this-> techniques. + // + template + const _type* idref:: + get_ () const + { + if (!this->empty () && this->_container () != 0) + { + return this->_root ()->_lookup_id (identity_); + } + else + return 0; + } + + template + _type* idref:: + get_ () + { + if (!this->empty () && this->_container () != 0) + { + return this->_root ()->_lookup_id (identity_); + } + else + return 0; + } + + template + void idref:: + true_ () + { + } + + + // idrefs + // + template + idrefs* idrefs:: + _clone (flags f, container* c) const + { + return new idrefs (*this, f, c); + } + + + // uri + // + template + uri* uri:: + _clone (flags f, container* c) const + { + return new uri (*this, f, c); + } + + + // qname + // + template + qname* qname:: + _clone (flags f, container* c) const + { + return new qname (*this, f, c); + } + + + // base64_binary + // + template + base64_binary:: + base64_binary (size_t size) + : buffer (size) + { + } + + template + base64_binary:: + base64_binary (size_t size, size_t capacity) + : buffer (size, capacity) + { + } + + template + base64_binary:: + base64_binary (const void* data, size_t size) + : buffer (data, size) + { + } + + template + base64_binary:: + base64_binary (const void* data, size_t size, size_t capacity) + : buffer (data, size, capacity) + { + } + + template + base64_binary:: + base64_binary (void* data, size_t size, size_t capacity, bool own) + : buffer (data, size, capacity, own) + { + } + + template + base64_binary* base64_binary:: + _clone (flags f, container* c) const + { + return new base64_binary (*this, f, c); + } + + // It would have been cleaner to mention size, and data with the + // using-declaration but HP aCC3 can't handle it in some non- + // trivial to track down cases. So we are going to use the + // old-n- ugly this-> techniques. + // + template + std::basic_string base64_binary:: + encode () const + { + // HP aCC3 cannot handle using namespace xercesc; + // + using xercesc::Base64; + std::basic_string str; + +#if _XERCES_VERSION >= 30000 + XMLSize_t n; + + xml::std_memory_manager mm; + auto_array r ( + Base64::encode ( + reinterpret_cast (this->data ()), + static_cast (this->size ()), + &n, + &mm), + mm); + + if (r) + { + str.reserve (n + 1); + str.resize (n); + + for (XMLSize_t i (0); i < n; ++i) + str[i] = C (r[i]); + } + else + { + //@@ throw + } +#else + unsigned int n; + + xml::std_memory_manager mm; + auto_array r ( + Base64::encode ( + reinterpret_cast (this->data ()), + static_cast (this->size ()), + &n, + &mm), + mm); + + if (r) + { + str.reserve (n + 1); + str.resize (n); + + for (unsigned int i (0); i < n; ++i) + str[i] = C (r[i]); + } + else + { + //@@ throw + } +#endif + + return str; + } + + template + void base64_binary:: + decode (const XMLCh* src) + { + // HP aCC3 cannot handle using namespace xercesc; + // + using xercesc::Base64; + + xml::std_memory_manager mm; + + // Xerces 2.6.0 and earlier do not have decodeToXMLByte which + // makes my life harder and your code slower. + // +#if _XERCES_VERSION >= 20700 + +#if _XERCES_VERSION >= 30000 + XMLSize_t size; + auto_array data ( + Base64::decodeToXMLByte (src, &size, &mm, Base64::Conf_RFC2045), + mm); +#else + unsigned int size; + auto_array data ( + Base64::decodeToXMLByte (src, &size, &mm, Base64::Conf_RFC2045), + mm); +#endif // _XERCES_VERSION >= 30000 + + if (data) + { + buffer tmp (data.get (), size, size, true); + data.release (); + this->swap (tmp); // g++ 4.1 likes it qualified, not sure why. + } + else + { + //@@ throw + } +#else + unsigned int size; + +#if _XERCES_VERSION >= 20600 // Xerces 2.5.0 does not have Conf_RFC2045. + auto_array data ( + Base64::decode (src, &size, &mm, Base64::Conf_RFC2045), + mm); +#else + auto_array data ( + Base64::decode (src, &size, &mm), mm); +#endif // _XERCES_VERSION >= 20600 + + if (data) + { + buffer tmp (size); + for (unsigned int i (0); i < size; ++i) + tmp.data ()[i] = static_cast (data[i]); + this->swap (tmp); // g++ 4.1 likes it qualified, not sure why. + } + else + { + //@@ throw + } +#endif //_XERCES_VERSION >= 20700 + } + + + // hex_binary + // + template + hex_binary:: + hex_binary (size_t size) + : buffer (size) + { + } + + template + hex_binary:: + hex_binary (size_t size, size_t capacity) + : buffer (size, capacity) + { + } + + template + hex_binary:: + hex_binary (const void* data, size_t size) + : buffer (data, size) + { + } + + template + hex_binary:: + hex_binary (const void* data, size_t size, size_t capacity) + : buffer (data, size, capacity) + { + } + + template + hex_binary:: + hex_binary (void* data, size_t size, size_t capacity, bool own) + : buffer (data, size, capacity, own) + { + } + + template + hex_binary* hex_binary:: + _clone (flags f, container* c) const + { + return new hex_binary (*this, f, c); + } + + // It would have been cleaner to mention size, and data with the + // using-declaration but HP aCC3 can't handle it in some non- + // trivial to track down cases. So we are going to use the + // old-n-ugly this-> techniques. + // + template + std::basic_string hex_binary:: + encode () const + { + std::basic_string str; + + const char tab[] = "0123456789ABCDEF"; + + if (size_t n = this->size ()) + { + str.reserve (2 * n + 1); + str.resize (2 * n); + + for (size_t i (0); i < n; ++i) + { + unsigned char byte ( + static_cast (*(this->data () + i))); + unsigned char h (byte >> 4); + unsigned char l (byte & 0x0F); + + str[2 * i] = C (tab[h]); + str[2 * i + 1] = C (tab[l]); + } + } + + return str; + } + + namespace bits + { + inline unsigned char + hex_decode (XMLCh c) + { + unsigned char r (0xFF); + + if (c >= '0' && c <= '9') + r = static_cast (c - '0'); + else if (c >= 'A' && c <= 'F') + r = static_cast (10 + (c - 'A')); + else if (c >= 'a' && c <= 'f') + r = static_cast (10 + (c - 'a')); + + return r; + } + } + + template + void hex_binary:: + decode (const XMLCh* src) + { + size_t src_n (xercesc::XMLString::stringLen (src)); + + if (src_n % 2 != 0) + return; // @@ throw + + size_t n (src_n / 2); + + buffer tmp (n); + + for (size_t i (0); i < n; ++i) + { + unsigned char h (bits::hex_decode (src[2 * i])); + unsigned char l (bits::hex_decode (src[2 * i + 1])); + + if (h == 0xFF || l == 0xFF) + return; //@@ throw + + tmp.data()[i] = (h << 4) | l; + } + + this->swap (tmp); // g++ 4.1 likes it qualified, not sure why. + } + + + // entity + // + template + entity* entity:: + _clone (flags f, container* c) const + { + return new entity (*this, f, c); + } + + + // entities + // + template + entities* entities:: + _clone (flags f, container* c) const + { + return new entities (*this, f, c); + } + } + } +} -- cgit v1.1