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/cdr/istream.cxx | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 libxsde/xsde/cxx/hybrid/cdr/istream.cxx (limited to 'libxsde/xsde/cxx/hybrid/cdr/istream.cxx') diff --git a/libxsde/xsde/cxx/hybrid/cdr/istream.cxx b/libxsde/xsde/cxx/hybrid/cdr/istream.cxx new file mode 100644 index 0000000..111e668 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/istream.cxx @@ -0,0 +1,101 @@ +// file : xsde/cxx/hybrid/cdr/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 + struct str_guard + { + str_guard (char* s) : s_ (s) {} + ~str_guard () {delete[] s_;} + + private: + char* s_; + }; + + void icdrstream:: + operator>> (std::string& x) + { + char* v; + + if (!cdr_.read_string (v)) + throw cdr_exception (); + + str_guard g (v); + x = v; + } +#else + void icdrstream:: + operator>> (char*& x) + { + if (!cdr_.read_string (x)) + throw cdr_exception (); + } +#endif + + void icdrstream:: + operator>> (buffer& x) + { + ACE_CDR::ULong n; + + if (!cdr_.read_ulong (n)) + throw cdr_exception (); + + x.size (n); + + if (!cdr_.read_octet_array ( + reinterpret_cast (x.data ()), n)) + throw cdr_exception (); + } + +#else // XSDE_EXCEPTIONS + +#ifdef XSDE_STL + bool icdrstream:: + operator>> (std::string& x) + { + char* v; + + if (!cdr_.read_string (v)) + return false; + + x = v; + delete[] v; + return true; + } +#else + bool icdrstream:: + operator>> (char*& x) + { + return cdr_.read_string (x); + } +#endif + + bool icdrstream:: + operator>> (buffer& x) + { + ACE_CDR::ULong n; + + if (!cdr_.read_ulong (n)) + return false; + + x.size (n); + return cdr_.read_octet_array ( + reinterpret_cast (x.data ()), n); + } + +#endif // XSDE_EXCEPTIONS + + } + } +} -- cgit v1.1