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/ace-cdr-stream-extraction.hxx | 334 ++++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx (limited to 'libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx') diff --git a/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx b/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx new file mode 100644 index 0000000..8151507 --- /dev/null +++ b/libxsd/xsd/cxx/tree/ace-cdr-stream-extraction.hxx @@ -0,0 +1,334 @@ +// file : xsd/cxx/tree/ace-cdr-stream-extraction.hxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX +#define XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX + +#include // std::size_t +#include + +#include // ACE::strdelete +#include + +#include + +#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_deallocator + { + void + deallocate (C* s) + { + ACE::strdelete (s); + } + }; + } + + inline istream& + operator>> (istream& s, std::basic_string& x) + { + typedef bits::ace_str_deallocator deallocator; + + deallocator d; + char* r; + + if (!s.impl ().read_string (r)) + throw ace_cdr_stream_extraction (); + + auto_array ar (r, d); + + x = r; + + return s; + } + +#ifdef ACE_HAS_WCHAR + inline istream& + operator>> (istream& s, std::basic_string& x) + { + typedef bits::ace_str_deallocator deallocator; + + deallocator d; + wchar_t* r; + + if (!s.impl ().read_wstring (r)) + throw ace_cdr_stream_extraction (); + + auto_array ar (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 // XSD_CXX_TREE_ACE_CDR_STREAM_EXTRACTION_HXX -- cgit v1.1