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/istream.cxx | 135 ++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 libxsde/xsde/cxx/hybrid/xdr/istream.cxx (limited to 'libxsde/xsde/cxx/hybrid/xdr/istream.cxx') diff --git a/libxsde/xsde/cxx/hybrid/xdr/istream.cxx b/libxsde/xsde/cxx/hybrid/xdr/istream.cxx new file mode 100644 index 0000000..af35769 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/istream.cxx @@ -0,0 +1,135 @@ +// file : xsde/cxx/hybrid/xdr/istream.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + +#ifdef XSDE_STL + void ixdrstream:: + operator>> (std::string& x) + { + unsigned int n; + + if (!xdr_u_int (&xdr_, &n)) + throw xdr_exception (); + + x.clear (); + + if (n != 0) + { + x.resize (n); + char* p = const_cast (x.c_str ()); + + if (!xdr_opaque (&xdr_, p, n)) + throw xdr_exception (); + } + } +#else + void ixdrstream:: + operator>> (char*& x) + { + unsigned int n; + + if (!xdr_u_int (&xdr_, &n)) + throw xdr_exception (); + + x = new char[n + 1]; + + if (!xdr_opaque (&xdr_, x, n)) + { + delete[] x; + throw xdr_exception (); + } + + x[n] = '\0'; + } +#endif + + void ixdrstream:: + operator>> (buffer& x) + { + unsigned int n; + + if (!xdr_u_int (&xdr_, &n)) + throw xdr_exception (); + + x.size (n); + + if (!xdr_opaque (&xdr_, x.data (), n)) + throw xdr_exception (); + } + +#else // XSDE_EXCEPTIONS + +#ifdef XSDE_STL + bool ixdrstream:: + operator>> (std::string& x) + { + unsigned int n; + + if (!xdr_u_int (&xdr_, &n)) + return false; + + x.clear (); + + if (n != 0) + { + x.resize (n); + char* p = const_cast (x.c_str ()); + return xdr_opaque (&xdr_, p, n); + } + + return true; + } +#else + bool ixdrstream:: + operator>> (char*& x) + { + unsigned int n; + + if (!xdr_u_int (&xdr_, &n)) + return false; + + x = new char[n + 1]; + + if (x == 0) + return false; + + if (!xdr_opaque (&xdr_, x, n)) + { + delete[] x; + return false; + } + + x[n] = '\0'; + + return true; + } +#endif + + bool ixdrstream:: + operator>> (buffer& x) + { + unsigned int n; + + if (!xdr_u_int (&xdr_, &n)) + return false; + + x.size (n); + return xdr_opaque (&xdr_, x.data (), n); + } + +#endif // XSDE_EXCEPTIONS + + } + } +} -- cgit v1.1