From 2615896faa646e5830abf2c269150e1165c66515 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 18 Dec 2020 18:48:46 +0300 Subject: Switch to build2 --- libxsd/libxsd/cxx/tree/ace-cdr-stream-common.hxx | 24 + .../libxsd/cxx/tree/ace-cdr-stream-extraction.hxx | 346 ++ .../libxsd/cxx/tree/ace-cdr-stream-insertion.hxx | 247 ++ libxsd/libxsd/cxx/tree/bits/literals.hxx | 259 ++ libxsd/libxsd/cxx/tree/bits/literals.ixx | 874 +++++ libxsd/libxsd/cxx/tree/buffer.hxx | 335 ++ libxsd/libxsd/cxx/tree/buffer.txx | 145 + libxsd/libxsd/cxx/tree/comparison-map.hxx | 111 + libxsd/libxsd/cxx/tree/comparison-map.txx | 298 ++ libxsd/libxsd/cxx/tree/containers-wildcard.hxx | 1337 +++++++ libxsd/libxsd/cxx/tree/containers.hxx | 1200 ++++++ libxsd/libxsd/cxx/tree/containers.txx | 295 ++ libxsd/libxsd/cxx/tree/date-time-extraction.txx | 155 + libxsd/libxsd/cxx/tree/date-time-insertion.txx | 186 + libxsd/libxsd/cxx/tree/date-time-ostream.txx | 322 ++ libxsd/libxsd/cxx/tree/date-time.hxx | 1949 ++++++++++ libxsd/libxsd/cxx/tree/date-time.ixx | 891 +++++ libxsd/libxsd/cxx/tree/date-time.txx | 92 + libxsd/libxsd/cxx/tree/element-map.hxx | 146 + libxsd/libxsd/cxx/tree/element-map.txx | 69 + libxsd/libxsd/cxx/tree/elements.hxx | 1867 +++++++++ libxsd/libxsd/cxx/tree/elements.ixx | 265 ++ libxsd/libxsd/cxx/tree/elements.txx | 55 + libxsd/libxsd/cxx/tree/error-handler.hxx | 60 + libxsd/libxsd/cxx/tree/error-handler.txx | 30 + libxsd/libxsd/cxx/tree/exceptions.hxx | 1032 +++++ libxsd/libxsd/cxx/tree/exceptions.txx | 508 +++ libxsd/libxsd/cxx/tree/facet.hxx | 41 + libxsd/libxsd/cxx/tree/istream-fwd.hxx | 19 + libxsd/libxsd/cxx/tree/istream.hxx | 453 +++ libxsd/libxsd/cxx/tree/iterator-adapter.hxx | 269 ++ libxsd/libxsd/cxx/tree/list.hxx | 133 + libxsd/libxsd/cxx/tree/ostream.hxx | 290 ++ libxsd/libxsd/cxx/tree/parsing.hxx | 10 + libxsd/libxsd/cxx/tree/parsing.txx | 918 +++++ libxsd/libxsd/cxx/tree/parsing/boolean.hxx | 74 + libxsd/libxsd/cxx/tree/parsing/byte.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/date-time.txx | 700 ++++ libxsd/libxsd/cxx/tree/parsing/decimal.hxx | 83 + libxsd/libxsd/cxx/tree/parsing/double.hxx | 92 + libxsd/libxsd/cxx/tree/parsing/element-map.txx | 40 + libxsd/libxsd/cxx/tree/parsing/float.hxx | 92 + libxsd/libxsd/cxx/tree/parsing/int.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/long.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/short.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/unsigned-byte.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/unsigned-int.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/unsigned-long.hxx | 78 + libxsd/libxsd/cxx/tree/parsing/unsigned-short.hxx | 78 + libxsd/libxsd/cxx/tree/serialization.hxx | 64 + libxsd/libxsd/cxx/tree/serialization.txx | 801 ++++ libxsd/libxsd/cxx/tree/serialization/boolean.hxx | 50 + libxsd/libxsd/cxx/tree/serialization/byte.hxx | 44 + libxsd/libxsd/cxx/tree/serialization/date-time.txx | 618 +++ libxsd/libxsd/cxx/tree/serialization/decimal.hxx | 124 + libxsd/libxsd/cxx/tree/serialization/double.hxx | 94 + .../libxsd/cxx/tree/serialization/element-map.txx | 38 + libxsd/libxsd/cxx/tree/serialization/float.hxx | 92 + libxsd/libxsd/cxx/tree/serialization/int.hxx | 44 + libxsd/libxsd/cxx/tree/serialization/long.hxx | 44 + libxsd/libxsd/cxx/tree/serialization/short.hxx | 44 + .../cxx/tree/serialization/unsigned-byte.hxx | 44 + .../libxsd/cxx/tree/serialization/unsigned-int.hxx | 44 + .../cxx/tree/serialization/unsigned-long.hxx | 44 + .../cxx/tree/serialization/unsigned-short.hxx | 44 + libxsd/libxsd/cxx/tree/std-ostream-map.hxx | 112 + libxsd/libxsd/cxx/tree/std-ostream-map.txx | 291 ++ libxsd/libxsd/cxx/tree/std-ostream-operators.hxx | 276 ++ libxsd/libxsd/cxx/tree/stream-extraction-map.hxx | 105 + libxsd/libxsd/cxx/tree/stream-extraction-map.txx | 331 ++ libxsd/libxsd/cxx/tree/stream-extraction.hxx | 304 ++ libxsd/libxsd/cxx/tree/stream-insertion-map.hxx | 152 + libxsd/libxsd/cxx/tree/stream-insertion-map.txx | 355 ++ libxsd/libxsd/cxx/tree/stream-insertion.hxx | 275 ++ libxsd/libxsd/cxx/tree/text.hxx | 28 + libxsd/libxsd/cxx/tree/text.txx | 61 + libxsd/libxsd/cxx/tree/type-factory-map.hxx | 173 + libxsd/libxsd/cxx/tree/type-factory-map.txx | 481 +++ libxsd/libxsd/cxx/tree/type-serializer-map.hxx | 234 ++ libxsd/libxsd/cxx/tree/type-serializer-map.txx | 572 +++ libxsd/libxsd/cxx/tree/types.hxx | 3946 ++++++++++++++++++++ libxsd/libxsd/cxx/tree/types.txx | 528 +++ libxsd/libxsd/cxx/tree/xdr-stream-common.hxx | 24 + libxsd/libxsd/cxx/tree/xdr-stream-extraction.hxx | 306 ++ libxsd/libxsd/cxx/tree/xdr-stream-insertion.hxx | 270 ++ 85 files changed, 27993 insertions(+) create mode 100644 libxsd/libxsd/cxx/tree/ace-cdr-stream-common.hxx create mode 100644 libxsd/libxsd/cxx/tree/ace-cdr-stream-extraction.hxx create mode 100644 libxsd/libxsd/cxx/tree/ace-cdr-stream-insertion.hxx create mode 100644 libxsd/libxsd/cxx/tree/bits/literals.hxx create mode 100644 libxsd/libxsd/cxx/tree/bits/literals.ixx create mode 100644 libxsd/libxsd/cxx/tree/buffer.hxx create mode 100644 libxsd/libxsd/cxx/tree/buffer.txx create mode 100644 libxsd/libxsd/cxx/tree/comparison-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/comparison-map.txx create mode 100644 libxsd/libxsd/cxx/tree/containers-wildcard.hxx create mode 100644 libxsd/libxsd/cxx/tree/containers.hxx create mode 100644 libxsd/libxsd/cxx/tree/containers.txx create mode 100644 libxsd/libxsd/cxx/tree/date-time-extraction.txx create mode 100644 libxsd/libxsd/cxx/tree/date-time-insertion.txx create mode 100644 libxsd/libxsd/cxx/tree/date-time-ostream.txx create mode 100644 libxsd/libxsd/cxx/tree/date-time.hxx create mode 100644 libxsd/libxsd/cxx/tree/date-time.ixx create mode 100644 libxsd/libxsd/cxx/tree/date-time.txx create mode 100644 libxsd/libxsd/cxx/tree/element-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/element-map.txx create mode 100644 libxsd/libxsd/cxx/tree/elements.hxx create mode 100644 libxsd/libxsd/cxx/tree/elements.ixx create mode 100644 libxsd/libxsd/cxx/tree/elements.txx create mode 100644 libxsd/libxsd/cxx/tree/error-handler.hxx create mode 100644 libxsd/libxsd/cxx/tree/error-handler.txx create mode 100644 libxsd/libxsd/cxx/tree/exceptions.hxx create mode 100644 libxsd/libxsd/cxx/tree/exceptions.txx create mode 100644 libxsd/libxsd/cxx/tree/facet.hxx create mode 100644 libxsd/libxsd/cxx/tree/istream-fwd.hxx create mode 100644 libxsd/libxsd/cxx/tree/istream.hxx create mode 100644 libxsd/libxsd/cxx/tree/iterator-adapter.hxx create mode 100644 libxsd/libxsd/cxx/tree/list.hxx create mode 100644 libxsd/libxsd/cxx/tree/ostream.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing.txx create mode 100644 libxsd/libxsd/cxx/tree/parsing/boolean.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/byte.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/date-time.txx create mode 100644 libxsd/libxsd/cxx/tree/parsing/decimal.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/double.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/element-map.txx create mode 100644 libxsd/libxsd/cxx/tree/parsing/float.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/int.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/long.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/short.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/unsigned-byte.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/unsigned-int.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/unsigned-long.hxx create mode 100644 libxsd/libxsd/cxx/tree/parsing/unsigned-short.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization.txx create mode 100644 libxsd/libxsd/cxx/tree/serialization/boolean.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/byte.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/date-time.txx create mode 100644 libxsd/libxsd/cxx/tree/serialization/decimal.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/double.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/element-map.txx create mode 100644 libxsd/libxsd/cxx/tree/serialization/float.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/int.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/long.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/short.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/unsigned-byte.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/unsigned-int.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/unsigned-long.hxx create mode 100644 libxsd/libxsd/cxx/tree/serialization/unsigned-short.hxx create mode 100644 libxsd/libxsd/cxx/tree/std-ostream-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/std-ostream-map.txx create mode 100644 libxsd/libxsd/cxx/tree/std-ostream-operators.hxx create mode 100644 libxsd/libxsd/cxx/tree/stream-extraction-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/stream-extraction-map.txx create mode 100644 libxsd/libxsd/cxx/tree/stream-extraction.hxx create mode 100644 libxsd/libxsd/cxx/tree/stream-insertion-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/stream-insertion-map.txx create mode 100644 libxsd/libxsd/cxx/tree/stream-insertion.hxx create mode 100644 libxsd/libxsd/cxx/tree/text.hxx create mode 100644 libxsd/libxsd/cxx/tree/text.txx create mode 100644 libxsd/libxsd/cxx/tree/type-factory-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/type-factory-map.txx create mode 100644 libxsd/libxsd/cxx/tree/type-serializer-map.hxx create mode 100644 libxsd/libxsd/cxx/tree/type-serializer-map.txx create mode 100644 libxsd/libxsd/cxx/tree/types.hxx create mode 100644 libxsd/libxsd/cxx/tree/types.txx create mode 100644 libxsd/libxsd/cxx/tree/xdr-stream-common.hxx create mode 100644 libxsd/libxsd/cxx/tree/xdr-stream-extraction.hxx create mode 100644 libxsd/libxsd/cxx/tree/xdr-stream-insertion.hxx (limited to 'libxsd/libxsd/cxx/tree') diff --git a/libxsd/libxsd/cxx/tree/ace-cdr-stream-common.hxx b/libxsd/libxsd/cxx/tree/ace-cdr-stream-common.hxx new file mode 100644 index 0000000..4bcc151 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/ace-cdr-stream-common.hxx @@ -0,0 +1,24 @@ +// file : libxsd/cxx/tree/ace-cdr-stream-common.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX +#define LIBXSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // Base exception for ACE CDR insertion/extraction exceptions. + // + struct ace_cdr_stream_operation: xsd::cxx::exception + { + }; + } + } +} + +#endif // LIBXSD_CXX_TREE_ACE_CDR_STREAM_COMMON_HXX diff --git a/libxsd/libxsd/cxx/tree/ace-cdr-stream-extraction.hxx b/libxsd/libxsd/cxx/tree/ace-cdr-stream-extraction.hxx new file mode 100644 index 0000000..c6d4876 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/ace-cdr-stream-extraction.hxx @@ -0,0 +1,346 @@ +// file : libxsd/cxx/tree/ace-cdr-stream-extraction.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX +#define LIBXSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX + +#include // std::size_t +#include + +#include // ACE::strdelete +#include + +#include // XSD_CXX11 + +#ifdef XSD_CXX11 +# include // std::unique_ptr +#else +# include +#endif + +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct ace_cdr_stream_extraction: ace_cdr_stream_operation + { + virtual const char* + what () const throw () + { + return "ACE CDR stream extraction operation failed"; + } + }; + + + // as_size + // + +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template + inline istream& + operator>> (istream& s, + istream::as_size& x) + { + ACE_CDR::ULongLong r; + + if (!s.impl ().read_ulonglong (r) || + r > ~(T (0))) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } +#else + template + inline istream& + operator>> (istream& s, + istream::as_size& x) + { + ACE_CDR::ULong r; + + if (!s.impl ().read_ulong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } +#endif + + + // 8-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int8& x) + { + ACE_CDR::Octet r; + + if (!s.impl ().read_octet (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint8& x) + { + ACE_CDR::Octet r; + + if (!s.impl ().read_octet (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // 16-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int16& x) + { + ACE_CDR::Short r; + + if (!s.impl ().read_short (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint16& x) + { + ACE_CDR::UShort r; + + if (!s.impl ().read_ushort (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // 32-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int32& x) + { + ACE_CDR::Long r; + + if (!s.impl ().read_long (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint32& x) + { + ACE_CDR::ULong r; + + if (!s.impl ().read_ulong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // 64-bit + // + template + inline istream& + operator>> (istream& s, + istream::as_int64& x) + { + ACE_CDR::LongLong r; + + if (!s.impl ().read_longlong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_uint64& x) + { + ACE_CDR::ULongLong r; + + if (!s.impl ().read_ulonglong (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // Boolean + // + template + inline istream& + operator>> (istream& s, + istream::as_bool& x) + { + ACE_CDR::Boolean r; + + if (!s.impl ().read_boolean (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + + // Floating-point + // + template + inline istream& + operator>> (istream& s, + istream::as_float32& x) + { + ACE_CDR::Float r; + + if (!s.impl ().read_float (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + template + inline istream& + operator>> (istream& s, + istream::as_float64& x) + { + ACE_CDR::Double r; + + if (!s.impl ().read_double (r)) + throw ace_cdr_stream_extraction (); + + x.x_ = static_cast (r); + + return s; + } + + // Extraction of std::basic_string. + // + + namespace bits + { + template + struct ace_str_deleter + { + void + operator() (C* s) const + { + ACE::strdelete (s); + } + }; + } + + inline istream& + operator>> (istream& s, std::basic_string& x) + { + typedef bits::ace_str_deleter deleter; + + deleter d; + char* r; + + if (!s.impl ().read_string (r)) + throw ace_cdr_stream_extraction (); + +#ifdef XSD_CXX11 + std::unique_ptr ar ( +#else + auto_array ar ( +#endif + r, d); + + x = r; + return s; + } + +#ifdef ACE_HAS_WCHAR + inline istream& + operator>> (istream& s, std::basic_string& x) + { + typedef bits::ace_str_deleter deleter; + + deleter d; + wchar_t* r; + + if (!s.impl ().read_wstring (r)) + throw ace_cdr_stream_extraction (); + +#ifdef XSD_CXX11 + std::unique_ptr ar ( +#else + auto_array ar ( +#endif + r, d); + + x = r; + return s; + } +#endif + + + // Extraction of a binary buffer. + // + template + istream& + operator>> (istream& s, buffer& x) + { + ACE_CDR::ULong size; + + if (!s.impl ().read_ulong (size)) + throw ace_cdr_stream_extraction (); + + x.size (size); + + if (!s.impl ().read_octet_array ( + reinterpret_cast (x.data ()), size)) + throw ace_cdr_stream_extraction (); + + return s; + } + } + } +} + +#endif // LIBXSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX diff --git a/libxsd/libxsd/cxx/tree/ace-cdr-stream-insertion.hxx b/libxsd/libxsd/cxx/tree/ace-cdr-stream-insertion.hxx new file mode 100644 index 0000000..4be3fc5 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/ace-cdr-stream-insertion.hxx @@ -0,0 +1,247 @@ +// file : libxsd/cxx/tree/ace-cdr-stream-insertion.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX +#define LIBXSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX + +#include // std::size_t +#include + +#include + +#include +#include +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + struct ace_cdr_stream_insertion: ace_cdr_stream_operation + { + virtual const char* + what () const throw () + { + return "ACE CDR stream insertion operation failed"; + } + }; + + + // as_size + // + +#ifdef XSD_CXX_TREE_USE_64_BIT_SIZE + template + inline ostream& + operator<< (ostream& s, + ostream::as_size x) + { + if (!s.impl ().write_ulonglong ( + static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } +#else + template + inline ostream& + operator<< (ostream& s, + ostream::as_size x) + { + if (x.x_ > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_ulong (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + + return s; + } +#endif + + + // 8-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int8 x) + { + ACE_CDR::Octet r (static_cast (x.x_)); + + if (!s.impl ().write_octet (r)) + throw ace_cdr_stream_insertion (); + + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint8 x) + { + ACE_CDR::Octet r (static_cast (x.x_)); + + if (!s.impl ().write_octet (r)) + throw ace_cdr_stream_insertion (); + + return s; + } + + + // 16-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int16 x) + { + if (!s.impl ().write_short (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint16 x) + { + if (!s.impl ().write_ushort (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // 32-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int32 x) + { + if (!s.impl ().write_long (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint32 x) + { + if (!s.impl ().write_ulong (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // 64-bit + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_int64 x) + { + if (!s.impl ().write_longlong (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_uint64 x) + { + if (!s.impl ().write_ulonglong ( + static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // Boolean + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_bool x) + { + if (!s.impl ().write_boolean (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + + // Floating-point + // + template + inline ostream& + operator<< (ostream& s, + ostream::as_float32 x) + { + if (!s.impl ().write_float (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + template + inline ostream& + operator<< (ostream& s, + ostream::as_float64 x) + { + if (!s.impl ().write_double (static_cast (x.x_))) + throw ace_cdr_stream_insertion (); + return s; + } + + // Insertion of std::basic_string. + // + + inline ostream& + operator<< (ostream& s, const std::basic_string& x) + { + // ACE CDR strings are hard-wired with a 32 bit length. + // + if (x.length () > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_string ( + static_cast (x.length ()), x.c_str ())) + throw ace_cdr_stream_insertion (); + return s; + } + +#ifdef ACE_HAS_WCHAR + inline ostream& + operator<< (ostream& s, + const std::basic_string& x) + { + // ACE CDR strings are hard-wired with a 32 bit length. + // + if (x.length () > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_wstring ( + static_cast (x.length ()), x.c_str ())) + throw ace_cdr_stream_insertion (); + return s; + } +#endif + + // Insertion of a binary buffer. + // + template + ostream& + operator<< (ostream& s, const buffer& x) + { + std::size_t size (x.size ()); + + // It is not possible to write an array with a 64-bit size. + // + if (size > ~(ACE_CDR::ULong (0)) || + !s.impl ().write_ulong (static_cast (size)) || + !s.impl ().write_octet_array ( + reinterpret_cast (x.data ()), size)) + throw ace_cdr_stream_insertion (); + + return s; + } + } + } +} + +#endif // LIBXSD_CXX_TREE_ACE_CDR_STREAM_INSERTION_HXX diff --git a/libxsd/libxsd/cxx/tree/bits/literals.hxx b/libxsd/libxsd/cxx/tree/bits/literals.hxx new file mode 100644 index 0000000..672eab1 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/bits/literals.hxx @@ -0,0 +1,259 @@ +// file : libxsd/cxx/tree/bits/literals.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_BITS_LITERALS_HXX +#define LIBXSD_CXX_TREE_BITS_LITERALS_HXX + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // Boolean literals + // + template + const C* + true_ (); + + template + const C* + one (); + + // Float literals: INF -INF NaN. + // + template + const C* + positive_inf (); + + template + const C* + negative_inf (); + + template + const C* + nan (); + + // Optional "not present" literal. + // + template + const C* + not_present (); + + // XML Schema namespace + // + template + const C* + xml_schema (); + + // Built-in XML Schema type names. + // + template + const C* + any_type (); + + template + const C* + any_simple_type (); + + template + const C* + string (); + + template + const C* + normalized_string (); + + template + const C* + token (); + + template + const C* + name (); + + template + const C* + nmtoken (); + + template + const C* + nmtokens (); + + template + const C* + ncname (); + + template + const C* + language (); + + template + const C* + id (); + + template + const C* + idref (); + + template + const C* + idrefs (); + + template + const C* + any_uri (); + + template + const C* + qname (); + + template + const C* + base64_binary (); + + template + const C* + hex_binary (); + + template + const C* + date (); + + template + const C* + date_time (); + + template + const C* + duration (); + + template + const C* + gday (); + + template + const C* + gmonth (); + + template + const C* + gmonth_day (); + + template + const C* + gyear (); + + template + const C* + gyear_month (); + + template + const C* + time (); + + template + const C* + entity (); + + template + const C* + entities (); + + // gday ("---") and gmonth ("--") prefixes. + // + template + const C* + gday_prefix (); + + template + const C* + gmonth_prefix (); + + // Exception and diagnostics string literals. + // + template + const C* + ex_error_error (); // " error: " + + template + const C* + ex_error_warning (); // " warning: " + + template + const C* + ex_parsing_msg (); // "instance document parsing failed" + + template + const C* + ex_eel_expected (); // "expected element '" + + template + const C* + ex_uel_expected (); // "expected element '" + + template + const C* + ex_uel_instead (); // "' instead of '" + + template + const C* + ex_uel_unexpected (); // "unexpected element '" + + template + const C* + ex_eat_expected (); // "expected attribute '" + + template + const C* + ex_uen_unexpected (); // "unexpected enumerator '" + + template + const C* + ex_etc_msg (); // "expected text content" + + template + const C* + ex_nti_no_type_info (); // "no type information available for type '" + + template + const C* + ex_nei_no_element_info (); // "no parsing or serialization information + // available for element '" + template + const C* + ex_nd_type (); // "type '" + + template + const C* + ex_nd_not_derived (); // "' is not derived from '" + + template + const C* + ex_di_id (); // "ID '" + + template + const C* + ex_di_already_exist (); // "' already exist" + + template + const C* + ex_serialization_msg (); // "serialization failed" + + template + const C* + ex_npm_no_mapping (); // "no mapping provided for namespace prefix '" + + template + const C* + ex_bounds_msg (); // "buffer boundary rules have been violated" + } + } + } +} + +#endif // LIBXSD_CXX_TREE_BITS_LITERALS_HXX + +#include diff --git a/libxsd/libxsd/cxx/tree/bits/literals.ixx b/libxsd/libxsd/cxx/tree/bits/literals.ixx new file mode 100644 index 0000000..8c2434b --- /dev/null +++ b/libxsd/libxsd/cxx/tree/bits/literals.ixx @@ -0,0 +1,874 @@ +// file : libxsd/cxx/tree/bits/literals.ixx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX +#define XSD_CXX_TREE_BITS_LITERALS_IXX + +// The char versions of the following literals are required even +// if we are using wchar_t as the character type. +// +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const char* + positive_inf () + { + return "INF"; + } + + template<> + inline const char* + negative_inf () + { + return "-INF"; + } + + template<> + inline const char* + nan () + { + return "NaN"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX + + +#if defined(XSD_CXX_TREE_USE_CHAR) || !defined(XSD_CXX_TREE_USE_WCHAR) + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR +#define XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const char* + true_ () + { + return "true"; + } + + template<> + inline const char* + one () + { + return "1"; + } + + // + // + template<> + inline const char* + not_present () + { + return ""; + } + + // + // + template <> + inline const char* + xml_schema () + { + return "http://www.w3.org/2001/XMLSchema"; + } + + // + // + template <> + inline const char* + any_type () + { + return "anyType"; + } + + template <> + inline const char* + any_simple_type () + { + return "anySimpleType"; + } + + template <> + inline const char* + string () + { + return "string"; + } + + template <> + inline const char* + normalized_string () + { + return "normalizedString"; + } + + template <> + inline const char* + token () + { + return "token"; + } + + template <> + inline const char* + name () + { + return "Name"; + } + + template <> + inline const char* + nmtoken () + { + return "NMTOKEN"; + } + + template <> + inline const char* + nmtokens () + { + return "NMTOKENS"; + } + + template <> + inline const char* + ncname () + { + return "NCName"; + } + + template <> + inline const char* + language () + { + return "language"; + } + + + template <> + inline const char* + id () + { + return "ID"; + } + + template <> + inline const char* + idref () + { + return "IDREF"; + } + + template <> + inline const char* + idrefs () + { + return "IDREFS"; + } + + template <> + inline const char* + any_uri () + { + return "anyURI"; + } + + template <> + inline const char* + qname () + { + return "QName"; + } + + template <> + inline const char* + base64_binary () + { + return "base64Binary"; + } + + template <> + inline const char* + hex_binary () + { + return "hexBinary"; + } + + template <> + inline const char* + date () + { + return "date"; + } + + template <> + inline const char* + date_time () + { + return "dateTime"; + } + + template <> + inline const char* + duration () + { + return "duration"; + } + + template <> + inline const char* + gday () + { + return "gDay"; + } + + template <> + inline const char* + gmonth () + { + return "gMonth"; + } + + template <> + inline const char* + gmonth_day () + { + return "gMonthDay"; + } + + template <> + inline const char* + gyear () + { + return "gYear"; + } + + template <> + inline const char* + gyear_month () + { + return "gYearMonth"; + } + + template <> + inline const char* + time () + { + return "time"; + } + + template <> + inline const char* + entity () + { + return "ENTITY"; + } + + template <> + inline const char* + entities () + { + return "ENTITIES"; + } + + template <> + inline const char* + gday_prefix () + { + return "---"; + } + + template <> + inline const char* + gmonth_prefix () + { + return "--"; + } + + // + // + template <> + inline const char* + ex_error_error () + { + return " error: "; + } + + template <> + inline const char* + ex_error_warning () + { + return " warning: "; + } + + template <> + inline const char* + ex_parsing_msg () + { + return "instance document parsing failed"; + } + + template <> + inline const char* + ex_eel_expected () + { + return "expected element '"; + } + + template <> + inline const char* + ex_uel_expected () + { + return "expected element '"; + } + + template <> + inline const char* + ex_uel_instead () + { + return "' instead of '"; + } + + template <> + inline const char* + ex_uel_unexpected () + { + return "unexpected element '"; + } + + template <> + inline const char* + ex_eat_expected () + { + return "expected attribute '"; + } + + template <> + inline const char* + ex_uen_unexpected () + { + return "unexpected enumerator '"; + } + + template <> + inline const char* + ex_etc_msg () + { + return "expected text content"; + } + + template <> + inline const char* + ex_nti_no_type_info () + { + return "no type information available for type '"; + } + + template <> + inline const char* + ex_nei_no_element_info () + { + return "no parsing or serialization information available for " + "element '"; + } + template <> + inline const char* + ex_nd_type () + { + return "type '"; + } + + template <> + inline const char* + ex_nd_not_derived () + { + return "' is not derived from '"; + } + + template <> + inline const char* + ex_di_id () + { + return "ID '"; + } + + template <> + inline const char* + ex_di_already_exist () + { + return "' already exist"; + } + + template <> + inline const char* + ex_serialization_msg () + { + return "serialization failed"; + } + + template <> + inline const char* + ex_npm_no_mapping () + { + return "no mapping provided for namespace prefix '"; + } + + template <> + inline const char* + ex_bounds_msg () + { + return "buffer boundary rules have been violated"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX_CHAR +#endif // XSD_CXX_TREE_USE_CHAR + + +#if defined(XSD_CXX_TREE_USE_WCHAR) || !defined(XSD_CXX_TREE_USE_CHAR) + +#ifndef XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR +#define XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR + +namespace xsd +{ + namespace cxx + { + namespace tree + { + namespace bits + { + // + // + template<> + inline const wchar_t* + true_ () + { + return L"true"; + } + + template<> + inline const wchar_t* + one () + { + return L"1"; + } + + // + // + template<> + inline const wchar_t* + positive_inf () + { + return L"INF"; + } + + template<> + inline const wchar_t* + negative_inf () + { + return L"-INF"; + } + + template<> + inline const wchar_t* + nan () + { + return L"NaN"; + } + + // + // + template<> + inline const wchar_t* + not_present () + { + return L""; + } + + // + // + template <> + inline const wchar_t* + xml_schema () + { + return L"http://www.w3.org/2001/XMLSchema"; + } + + // + // + template <> + inline const wchar_t* + any_type () + { + return L"anyType"; + } + + template <> + inline const wchar_t* + any_simple_type () + { + return L"anySimpleType"; + } + + template <> + inline const wchar_t* + string () + { + return L"string"; + } + + template <> + inline const wchar_t* + normalized_string () + { + return L"normalizedString"; + } + + template <> + inline const wchar_t* + token () + { + return L"token"; + } + + template <> + inline const wchar_t* + name () + { + return L"Name"; + } + + template <> + inline const wchar_t* + nmtoken () + { + return L"NMTOKEN"; + } + + template <> + inline const wchar_t* + nmtokens () + { + return L"NMTOKENS"; + } + + template <> + inline const wchar_t* + ncname () + { + return L"NCName"; + } + + template <> + inline const wchar_t* + language () + { + return L"language"; + } + + + template <> + inline const wchar_t* + id () + { + return L"ID"; + } + + template <> + inline const wchar_t* + idref () + { + return L"IDREF"; + } + + template <> + inline const wchar_t* + idrefs () + { + return L"IDREFS"; + } + + template <> + inline const wchar_t* + any_uri () + { + return L"anyURI"; + } + + template <> + inline const wchar_t* + qname () + { + return L"QName"; + } + + template <> + inline const wchar_t* + base64_binary () + { + return L"base64Binary"; + } + + template <> + inline const wchar_t* + hex_binary () + { + return L"hexBinary"; + } + + template <> + inline const wchar_t* + date () + { + return L"date"; + } + + template <> + inline const wchar_t* + date_time () + { + return L"dateTime"; + } + + template <> + inline const wchar_t* + duration () + { + return L"duration"; + } + + template <> + inline const wchar_t* + gday () + { + return L"gDay"; + } + + template <> + inline const wchar_t* + gmonth () + { + return L"gMonth"; + } + + template <> + inline const wchar_t* + gmonth_day () + { + return L"gMonthDay"; + } + + template <> + inline const wchar_t* + gyear () + { + return L"gYear"; + } + + template <> + inline const wchar_t* + gyear_month () + { + return L"gYearMonth"; + } + + template <> + inline const wchar_t* + time () + { + return L"time"; + } + + template <> + inline const wchar_t* + entity () + { + return L"ENTITY"; + } + + template <> + inline const wchar_t* + entities () + { + return L"ENTITIES"; + } + + template <> + inline const wchar_t* + gday_prefix () + { + return L"---"; + } + + template <> + inline const wchar_t* + gmonth_prefix () + { + return L"--"; + } + + // + // + template <> + inline const wchar_t* + ex_error_error () + { + return L" error: "; + } + + template <> + inline const wchar_t* + ex_error_warning () + { + return L" warning: "; + } + + template <> + inline const wchar_t* + ex_parsing_msg () + { + return L"instance document parsing failed"; + } + + template <> + inline const wchar_t* + ex_eel_expected () + { + return L"expected element '"; + } + + template <> + inline const wchar_t* + ex_uel_expected () + { + return L"expected element '"; + } + + template <> + inline const wchar_t* + ex_uel_instead () + { + return L"' instead of '"; + } + + template <> + inline const wchar_t* + ex_uel_unexpected () + { + return L"unexpected element '"; + } + + template <> + inline const wchar_t* + ex_eat_expected () + { + return L"expected attribute '"; + } + + template <> + inline const wchar_t* + ex_uen_unexpected () + { + return L"unexpected enumerator '"; + } + + template <> + inline const wchar_t* + ex_etc_msg () + { + return L"expected text content"; + } + + template <> + inline const wchar_t* + ex_nti_no_type_info () + { + return L"no type information available for type '"; + } + + template <> + inline const wchar_t* + ex_nei_no_element_info () + { + return L"no parsing or serialization information available for " + L"element '"; + } + template <> + inline const wchar_t* + ex_nd_type () + { + return L"type '"; + } + + template <> + inline const wchar_t* + ex_nd_not_derived () + { + return L"' is not derived from '"; + } + + template <> + inline const wchar_t* + ex_di_id () + { + return L"ID '"; + } + + template <> + inline const wchar_t* + ex_di_already_exist () + { + return L"' already exist"; + } + + template <> + inline const wchar_t* + ex_serialization_msg () + { + return L"serialization failed"; + } + + template <> + inline const wchar_t* + ex_npm_no_mapping () + { + return L"no mapping provided for namespace prefix '"; + } + + template <> + inline const wchar_t* + ex_bounds_msg () + { + return L"buffer boundary rules have been violated"; + } + } + } + } +} + +#endif // XSD_CXX_TREE_BITS_LITERALS_IXX_WCHAR +#endif // XSD_CXX_TREE_USE_WCHAR diff --git a/libxsd/libxsd/cxx/tree/buffer.hxx b/libxsd/libxsd/cxx/tree/buffer.hxx new file mode 100644 index 0000000..36e83b8 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/buffer.hxx @@ -0,0 +1,335 @@ +// file : libxsd/cxx/tree/buffer.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +/** + * @file + * + * @brief Contains a simple binary buffer abstraction that is used to + * implement the base64Binary and hexBinary XML Schema built-in types. + * + * This is an internal header and is included by the generated code. You + * normally should not include it directly. + * + */ + +#ifndef LIBXSD_CXX_TREE_BUFFER_HXX +#define LIBXSD_CXX_TREE_BUFFER_HXX + +#include // operator new/delete +#include // std::size_t +#include // std::memcpy, std::memcmp + +#include + +namespace xsd +{ + namespace cxx + { + /** + * @brief C++/Tree mapping runtime namespace. + * + * This is an internal namespace and normally should not be referenced + * directly. Instead you should use the aliases for types in this + * namespaces that are created in the generated code. + * + */ + namespace tree + { + //@cond + + class buffer_base + { + protected: + virtual + ~buffer_base () + { + if (free_ && data_) + operator delete (data_); + } + + buffer_base () + : data_ (0), size_ (0), capacity_ (0), free_ (true) + { + } + + protected: + char* data_; + size_t size_; + size_t capacity_; + bool free_; + }; + + //@endcond + + /** + * @brief Simple binary %buffer abstraction + * + * The %buffer class manages a continuous binary %buffer. The base + * concepts are data (actual memory region), size (the portion of + * the %buffer that contains useful information), and capacity (the + * actual size of the underlying memory region). The bounds + * %exception is thrown from the constructors and modifier functions + * if the (size <= capacity) constraint is violated. + * + * Note that the template parameter is only used to instantiate + * %exception types. The underlying %buffer type is always @c char. + * + * @nosubgrouping + */ + template + class buffer: protected buffer_base + { + public: + /** + * @brief Size type + */ + typedef std::size_t size_t; + + public: + /** + * @name Constructors + */ + //@{ + + /** + * @brief Allocate a %buffer of the specified size. + * + * The resulting %buffer has the same size and capacity. + * + * @param size A %buffer size in bytes. + */ + explicit + buffer (size_t size = 0); + + /** + * @brief Allocate a %buffer of the specified size and capacity. + * + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (size_t size, size_t capacity); + + /** + * @brief Allocate a %buffer of the specified size and copy + * the data. + * + * The resulting %buffer has the same size and capacity with + * @a size bytes copied from @a data. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + */ + buffer (const void* data, size_t size); + + /** + * @brief Allocate a %buffer of the specified size and capacity + * and copy the data. + * + * @a size bytes are copied from @a data to the resulting + * %buffer. + * + * @param data A %buffer to copy the data from. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (const void* data, size_t size, size_t capacity); + + /** + * @brief Reuse an existing %buffer. + * + * If the @a assume_ownership argument is true, the %buffer will + * assume ownership of @a data and will release the memory + * by calling @c operator @c delete(). + * + * @param data A %buffer to reuse. + * @param size A %buffer size in bytes. + * @param capacity A %buffer capacity in bytes. + * @param assume_ownership A boolean value indication whether to + * assume ownership. + * @throw bounds If @a size exceeds @a capacity + */ + buffer (void* data, + size_t size, + size_t capacity, + bool assume_ownership); + + /** + * @brief Copy constructor. + * + * The copy constructor performs a deep copy of the underlying + * memory %buffer. + * + * @param x An instance to make a copy of. + */ + buffer (const buffer& x); + + //@} + + public: + /** + * @brief Copy assignment operator. + * + * The copy assignment operator changes the buffer's capacity + * to @c x.capacity() and copies @c x.size() bytes from @a x. + * + * @param x An instance to assign. + * @return A reference to the instance. + */ + buffer& + operator= (const buffer& x); + + public: + /** + * @brief Get buffer's capacity. + * + * @return A number of bytes that the %buffer can hold without + * reallocation. + */ + size_t + capacity () const + { + return capacity_; + } + + /** + * @brief Set buffer's capacity. + * + * @param c The new capacity in bytes. + * @return True if the underlying %buffer has moved, false otherwise. + */ + bool + capacity (size_t c) + { + return this->capacity (c, true); + } + + public: + /** + * @brief Get buffer's size. + * + * @return A number of bytes that the %buffer holds. + */ + size_t + size () const {return size_;} + + /** + * @brief Set buffer's size. + * + * @param s The new size in bytes. + * @return True if the underlying %buffer has moved, false otherwise. + */ + bool + size (size_t s) + { + bool r (false); + + if (s > capacity_) + r = capacity (s); + + size_ = s; + + return r; + } + + public: + /** + * @brief Get the underlying memory region. + * + * @return A constant pointer to the underlying memory region. + */ + const char* + data () const {return data_;} + + /** + * @brief Get the underlying memory region. + * + * @return A pointer to the underlying memory region. + */ + char* + data () {return data_;} + + /** + * @brief Get the beginning of the underlying memory region. + * + * @return A constant pointer to the first byte of the underlying + * memory region. + */ + const char* + begin () const {return data_;} + + /** + * @brief Get the beginning of the underlying memory region. + * + * @return A pointer to the first byte of the underlying memory + * region. + */ + char* + begin () {return data_;} + + /** + * @brief Get the end of the underlying memory region. + * + * @return A constant pointer to the one past last byte of the + * underlying memory region (that is @c %begin() @c + @c %size() ). + */ + const char* + end () const {return data_ + size_;} + + /** + * @brief Get the end of the underlying memory region. + * + * @return A pointer to the one past last byte of the underlying + * memory region (that is @c %begin() @c + @c %size() ). + */ + char* + end () {return data_ + size_;} + + public: + /** + * @brief Swap data with another %buffer. + * + * @param x A %buffer to swap with. + */ + void + swap (buffer& x); + + private: + bool + capacity (size_t capacity, bool copy); + }; + + /** + * @brief %buffer comparison operator. + * + * @return True if the buffers have the same sizes and the same + * data. + */ + template + inline bool + operator== (const buffer& a, const buffer& b) + { + return a.size () == b.size () && + std::memcmp (a.data (), b.data (), a.size ()) == 0; + } + + /** + * @brief %buffer comparison operator. + * + * @return True if the buffers have different sizes or different + * data. + */ + template + inline bool + operator!= (const buffer& a, const buffer& b) + { + return !(a == b); + } + } + } +} + +#include + +#endif // LIBXSD_CXX_TREE_BUFFER_HXX diff --git a/libxsd/libxsd/cxx/tree/buffer.txx b/libxsd/libxsd/cxx/tree/buffer.txx new file mode 100644 index 0000000..e8c2340 --- /dev/null +++ b/libxsd/libxsd/cxx/tree/buffer.txx @@ -0,0 +1,145 @@ +// file : libxsd/cxx/tree/buffer.txx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + buffer:: + buffer (size_t size) + { + capacity (size); + size_ = size; + } + + template + buffer:: + buffer (size_t size, size_t capacity) + { + if (size > capacity) + throw bounds (); + + this->capacity (capacity); + size_ = size; + } + + template + buffer:: + buffer (const void* data, size_t size) + { + capacity (size); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + template + buffer:: + buffer (const void* data, size_t size, size_t capacity) + { + if (size > capacity) + throw bounds (); + + this->capacity (capacity); + size_ = size; + + if (size_) + std::memcpy (data_, data, size_); + } + + template + buffer:: + buffer (void* data, size_t size, size_t capacity, bool own) + { + if (size > capacity) + throw bounds (); + + data_ = reinterpret_cast (data); + size_ = size; + capacity_ = capacity; + free_ = own; + } + + template + buffer:: + buffer (const buffer& other) + : buffer_base () + { + capacity (other.capacity_); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + template + buffer& buffer:: + operator= (const buffer& other) + { + if (this != &other) + { + capacity (other.capacity_, false); + size_ = other.size_; + + if (size_) + std::memcpy (data_, other.data_, size_); + } + + return *this; + } + + template + void buffer:: + swap (buffer& other) + { + char* tmp_data (data_); + size_t tmp_size (size_); + size_t tmp_capacity (capacity_); + bool tmp_free (free_); + + data_ = other.data_; + size_ = other.size_; + capacity_ = other.capacity_; + free_ = other.free_; + + other.data_ = tmp_data; + other.size_ = tmp_size; + other.capacity_ = tmp_capacity; + other.free_ = tmp_free; + } + + template + bool buffer:: + capacity (size_t capacity, bool copy) + { + if (size_ > capacity) + throw bounds (); + + if (capacity <= capacity_) + { + return false; // Do nothing if shrinking is requested. + } + else + { + char* data (reinterpret_cast (operator new (capacity))); + + if (copy && size_ > 0) + std::memcpy (data, data_, size_); + + if (free_ && data_) + operator delete (data_); + + data_ = data; + capacity_ = capacity; + free_ = true; + + return true; + } + } + } + } +} diff --git a/libxsd/libxsd/cxx/tree/comparison-map.hxx b/libxsd/libxsd/cxx/tree/comparison-map.hxx new file mode 100644 index 0000000..e133c6c --- /dev/null +++ b/libxsd/libxsd/cxx/tree/comparison-map.hxx @@ -0,0 +1,111 @@ +// file : libxsd/cxx/tree/comparison-map.hxx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef LIBXSD_CXX_TREE_COMPARISON_MAP_HXX +#define LIBXSD_CXX_TREE_COMPARISON_MAP_HXX + +#include +#include // std::size_t +#include + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + template + struct comparison_map + { + typedef std::type_info type_id; + typedef bool (*comparator) (const type&, const type&); + + comparison_map (); + + void + register_type (const type_id&, comparator, bool replace = true); + + void + unregister_type (const type_id&); + + bool + compare (const type&, const type&); + + public: + comparator + find (const type_id&) const; + + private: + struct type_id_comparator + { + bool + operator() (const type_id* x, const type_id* y) const + { + // XL C++ on AIX has buggy type_info::before() in that + // it returns true for two different type_info objects + // that happened to be for the same type. + // +#if defined(__xlC__) && defined(_AIX) + return *x != *y && x->before (*y); +#else + return x->before (*y); +#endif + } + }; + + typedef + std::map + type_map; + + type_map type_map_; + }; + + // + // + template + struct comparison_plate + { + static comparison_map* map; + static std::size_t count; + + comparison_plate (); + ~comparison_plate (); + }; + + template + comparison_map* comparison_plate::map = 0; + + template + std::size_t comparison_plate::count = 0; + + + // + // + template + inline comparison_map& + comparison_map_instance () + { + return *comparison_plate::map; + } + + // + // + template + bool + comparator_impl (const type&, const type&); + + template + struct comparison_initializer + { + comparison_initializer (); + ~comparison_initializer (); + }; + } + } +} + +#include + +#endif // LIBXSD_CXX_TREE_COMPARISON_MAP_HXX diff --git a/libxsd/libxsd/cxx/tree/comparison-map.txx b/libxsd/libxsd/cxx/tree/comparison-map.txx new file mode 100644 index 0000000..e18d12e --- /dev/null +++ b/libxsd/libxsd/cxx/tree/comparison-map.txx @@ -0,0 +1,298 @@ +// file : libxsd/cxx/tree/comparison-map.txx +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +namespace xsd +{ + namespace cxx + { + namespace tree + { + // comparison_map + // + template + comparison_map:: + comparison_map () + { + // anyType and anySimpleType. + // + + register_type ( + typeid (type), + &comparator_impl, + false); + + typedef simple_type simple_type; + + register_type ( + typeid (simple_type), + &comparator_impl, + false); + + // Strings + // + typedef string string; + register_type ( + typeid (string), + &comparator_impl, + false); + + typedef normalized_string normalized_string; + register_type ( + typeid (normalized_string), + &comparator_impl, + false); + + typedef token token; + register_type ( + typeid (token), + &comparator_impl, + false); + + typedef name name; + register_type ( + typeid (name), + &comparator_impl, + false); + + typedef nmtoken nmtoken; + register_type ( + typeid (nmtoken), + &comparator_impl, + false); + + typedef nmtokens nmtokens; + register_type ( + typeid (nmtokens), + &comparator_impl, + false); + + typedef ncname ncname; + register_type ( + typeid (ncname), + &comparator_impl, + false); + + typedef language language; + register_type ( + typeid (language), + &comparator_impl, + false); + + + // ID/IDREF. + // + typedef id id; + register_type ( + typeid (id), + &comparator_impl, + false); + + typedef idref idref; + register_type ( + typeid (idref), + &comparator_impl, + false); + + typedef idrefs idrefs; + register_type ( + typeid (idrefs), + &comparator_impl, + false); + + + // URI. + // + typedef uri uri; + register_type ( + typeid (uri), + &comparator_impl, + false); + + + // Qualified name. + // + typedef qname qname; + register_type ( + typeid (qname), + &comparator_impl, + false); + + + // Binary. + // + typedef base64_binary base64_binary; + register_type ( + typeid (base64_binary), + &comparator_impl, + false); + + typedef hex_binary hex_binary; + register_type ( + typeid (hex_binary), + &comparator_impl, + false); + + + // Date/time. + // + typedef gday gday; + register_type ( + typeid (gday), + &comparator_impl, + false); + + typedef gmonth gmonth; + register_type ( + typeid (gmonth), + &comparator_impl, + false); + + typedef gyear gyear; + register_type ( + typeid (gyear), + &comparator_impl, + false); + + typedef gmonth_day gmonth_day; + register_type ( + typeid (gmonth_day), + &comparator_impl, + false); + + typedef gyear_month gyear_month; + register_type ( + typeid (gyear_month), + &comparator_impl, + false); + + typedef date date; + register_type ( + typeid (date), + &comparator_impl, + false); + + typedef time time; + register_type ( + typeid (time), + &comparator_impl