diff options
Diffstat (limited to 'libxsde/xsde/cxx/hybrid/xdr')
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/date-time.cxx | 764 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/exceptions.cxx | 21 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/exceptions.hxx | 26 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/istream.cxx | 135 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/istream.hxx | 181 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/istream.ixx | 365 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/istream.txx | 184 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/ostream.cxx | 92 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/ostream.hxx | 181 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/ostream.ixx | 281 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/ostream.txx | 110 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/qname.cxx | 74 | ||||
-rw-r--r-- | libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx | 107 |
13 files changed, 2521 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/hybrid/xdr/date-time.cxx b/libxsde/xsde/cxx/hybrid/xdr/date-time.cxx new file mode 100644 index 0000000..e920850 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/date-time.cxx @@ -0,0 +1,764 @@ +// file : xsde/cxx/hybrid/xdr/date-time.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/hybrid/xdr/istream.hxx> +#include <xsde/cxx/hybrid/xdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + // operator<< + // + + void + operator<< (oxdrstream& s, const time_zone& x) + { + s << x.zone_hours (); + s << x.zone_minutes (); + } + + void + operator<< (oxdrstream& s, const date& x) + { + s << x.year (); + s << x.month (); + s << x.day (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const date_time& x) + { + s << x.year (); + s << x.month (); + s << x.day (); + s << x.hours (); + s << x.minutes (); + s << x.seconds (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const duration& x) + { + s << x.negative (); + s << x.years (); + s << x.months (); + s << x.days (); + s << x.hours (); + s << x.minutes (); + s << x.seconds (); + } + + void + operator<< (oxdrstream& s, const gday& x) + { + s << x.day (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const gmonth& x) + { + s << x.month (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const gmonth_day& x) + { + s << x.month (); + s << x.day (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const gyear& x) + { + s << x.year (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const gyear_month& x) + { + s << x.year (); + s << x.month (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + void + operator<< (oxdrstream& s, const time& x) + { + s << x.hours (); + s << x.minutes (); + s << x.seconds (); + bool zp = x.zone_present (); + s << zp; + + if (zp) + { + const time_zone& z = x; + s << z; + } + } + + + // operator>> + // + + void + operator>> (ixdrstream& s, time_zone& x) + { + short h, m; + s >> h; + s >> m; + + x.zone_hours (h); + x.zone_minutes (m); + } + + void + operator>> (ixdrstream& s, date& x) + { + int y; + unsigned short m, d; + bool zp; + + s >> y; + s >> m; + s >> d; + s >> zp; + + x.year (y); + x.month (m); + x.day (d); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, date_time& x) + { + int y; + unsigned short m, d, h, mi; + double se; + bool zp; + + s >> y; + s >> m; + s >> d; + s >> h; + s >> mi; + s >> se; + s >> zp; + + x.year (y); + x.month (m); + x.day (d); + x.hours (h); + x.minutes (mi); + x.seconds (se); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, duration& x) + { + bool n; + unsigned int y, m, d, h, mi; + double se; + + s >> n; + s >> y; + s >> m; + s >> d; + s >> h; + s >> mi; + s >> se; + + x.negative (n); + x.years (y); + x.months (m); + x.days (d); + x.hours (h); + x.minutes (mi); + x.seconds (se); + } + + void + operator>> (ixdrstream& s, gday& x) + { + unsigned short d; + bool zp; + + s >> d; + s >> zp; + + x.day (d); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, gmonth& x) + { + unsigned short m; + bool zp; + + s >> m; + s >> zp; + + x.month (m); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, gmonth_day& x) + { + unsigned short d, m; + bool zp; + + s >> d; + s >> m; + s >> zp; + + x.day (d); + x.month (m); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, gyear& x) + { + int y; + bool zp; + + s >> y; + s >> zp; + + x.year (y); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, gyear_month& x) + { + int y; + unsigned short m; + bool zp; + + s >> y; + s >> m; + s >> zp; + + x.year (y); + x.month (m); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (ixdrstream& s, time& x) + { + unsigned short h, m; + double se; + bool zp; + + s >> h; + s >> m; + s >> se; + s >> zp; + + x.hours (h); + x.minutes (m); + x.seconds (se); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + +#else // XSDE_EXCEPTIONS + + // operator<< + // + + bool + operator<< (oxdrstream& s, const time_zone& x) + { + return s << x.zone_hours () && s << x.zone_minutes (); + } + + bool + operator<< (oxdrstream& s, const date& x) + { + bool zp = x.zone_present (); + + if (!(s << x.year ()) || + !(s << x.month ()) || + !(s << x.day ()) || + !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const date_time& x) + { + bool zp = x.zone_present (); + + if (!(s << x.year ()) || + !(s << x.month ()) || + !(s << x.day ()) || + !(s << x.hours ()) || + !(s << x.minutes ()) || + !(s << x.seconds ()) || + !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const duration& x) + { + return s << x.negative () && + s << x.years () && + s << x.months () && + s << x.days () && + s << x.hours () && + s << x.minutes () && + s << x.seconds (); + } + + bool + operator<< (oxdrstream& s, const gday& x) + { + bool zp = x.zone_present (); + + + if (!(s << x.day ()) || !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const gmonth& x) + { + bool zp = x.zone_present (); + + if (!(s << x.month ()) || !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const gmonth_day& x) + { + bool zp = x.zone_present (); + + if (!(s << x.month ()) || !(s << x.day ()) || !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const gyear& x) + { + bool zp = x.zone_present (); + + if (!(s << x.year ()) || !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const gyear_month& x) + { + bool zp = x.zone_present (); + + if (!(s << x.year ()) || !(s << x.month ()) || !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + bool + operator<< (oxdrstream& s, const time& x) + { + bool zp = x.zone_present (); + + if (!(s << x.hours ()) || + !(s << x.minutes ()) || + !(s << x.seconds ()) || + !(s << zp)) + return false; + + if (zp) + { + const time_zone& z = x; + return s << z; + } + + return true; + } + + + // operator>> + // + + bool + operator>> (ixdrstream& s, time_zone& x) + { + short h, m; + + if (!(s >> h) || !(s >> m)) + return false; + + x.zone_hours (h); + x.zone_minutes (m); + + return true; + } + + bool + operator>> (ixdrstream& s, date& x) + { + int y; + unsigned short m, d; + bool zp; + + if (!(s >> y) || !(s >> m) || !(s >> d) || !(s >> zp)) + return false; + + x.year (y); + x.month (m); + x.day (d); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, date_time& x) + { + int y; + unsigned short m, d, h, mi; + double se; + bool zp; + + if (!(s >> y) || !(s >> m) || !(s >> d) || + !(s >> h) || !(s >> mi) || !(s >> se) || !(s >> zp)) + return false; + + x.year (y); + x.month (m); + x.day (d); + x.hours (h); + x.minutes (mi); + x.seconds (se); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, duration& x) + { + bool n; + unsigned int y, m, d, h, mi; + double se; + + if (!(s >> n) || !(s >> y) || !(s >> m) || !(s >> d) || + !(s >> h) || !(s >> mi) || !(s >> se)) + return false; + + x.negative (n); + x.years (y); + x.months (m); + x.days (d); + x.hours (h); + x.minutes (mi); + x.seconds (se); + + return true; + } + + bool + operator>> (ixdrstream& s, gday& x) + { + unsigned short d; + bool zp; + + if (!(s >> d) || !(s >> zp)) + return false; + + x.day (d); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, gmonth& x) + { + unsigned short m; + bool zp; + + if (!(s >> m) || !(s >> zp)) + return false; + + x.month (m); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, gmonth_day& x) + { + unsigned short d, m; + bool zp; + + if (!(s >> d) || !(s >> m) || !(s >> zp)) + return false; + + x.day (d); + x.month (m); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, gyear& x) + { + int y; + bool zp; + + if (!(s >> y) || !(s >> zp)) + return false; + + x.year (y); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, gyear_month& x) + { + int y; + unsigned short m; + bool zp; + + if (!(s >> y) || !(s >> m) || !(s >> zp)) + return false; + + x.year (y); + x.month (m); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + + bool + operator>> (ixdrstream& s, time& x) + { + unsigned short h, m; + double se; + bool zp; + + if (!(s >> h) || !(s >> m) || !(s >> se) || !(s >> zp)) + return false; + + x.hours (h); + x.minutes (m); + x.seconds (se); + + if (zp) + { + time_zone& z = x; + return s >> z; + } + + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/exceptions.cxx b/libxsde/xsde/cxx/hybrid/xdr/exceptions.cxx new file mode 100644 index 0000000..4a66f6c --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/exceptions.cxx @@ -0,0 +1,21 @@ +// file : xsde/cxx/hybrid/xdr/exceptions.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/hybrid/xdr/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + const char* xdr_exception:: + what () const throw () + { + return "XDR stream operation failed"; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/exceptions.hxx b/libxsde/xsde/cxx/hybrid/xdr/exceptions.hxx new file mode 100644 index 0000000..61d0a3c --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/exceptions.hxx @@ -0,0 +1,26 @@ +// file : xsde/cxx/hybrid/xdr/exceptions.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_XDR_EXCEPTIONS_HXX +#define XSDE_CXX_HYBRID_XDR_EXCEPTIONS_HXX + +#include <xsde/cxx/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + struct xdr_exception: xsde::cxx::exception + { + virtual const char* + what () const throw (); + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_XDR_EXCEPTIONS_HXX 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 <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/hybrid/xdr/istream.hxx> + +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<char*> (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<char*> (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 + + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/istream.hxx b/libxsde/xsde/cxx/hybrid/xdr/istream.hxx new file mode 100644 index 0000000..559b136 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/istream.hxx @@ -0,0 +1,181 @@ +// file : xsde/cxx/hybrid/xdr/istream.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_XDR_ISTREAM_HXX +#define XSDE_CXX_HYBRID_XDR_ISTREAM_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t +#include <rpc/xdr.h> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/buffer.hxx> +#include <xsde/cxx/date-time.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/qname-stl.hxx> +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/qname.hxx> +# include <xsde/cxx/string-sequence.hxx> +#endif + +#include <xsde/cxx/hybrid/any-type.hxx> +#include <xsde/cxx/hybrid/sequence.hxx> + +#ifdef XSDE_EXCEPTIONS +# include <xsde/cxx/hybrid/xdr/exceptions.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + class ixdrstream + { + public: + explicit + ixdrstream (XDR& xdr); + + XDR& + impl (); + + public: + struct as_size + { + explicit as_size (size_t& s) : s_ (s) {} + size_t& s_; + }; + + public: +#ifdef XSDE_EXCEPTIONS + + void operator>> (bool&); + void operator>> (signed char&); + void operator>> (unsigned char&); + void operator>> (short&); + void operator>> (unsigned short&); + void operator>> (int&); + void operator>> (unsigned int&); + void operator>> (long&); + void operator>> (unsigned long&); + +#ifdef XSDE_LONGLONG + void operator>> (long long&); + void operator>> (unsigned long long&); +#endif + void operator>> (as_size&); + void operator>> (float&); + void operator>> (double&); + +#ifdef XSDE_STL + void operator>> (std::string&); +#else + void operator>> (char*&); +#endif + void operator>> (buffer&); + +#else // XSDE_EXCEPTIONS + + bool operator>> (bool&); + bool operator>> (signed char&); + bool operator>> (unsigned char&); + bool operator>> (short&); + bool operator>> (unsigned short&); + bool operator>> (int&); + bool operator>> (unsigned int&); + bool operator>> (long&); + bool operator>> (unsigned long&); + +#ifdef XSDE_LONGLONG + bool operator>> (long long&); + bool operator>> (unsigned long long&); +#endif + bool operator>> (as_size&); + bool operator>> (float&); + bool operator>> (double&); + +#ifdef XSDE_STL + bool operator>> (std::string&); +#else + bool operator>> (char*&); +#endif + bool operator>> (buffer&); + +#endif // XSDE_EXCEPTIONS + + private: + ixdrstream (const ixdrstream&); + ixdrstream& operator= (const ixdrstream&); + + private: + XDR& xdr_; + }; + +#ifdef XSDE_EXCEPTIONS + void operator>> (ixdrstream&, any_type&); + void operator>> (ixdrstream&, any_simple_type&); + void operator>> (ixdrstream&, qname&); + void operator>> (ixdrstream&, string_sequence&); + void operator>> (ixdrstream&, time_zone&); + void operator>> (ixdrstream&, date&); + void operator>> (ixdrstream&, date_time&); + void operator>> (ixdrstream&, duration&); + void operator>> (ixdrstream&, gday&); + void operator>> (ixdrstream&, gmonth&); + void operator>> (ixdrstream&, gmonth_day&); + void operator>> (ixdrstream&, gyear&); + void operator>> (ixdrstream&, gyear_month&); + void operator>> (ixdrstream&, time&); +#else + bool operator>> (ixdrstream&, any_type&); + bool operator>> (ixdrstream&, any_simple_type&); + bool operator>> (ixdrstream&, qname&); + bool operator>> (ixdrstream&, string_sequence&); + bool operator>> (ixdrstream&, time_zone&); + bool operator>> (ixdrstream&, date&); + bool operator>> (ixdrstream&, date_time&); + bool operator>> (ixdrstream&, duration&); + bool operator>> (ixdrstream&, gday&); + bool operator>> (ixdrstream&, gmonth&); + bool operator>> (ixdrstream&, gmonth_day&); + bool operator>> (ixdrstream&, gyear&); + bool operator>> (ixdrstream&, gyear_month&); + bool operator>> (ixdrstream&, time&); +#endif + +#ifdef XSDE_EXCEPTIONS + template <typename T> + void operator>> (ixdrstream&, pod_seq<T>&); + + template <typename T> + void operator>> (ixdrstream&, fix_seq<T>&); + + template <typename T> + void operator>> (ixdrstream&, var_seq<T>&); +#else + template <typename T> + bool operator>> (ixdrstream&, pod_seq<T>&); + + template <typename T> + bool operator>> (ixdrstream&, fix_seq<T>&); + + template <typename T> + bool operator>> (ixdrstream&, var_seq<T>&); +#endif + } + } +} + +#include <xsde/cxx/hybrid/xdr/istream.ixx> +#include <xsde/cxx/hybrid/xdr/istream.txx> + +#endif // XSDE_CXX_HYBRID_XDR_ISTREAM_HXX diff --git a/libxsde/xsde/cxx/hybrid/xdr/istream.ixx b/libxsde/xsde/cxx/hybrid/xdr/istream.ixx new file mode 100644 index 0000000..86dd0ec --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/istream.ixx @@ -0,0 +1,365 @@ +// file : xsde/cxx/hybrid/xdr/istream.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// 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 ixdrstream:: + ixdrstream (XDR& xdr) + : xdr_ (xdr) + { + } + + inline XDR& ixdrstream:: + impl () + { + return xdr_; + } + +#ifdef XSDE_EXCEPTIONS + + inline void ixdrstream:: + operator>> (bool& x) + { + bool_t v; + + if (!xdr_bool (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<bool> (v); + } + + inline void ixdrstream:: + operator>> (signed char& x) + { + int8_t v; + + if (!xdr_int8_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<signed char> (v); + } + + + inline void ixdrstream:: + operator>> (unsigned char& x) + { + uint8_t v; + + if (!xdr_uint8_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<unsigned char> (v); + } + + inline void ixdrstream:: + operator>> (short& x) + { + int16_t v; + + if (!xdr_int16_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<short> (v); + } + + inline void ixdrstream:: + operator>> (unsigned short& x) + { + uint16_t v; + + if (!xdr_uint16_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<unsigned short> (v); + } + + inline void ixdrstream:: + operator>> (int& x) + { + int32_t v; + + if (!xdr_int32_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<int> (v); + } + + inline void ixdrstream:: + operator>> (unsigned int& x) + { + uint32_t v; + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<unsigned int> (v); + } + + inline void ixdrstream:: + operator>> (long& x) + { + int32_t v; + + if (!xdr_int32_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<long> (v); + } + + inline void ixdrstream:: + operator>> (unsigned long& x) + { + uint32_t v; + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<unsigned long> (v); + } + +#ifdef XSDE_LONGLONG + inline void ixdrstream:: + operator>> (long long& x) + { + int64_t v; + + if (!xdr_int64_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<long long> (v); + } + + inline void ixdrstream:: + operator>> (unsigned long long& x) + { + uint64_t v; + + if (!xdr_uint64_t (&xdr_, &v)) + throw xdr_exception (); + + x = static_cast<unsigned long long> (v); + } +#endif + + inline void ixdrstream:: + operator>> (as_size& x) + { + // Assume size is 32-bit. + // + uint32_t v; + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + + x.s_ = static_cast<size_t> (v); + } + + inline void ixdrstream:: + operator>> (float& x) + { + if (!xdr_float (&xdr_, &x)) + throw xdr_exception (); + } + + inline void ixdrstream:: + operator>> (double& x) + { + if (!xdr_double (&xdr_, &x)) + throw xdr_exception (); + } + + inline void + operator>> (ixdrstream&, any_type&) + { + } + + inline void + operator>> (ixdrstream&, any_simple_type&) + { + } + +#else // XSDE_EXCEPTIONS + + inline bool ixdrstream:: + operator>> (bool& x) + { + bool_t v; + + if (!xdr_bool (&xdr_, &v)) + return false; + + x = static_cast<bool> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (signed char& x) + { + int8_t v; + + if (!xdr_int8_t (&xdr_, &v)) + return false; + + x = static_cast<signed char> (v); + return true; + } + + + inline bool ixdrstream:: + operator>> (unsigned char& x) + { + uint8_t v; + + if (!xdr_uint8_t (&xdr_, &v)) + return false; + + x = static_cast<unsigned char> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (short& x) + { + int16_t v; + + if (!xdr_int16_t (&xdr_, &v)) + return false; + + x = static_cast<short> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (unsigned short& x) + { + uint16_t v; + + if (!xdr_uint16_t (&xdr_, &v)) + return false; + + x = static_cast<unsigned short> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (int& x) + { + int32_t v; + + if (!xdr_int32_t (&xdr_, &v)) + return false; + + x = static_cast<int> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (unsigned int& x) + { + uint32_t v; + + if (!xdr_uint32_t (&xdr_, &v)) + return false; + + x = static_cast<unsigned int> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (long& x) + { + int32_t v; + + if (!xdr_int32_t (&xdr_, &v)) + return false; + + x = static_cast<long> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (unsigned long& x) + { + uint32_t v; + + if (!xdr_uint32_t (&xdr_, &v)) + return false; + + x = static_cast<unsigned long> (v); + return true; + } + +#ifdef XSDE_LONGLONG + inline bool ixdrstream:: + operator>> (long long& x) + { + int64_t v; + + if (!xdr_int64_t (&xdr_, &v)) + return false; + + x = static_cast<long long> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (unsigned long long& x) + { + uint64_t v; + + if (!xdr_uint64_t (&xdr_, &v)) + return false; + + x = static_cast<unsigned long long> (v); + return true; + } +#endif + + inline bool ixdrstream:: + operator>> (as_size& x) + { + // Assume size is 32-bit. + // + uint32_t v; + + if (!xdr_uint32_t (&xdr_, &v)) + return false; + + x.s_ = static_cast<size_t> (v); + return true; + } + + inline bool ixdrstream:: + operator>> (float& x) + { + return xdr_float (&xdr_, &x); + } + + inline bool ixdrstream:: + operator>> (double& x) + { + return xdr_double (&xdr_, &x); + } + + inline bool + operator>> (ixdrstream&, any_type&) + { + return true; + } + + inline bool + operator>> (ixdrstream&, any_simple_type&) + { + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/istream.txx b/libxsde/xsde/cxx/hybrid/xdr/istream.txx new file mode 100644 index 0000000..c13015d --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/istream.txx @@ -0,0 +1,184 @@ +// file : xsde/cxx/hybrid/xdr/istream.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + template <typename T> + void + operator>> (ixdrstream& s, pod_seq<T>& x) + { + size_t n; + ixdrstream::as_size as_size (n); + s >> as_size; + + x.clear (); + + if (n > 0) + { + x.reserve (n); + + T i; + while (n--) + { + s >> i; + x.push_back (i); + } + } + } + + template <typename T> + void + operator>> (ixdrstream& s, fix_seq<T>& x) + { + size_t n; + ixdrstream::as_size as_size (n); + s >> as_size; + + x.clear (); + + if (n > 0) + { + x.reserve (n); + + while (n--) + { + T i; + s >> i; + x.push_back (i); + } + } + } + + template <typename T> + void + operator>> (ixdrstream& s, var_seq<T>& x) + { + size_t n; + ixdrstream::as_size as_size (n); + s >> as_size; + + x.clear (); + + if (n > 0) + { + x.reserve (n); + + while (n--) + { + T* p = new T; + typename var_seq<T>::guard g (p); + s >> *p; + g.release (); + x.push_back (p); + } + } + } + +#else // XSDE_EXCEPTIONS + + template <typename T> + bool + operator>> (ixdrstream& s, pod_seq<T>& x) + { + size_t n; + ixdrstream::as_size as_size (n); + + if (!(s >> as_size)) + return false; + + x.clear (); + + if (n > 0) + { + if (x.reserve (n)) + return false; + + T i; + while (n--) + { + if (!(s >> i) || x.push_back (i)) + return false; + } + } + + return true; + } + + template <typename T> + bool + operator>> (ixdrstream& s, fix_seq<T>& x) + { + size_t n; + ixdrstream::as_size as_size (n); + + if (!(s >> as_size)) + return false; + + x.clear (); + + if (n > 0) + { + if (x.reserve (n)) + return false; + + while (n--) + { + T i; + if (!(s >> i) || x.push_back (i)) + return false; + } + } + + return true; + } + + template <typename T> + bool + operator>> (ixdrstream& s, var_seq<T>& x) + { + size_t n; + ixdrstream::as_size as_size (n); + + if (!(s >> as_size)) + return false; + + x.clear (); + + if (n > 0) + { + if (x.reserve (n)) + return false; + + while (n--) + { + T* p = new T; + + if (p == 0) + return false; + + if (!(s >> *p)) + { + delete p; + return false; + } + + if (x.push_back (p)) + return false; + } + } + + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/ostream.cxx b/libxsde/xsde/cxx/hybrid/xdr/ostream.cxx new file mode 100644 index 0000000..1abca26 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/ostream.cxx @@ -0,0 +1,92 @@ +// file : xsde/cxx/hybrid/xdr/ostream.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/config.hxx> + +#ifndef XSDE_STL +# include <string.h> +#endif + +#include <xsde/cxx/hybrid/xdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + // XDR strings always use 32-bit length. + // +#ifdef XSDE_STL + void oxdrstream:: + operator<< (const std::string& x) + { + char* p = const_cast<char*> (x.c_str ()); + unsigned int n = static_cast<unsigned int> (x.length ()); + + if (!xdr_u_int (&xdr_, &n) || !xdr_opaque (&xdr_, p, n)) + throw xdr_exception (); + } +#else + void oxdrstream:: + operator<< (const char* x) + { + unsigned int n = static_cast<unsigned int> (strlen (x)); + + if (!xdr_u_int (&xdr_, &n) || + !xdr_opaque (&xdr_, const_cast<char*> (x), n)) + throw xdr_exception (); + } +#endif + + void oxdrstream:: + operator<< (const buffer& x) + { + // XDR arrays are limited to 32-bit size. + // + unsigned int n = static_cast<unsigned int> (x.size ()); + + if (!xdr_u_int (&xdr_, &n) || + !xdr_opaque (&xdr_, const_cast<char*> (x.data ()), n)) + throw xdr_exception (); + } + +#else // XSDE_EXCEPTIONS + +#ifdef XSDE_STL + bool oxdrstream:: + operator<< (const std::string& x) + { + char* p = const_cast<char*> (x.c_str ()); + unsigned int n = static_cast<unsigned int> (x.length ()); + return xdr_u_int (&xdr_, &n) && xdr_opaque (&xdr_, p, n); + } +#else + bool oxdrstream:: + operator<< (const char* x) + { + unsigned int n = static_cast<unsigned int> (strlen (x)); + return xdr_u_int (&xdr_, &n) && + xdr_opaque (&xdr_, const_cast<char*> (x), n); + } +#endif + + bool oxdrstream:: + operator<< (const buffer& x) + { + // XDR arrays are limited to 32-bit size. + // + unsigned int n = static_cast<unsigned int> (x.size ()); + return xdr_u_int (&xdr_, &n) && + xdr_opaque (&xdr_, const_cast<char*> (x.data ()), n); + } + +#endif // XSDE_EXCEPTIONS + + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/ostream.hxx b/libxsde/xsde/cxx/hybrid/xdr/ostream.hxx new file mode 100644 index 0000000..7a6a2b9 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/ostream.hxx @@ -0,0 +1,181 @@ +// file : xsde/cxx/hybrid/xdr/ostream.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_HYBRID_XDR_OSTREAM_HXX +#define XSDE_CXX_HYBRID_XDR_OSTREAM_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t +#include <rpc/xdr.h> + +#ifdef XSDE_STL +# include <string> +#endif + +#include <xsde/cxx/buffer.hxx> +#include <xsde/cxx/date-time.hxx> + +#ifdef XSDE_STL +# include <xsde/cxx/qname-stl.hxx> +# include <xsde/cxx/string-sequence-stl.hxx> +#else +# include <xsde/cxx/qname.hxx> +# include <xsde/cxx/string-sequence.hxx> +#endif + +#include <xsde/cxx/hybrid/any-type.hxx> +#include <xsde/cxx/hybrid/sequence.hxx> + +#ifdef XSDE_EXCEPTIONS +# include <xsde/cxx/hybrid/xdr/exceptions.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + class oxdrstream + { + public: + explicit + oxdrstream (XDR& xdr); + + XDR& + impl (); + + public: + struct as_size + { + explicit as_size (size_t s) : s_ (s) {} + size_t s_; + }; + + public: +#ifdef XSDE_EXCEPTIONS + + void operator<< (bool); + void operator<< (signed char); + void operator<< (unsigned char); + void operator<< (short); + void operator<< (unsigned short); + void operator<< (int); + void operator<< (unsigned int); + void operator<< (long); + void operator<< (unsigned long); + +#ifdef XSDE_LONGLONG + void operator<< (long long); + void operator<< (unsigned long long); +#endif + void operator<< (as_size); + void operator<< (float); + void operator<< (double); + +#ifdef XSDE_STL + void operator<< (const std::string&); +#else + void operator<< (const char*); +#endif + void operator<< (const buffer&); + +#else // XSDE_EXCEPTIONS + + bool operator<< (bool); + bool operator<< (signed char); + bool operator<< (unsigned char); + bool operator<< (short); + bool operator<< (unsigned short); + bool operator<< (int); + bool operator<< (unsigned int); + bool operator<< (long); + bool operator<< (unsigned long); + +#ifdef XSDE_LONGLONG + bool operator<< (long long); + bool operator<< (unsigned long long); +#endif + bool operator<< (as_size); + bool operator<< (float); + bool operator<< (double); + +#ifdef XSDE_STL + bool operator<< (const std::string&); +#else + bool operator<< (const char*); +#endif + bool operator<< (const buffer&); + +#endif // XSDE_EXCEPTIONS + + private: + oxdrstream (const oxdrstream&); + oxdrstream& operator= (const oxdrstream&); + + private: + XDR& xdr_; + }; + +#ifdef XSDE_EXCEPTIONS + void operator<< (oxdrstream&, const any_type&); + void operator<< (oxdrstream&, const any_simple_type&); + void operator<< (oxdrstream&, const qname&); + void operator<< (oxdrstream&, const string_sequence&); + void operator<< (oxdrstream&, const time_zone&); + void operator<< (oxdrstream&, const date&); + void operator<< (oxdrstream&, const date_time&); + void operator<< (oxdrstream&, const duration&); + void operator<< (oxdrstream&, const gday&); + void operator<< (oxdrstream&, const gmonth&); + void operator<< (oxdrstream&, const gmonth_day&); + void operator<< (oxdrstream&, const gyear&); + void operator<< (oxdrstream&, const gyear_month&); + void operator<< (oxdrstream&, const time&); +#else + bool operator<< (oxdrstream&, const any_type&); + bool operator<< (oxdrstream&, const any_simple_type&); + bool operator<< (oxdrstream&, const qname&); + bool operator<< (oxdrstream&, const string_sequence&); + bool operator<< (oxdrstream&, const time_zone&); + bool operator<< (oxdrstream&, const date&); + bool operator<< (oxdrstream&, const date_time&); + bool operator<< (oxdrstream&, const duration&); + bool operator<< (oxdrstream&, const gday&); + bool operator<< (oxdrstream&, const gmonth&); + bool operator<< (oxdrstream&, const gmonth_day&); + bool operator<< (oxdrstream&, const gyear&); + bool operator<< (oxdrstream&, const gyear_month&); + bool operator<< (oxdrstream&, const time&); +#endif + +#ifdef XSDE_EXCEPTIONS + template <typename T> + void operator<< (oxdrstream&, const pod_seq<T>&); + + template <typename T> + void operator<< (oxdrstream&, const fix_seq<T>&); + + template <typename T> + void operator<< (oxdrstream&, const var_seq<T>&); +#else + template <typename T> + bool operator<< (oxdrstream&, const pod_seq<T>&); + + template <typename T> + bool operator<< (oxdrstream&, const fix_seq<T>&); + + template <typename T> + bool operator<< (oxdrstream&, const var_seq<T>&); +#endif + } + } +} + +#include <xsde/cxx/hybrid/xdr/ostream.ixx> +#include <xsde/cxx/hybrid/xdr/ostream.txx> + +#endif // XSDE_CXX_HYBRID_XDR_OSTREAM_HXX 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 <boris@codesynthesis.com> +// 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<bool_t> (x); + + if (!xdr_bool (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (signed char x) + { + int8_t v = static_cast<int8_t> (x); + + if (!xdr_int8_t (&xdr_, &v)) + throw xdr_exception (); + } + + + inline void oxdrstream:: + operator<< (unsigned char x) + { + uint8_t v = static_cast<uint8_t> (x); + + if (!xdr_uint8_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (short x) + { + int16_t v = static_cast<int16_t> (x); + + if (!xdr_int16_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned short x) + { + uint16_t v = static_cast<uint16_t> (x); + + if (!xdr_uint16_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (int x) + { + int32_t v = static_cast<int32_t> (x); + + if (!xdr_int32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned int x) + { + uint32_t v = static_cast<uint32_t> (x); + + if (!xdr_uint32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (long x) + { + int32_t v = static_cast<int32_t> (x); + + if (!xdr_int32_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned long x) + { + uint32_t v = static_cast<uint32_t> (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<int64_t> (x); + + if (!xdr_int64_t (&xdr_, &v)) + throw xdr_exception (); + } + + inline void oxdrstream:: + operator<< (unsigned long long x) + { + uint64_t v = static_cast<uint64_t> (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<uint32_t> (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<bool_t> (x); + return xdr_bool (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (signed char x) + { + int8_t v = static_cast<int8_t> (x); + return xdr_int8_t (&xdr_, &v); + } + + + inline bool oxdrstream:: + operator<< (unsigned char x) + { + uint8_t v = static_cast<uint8_t> (x); + return xdr_uint8_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (short x) + { + int16_t v = static_cast<int16_t> (x); + return xdr_int16_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned short x) + { + uint16_t v = static_cast<uint16_t> (x); + return xdr_uint16_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (int x) + { + int32_t v = static_cast<int32_t> (x); + return xdr_int32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned int x) + { + uint32_t v = static_cast<uint32_t> (x); + return xdr_uint32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (long x) + { + int32_t v = static_cast<int32_t> (x); + return xdr_int32_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned long x) + { + uint32_t v = static_cast<uint32_t> (x); + return xdr_uint32_t (&xdr_, &v); + } + +#ifdef XSDE_LONGLONG + inline bool oxdrstream:: + operator<< (long long x) + { + int64_t v = static_cast<int64_t> (x); + return xdr_int64_t (&xdr_, &v); + } + + inline bool oxdrstream:: + operator<< (unsigned long long x) + { + uint64_t v = static_cast<uint64_t> (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<uint32_t> (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 + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/ostream.txx b/libxsde/xsde/cxx/hybrid/xdr/ostream.txx new file mode 100644 index 0000000..5211b80 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/ostream.txx @@ -0,0 +1,110 @@ +// file : xsde/cxx/hybrid/xdr/ostream.txx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + +#ifdef XSDE_EXCEPTIONS + + template <typename T> + void + operator<< (oxdrstream& s, const pod_seq<T>& x) + { + s << oxdrstream::as_size (x.size ()); + + for (typename pod_seq<T>::const_iterator i = x.begin (); + i != x.end (); ++i) + { + s << *i; + } + } + + template <typename T> + void + operator<< (oxdrstream& s, const fix_seq<T>& x) + { + s << oxdrstream::as_size (x.size ()); + + for (typename fix_seq<T>::const_iterator i = x.begin (); + i != x.end (); ++i) + { + s << *i; + } + } + + template <typename T> + void + operator<< (oxdrstream& s, const var_seq<T>& x) + { + s << oxdrstream::as_size (x.size ()); + + for (typename var_seq<T>::const_iterator i = x.begin (); + i != x.end (); ++i) + { + s << *i; + } + } + +#else // XSDE_EXCEPTIONS + + template <typename T> + bool + operator<< (oxdrstream& s, const pod_seq<T>& x) + { + if (!(s << oxdrstream::as_size (x.size ()))) + return false; + + for (typename pod_seq<T>::const_iterator i = x.begin (); + i != x.end (); ++i) + { + if (!(s << *i)) + return false; + } + + return true; + } + + template <typename T> + bool + operator<< (oxdrstream& s, const fix_seq<T>& x) + { + if (!(s << oxdrstream::as_size (x.size ()))) + return false; + + for (typename fix_seq<T>::const_iterator i = x.begin (); + i != x.end (); ++i) + { + if (!(s << *i)) + return false; + } + + return true; + } + + template <typename T> + bool + operator<< (oxdrstream& s, const var_seq<T>& x) + { + if (!(s << oxdrstream::as_size (x.size ()))) + return false; + + for (typename var_seq<T>::const_iterator i = x.begin (); + i != x.end (); ++i) + { + if (!(s << *i)) + return false; + } + + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/qname.cxx b/libxsde/xsde/cxx/hybrid/xdr/qname.cxx new file mode 100644 index 0000000..47a6287 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/qname.cxx @@ -0,0 +1,74 @@ +// file : xsde/cxx/hybrid/xdr/qname.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/hybrid/xdr/istream.hxx> +#include <xsde/cxx/hybrid/xdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + void + operator<< (oxdrstream& s, const qname& x) + { + s << x.prefix (); + s << x.name (); + } + + void + operator>> (ixdrstream& s, qname& x) + { + +#ifdef XSDE_STL + std::string p, n; +#else + char* p; + char* n; +#endif + s >> p; + x.prefix (p); + + s >> n; // x will free p in case extraction fails + x.name (n); + } + +#else // XSDE_EXCEPTIONS + + bool + operator<< (oxdrstream& s, const qname& x) + { + return s << x.prefix () && s << x.name (); + } + + bool + operator>> (ixdrstream& s, qname& x) + { + +#ifdef XSDE_STL + std::string p, n; +#else + char* p; + char* n; +#endif + if (!(s >> p)) + return false; + + x.prefix (p); + + if (!(s >> n)) + return false; // x will free p + + x.name (n); + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx b/libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx new file mode 100644 index 0000000..f8b3a54 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx @@ -0,0 +1,107 @@ +// file : xsde/cxx/hybrid/xdr/string-sequence.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <xsde/cxx/hybrid/xdr/istream.hxx> +#include <xsde/cxx/hybrid/xdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + void + operator<< (oxdrstream& s, const string_sequence& x) + { + s << oxdrstream::as_size (x.size ()); + + for (string_sequence::const_iterator i = x.begin (); + i != x.end (); ++i) + { + s << *i; + } + } + + void + operator>> (ixdrstream& s, string_sequence& x) + { + size_t n; + ixdrstream::as_size as_size (n); + s >> as_size; + + x.clear (); + + if (n > 0) + { + x.reserve (n); + +#ifdef XSDE_STL + std::string i; +#else + char* i; +#endif + while (n--) + { + s >> i; + x.push_back (i); + } + } + } + +#else // XSDE_EXCEPTIONS + + bool + operator<< (oxdrstream& s, const string_sequence& x) + { + if (!(s << oxdrstream::as_size (x.size ()))) + return false; + + for (string_sequence::const_iterator i = x.begin (); + i != x.end (); ++i) + { + if (!(s << *i)) + return false; + } + + return true; + } + + bool + operator>> (ixdrstream& s, string_sequence& x) + { + size_t n; + ixdrstream::as_size as_size (n); + + if (!(s >> as_size)) + return false; + + x.clear (); + + if (n > 0) + { + if (x.reserve (n)) + return false; + +#ifdef XSDE_STL + std::string i; +#else + char* i; +#endif + while (n--) + { + if (!(s >> i) || x.push_back (i)) + return false; + } + } + + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} |