From 0bce70a0e483294b83b8bf9d5468838a63405612 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 8 Mar 2009 17:23:30 +0200 Subject: Add support for binary representations xsde/cxx/hybrid/insertion-*: insertion operators generator xsde/cxx/hybrid/extraction-*: extraction operators generator libxsde/xsde/cxx/hybrid/cdr/: CDR support code libxsde/xsde/cxx/hybrid/xdr/: XDR support code tests/cxx/hybrid/binary/: new tests examples/cxx/hybrid/binary/: new examples documentation/cxx/hybrid/guide/: new chapter --- libxsde/xsde/cxx/hybrid/xdr/ostream.ixx | 281 ++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 libxsde/xsde/cxx/hybrid/xdr/ostream.ixx (limited to 'libxsde/xsde/cxx/hybrid/xdr/ostream.ixx') diff --git a/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx b/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx new file mode 100644 index 0000000..64c8a26 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx @@ -0,0 +1,281 @@ +// file : xsde/cxx/hybrid/xdr/ostream.ixx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + inline oxdrstream:: + oxdrstream (XDR& xdr) + : xdr_ (xdr) + { + } + + inline XDR& oxdrstream:: + impl () + { + return xdr_; + } + +#ifdef XSDE_EXCEPTIONS + + inline void oxdrstream:: + operator<< (bool x) + { + bool_t v = static_cast (x); + + if (!xdr_bool (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (signed char x) + { + int8_t v = static_cast (x); + + if (!xdr_int8_t (&xdr_, &v)) + throw xdr_exception (); + } + + + inline void oxdrstream:: + operator<< (unsigned char x) + { + uint8_t v = static_cast (x); + + if (!xdr_uint8_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (short x) + { + int16_t v = static_cast (x); + + if (!xdr_int16_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned short x) + { + uint16_t v = static_cast (x); + + if (!xdr_uint16_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (int x) + { + int32_t v = static_cast (x); + + if (!xdr_int32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned int x) + { + uint32_t v = static_cast (x); + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (long x) + { + int32_t v = static_cast (x); + + if (!xdr_int32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned long x) + { + uint32_t v = static_cast (x); + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + } + +#ifdef XSDE_LONGLONG + inline void oxdrstream:: + operator<< (long long x) + { + int64_t v = static_cast (x); + + if (!xdr_int64_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned long long x) + { + uint64_t v = static_cast (x); + + if (!xdr_uint64_t (&xdr_, &v)) + throw xdr_exception (); + } +#endif + + inline void oxdrstream:: + operator<< (as_size x) + { + // Assume size is 32-bit. + // + uint32_t v = static_cast (x.s_); + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (float x) + { + if (!xdr_float (&xdr_, &x)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (double x) + { + if (!xdr_double (&xdr_, &x)) + throw xdr_exception (); + } + + inline void + operator<< (oxdrstream&, const any_type&) + { + } + + inline void + operator<< (oxdrstream&, const any_simple_type&) + { + } + +#else // XSDE_EXCEPTIONS + + inline bool oxdrstream:: + operator<< (bool x) + { + bool_t v = static_cast (x); + return xdr_bool (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (signed char x) + { + int8_t v = static_cast (x); + return xdr_int8_t (&xdr_, &v); + } + + + inline bool oxdrstream:: + operator<< (unsigned char x) + { + uint8_t v = static_cast (x); + return xdr_uint8_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (short x) + { + int16_t v = static_cast (x); + return xdr_int16_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned short x) + { + uint16_t v = static_cast (x); + return xdr_uint16_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (int x) + { + int32_t v = static_cast (x); + return xdr_int32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned int x) + { + uint32_t v = static_cast (x); + return xdr_uint32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (long x) + { + int32_t v = static_cast (x); + return xdr_int32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned long x) + { + uint32_t v = static_cast (x); + return xdr_uint32_t (&xdr_, &v); + } + +#ifdef XSDE_LONGLONG + inline bool oxdrstream:: + operator<< (long long x) + { + int64_t v = static_cast (x); + return xdr_int64_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned long long x) + { + uint64_t v = static_cast (x); + return xdr_uint64_t (&xdr_, &v); + } +#endif + + inline bool oxdrstream:: + operator<< (as_size x) + { + // Assume size is 32-bit. + // + uint32_t v = static_cast (x.s_); + return xdr_uint32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (float x) + { + return xdr_float (&xdr_, &x); + } + + inline bool oxdrstream:: + operator<< (double x) + { + return xdr_double (&xdr_, &x); + } + + inline bool + operator<< (oxdrstream&, const any_type&) + { + return true; + } + + inline bool + operator<< (oxdrstream&, const any_simple_type&) + { + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} -- cgit v1.1