diff options
Diffstat (limited to 'libxsde/xsde/cxx/hybrid')
27 files changed, 4991 insertions, 1 deletions
diff --git a/libxsde/xsde/cxx/hybrid/cdr/date-time.cxx b/libxsde/xsde/cxx/hybrid/cdr/date-time.cxx new file mode 100644 index 0000000..4feaa44 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/date-time.cxx @@ -0,0 +1,764 @@ +// file : xsde/cxx/hybrid/cdr/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/cdr/istream.hxx> +#include <xsde/cxx/hybrid/cdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + // operator<< + // + + void + operator<< (ocdrstream& s, const time_zone& x) + { + s << x.zone_hours (); + s << x.zone_minutes (); + } + + void + operator<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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>> (icdrstream& s, time_zone& x) + { + short h, m; + s >> h; + s >> m; + + x.zone_hours (h); + x.zone_minutes (m); + } + + void + operator>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& s, gyear& x) + { + int y; + bool zp; + + s >> y; + s >> zp; + + x.year (y); + + if (zp) + { + time_zone& z = x; + s >> z; + } + } + + void + operator>> (icdrstream& 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>> (icdrstream& 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<< (ocdrstream& s, const time_zone& x) + { + return s << x.zone_hours () && s << x.zone_minutes (); + } + + bool + operator<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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<< (ocdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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>> (icdrstream& 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/cdr/exceptions.cxx b/libxsde/xsde/cxx/hybrid/cdr/exceptions.cxx new file mode 100644 index 0000000..8b79805 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/exceptions.cxx @@ -0,0 +1,21 @@ +// file : xsde/cxx/hybrid/cdr/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/cdr/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + const char* cdr_exception:: + what () const throw () + { + return "CDR stream operation failed"; + } + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/cdr/exceptions.hxx b/libxsde/xsde/cxx/hybrid/cdr/exceptions.hxx new file mode 100644 index 0000000..bc0b861 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/exceptions.hxx @@ -0,0 +1,26 @@ +// file : xsde/cxx/hybrid/cdr/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_CDR_EXCEPTIONS_HXX +#define XSDE_CXX_HYBRID_CDR_EXCEPTIONS_HXX + +#include <xsde/cxx/exceptions.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + struct cdr_exception: xsde::cxx::exception + { + virtual const char* + what () const throw (); + }; + } + } +} + +#endif // XSDE_CXX_HYBRID_CDR_EXCEPTIONS_HXX 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 <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/cdr/istream.hxx> + +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<ACE_CDR::Octet*> (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<ACE_CDR::Octet*> (x.data ()), n); + } + +#endif // XSDE_EXCEPTIONS + + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/cdr/istream.hxx b/libxsde/xsde/cxx/hybrid/cdr/istream.hxx new file mode 100644 index 0000000..484010b --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/istream.hxx @@ -0,0 +1,182 @@ +// file : xsde/cxx/hybrid/cdr/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_CDR_ISTREAM_HXX +#define XSDE_CXX_HYBRID_CDR_ISTREAM_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#ifdef XSDE_STL +# include <string> +#endif + +#include <ace/CDR_Stream.h> + +#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/cdr/exceptions.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + class icdrstream + { + public: + explicit + icdrstream (ACE_InputCDR& cdr); + + ACE_InputCDR& + 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: + icdrstream (const icdrstream&); + icdrstream& operator= (const icdrstream&); + + private: + ACE_InputCDR& cdr_; + }; + +#ifdef XSDE_EXCEPTIONS + void operator>> (icdrstream&, any_type&); + void operator>> (icdrstream&, any_simple_type&); + void operator>> (icdrstream&, qname&); + void operator>> (icdrstream&, string_sequence&); + void operator>> (icdrstream&, time_zone&); + void operator>> (icdrstream&, date&); + void operator>> (icdrstream&, date_time&); + void operator>> (icdrstream&, duration&); + void operator>> (icdrstream&, gday&); + void operator>> (icdrstream&, gmonth&); + void operator>> (icdrstream&, gmonth_day&); + void operator>> (icdrstream&, gyear&); + void operator>> (icdrstream&, gyear_month&); + void operator>> (icdrstream&, time&); +#else + bool operator>> (icdrstream&, any_type&); + bool operator>> (icdrstream&, any_simple_type&); + bool operator>> (icdrstream&, qname&); + bool operator>> (icdrstream&, string_sequence&); + bool operator>> (icdrstream&, time_zone&); + bool operator>> (icdrstream&, date&); + bool operator>> (icdrstream&, date_time&); + bool operator>> (icdrstream&, duration&); + bool operator>> (icdrstream&, gday&); + bool operator>> (icdrstream&, gmonth&); + bool operator>> (icdrstream&, gmonth_day&); + bool operator>> (icdrstream&, gyear&); + bool operator>> (icdrstream&, gyear_month&); + bool operator>> (icdrstream&, time&); +#endif + +#ifdef XSDE_EXCEPTIONS + template <typename T> + void operator>> (icdrstream&, pod_seq<T>&); + + template <typename T> + void operator>> (icdrstream&, fix_seq<T>&); + + template <typename T> + void operator>> (icdrstream&, var_seq<T>&); +#else + template <typename T> + bool operator>> (icdrstream&, pod_seq<T>&); + + template <typename T> + bool operator>> (icdrstream&, fix_seq<T>&); + + template <typename T> + bool operator>> (icdrstream&, var_seq<T>&); +#endif + } + } +} + +#include <xsde/cxx/hybrid/cdr/istream.ixx> +#include <xsde/cxx/hybrid/cdr/istream.txx> + +#endif // XSDE_CXX_HYBRID_CDR_ISTREAM_HXX diff --git a/libxsde/xsde/cxx/hybrid/cdr/istream.ixx b/libxsde/xsde/cxx/hybrid/cdr/istream.ixx new file mode 100644 index 0000000..36d67dd --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/istream.ixx @@ -0,0 +1,385 @@ +// file : xsde/cxx/hybrid/cdr/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 icdrstream:: + icdrstream (ACE_InputCDR& cdr) + : cdr_ (cdr) + { + } + + inline ACE_InputCDR& icdrstream:: + impl () + { + return cdr_; + } + +#ifdef XSDE_EXCEPTIONS + + inline void icdrstream:: + operator>> (bool& x) + { + ACE_CDR::Boolean v; + + if (!cdr_.read_boolean (v)) + throw cdr_exception (); + + x = static_cast<bool> (v); + } + + inline void icdrstream:: + operator>> (signed char& x) + { + ACE_CDR::Octet v; + + if (!cdr_.read_octet (v)) + throw cdr_exception (); + + x = static_cast<signed char> (v); + } + + + inline void icdrstream:: + operator>> (unsigned char& x) + { + ACE_CDR::Octet v; + + if (!cdr_.read_octet (v)) + throw cdr_exception (); + + x = static_cast<unsigned char> (v); + } + + inline void icdrstream:: + operator>> (short& x) + { + ACE_CDR::Short v; + + if (!cdr_.read_short (v)) + throw cdr_exception (); + + x = static_cast<short> (v); + } + + inline void icdrstream:: + operator>> (unsigned short& x) + { + ACE_CDR::UShort v; + + if (!cdr_.read_ushort (v)) + throw cdr_exception (); + + x = static_cast<unsigned short> (v); + } + + inline void icdrstream:: + operator>> (int& x) + { + ACE_CDR::Long v; + + if (!cdr_.read_long (v)) + throw cdr_exception (); + + x = static_cast<int> (v); + } + + inline void icdrstream:: + operator>> (unsigned int& x) + { + ACE_CDR::ULong v; + + if (!cdr_.read_ulong (v)) + throw cdr_exception (); + + x = static_cast<unsigned int> (v); + } + + inline void icdrstream:: + operator>> (long& x) + { + ACE_CDR::Long v; + + if (!cdr_.read_long (v)) + throw cdr_exception (); + + x = static_cast<long> (v); + } + + inline void icdrstream:: + operator>> (unsigned long& x) + { + ACE_CDR::ULong v; + + if (!cdr_.read_ulong (v)) + throw cdr_exception (); + + x = static_cast<unsigned long> (v); + } + +#ifdef XSDE_LONGLONG + inline void icdrstream:: + operator>> (long long& x) + { + ACE_CDR::LongLong v; + + if (!cdr_.read_longlong (v)) + throw cdr_exception (); + + x = static_cast<long long> (v); + } + + inline void icdrstream:: + operator>> (unsigned long long& x) + { + ACE_CDR::ULongLong v; + + if (!cdr_.read_ulonglong (v)) + throw cdr_exception (); + + x = static_cast<unsigned long long> (v); + } +#endif + + inline void icdrstream:: + operator>> (as_size& x) + { + // Assume size is 32-bit. + // + ACE_CDR::ULong v; + + if (!cdr_.read_ulong (v)) + throw cdr_exception (); + + x.s_ = static_cast<size_t> (v); + } + + inline void icdrstream:: + operator>> (float& x) + { + ACE_CDR::Float v; + + if (!cdr_.read_float (v)) + throw cdr_exception (); + + x = static_cast<float> (v); + } + + inline void icdrstream:: + operator>> (double& x) + { + ACE_CDR::Double v; + + if (!cdr_.read_double (v)) + throw cdr_exception (); + + x = static_cast<double> (v); + } + + inline void + operator>> (icdrstream&, any_type&) + { + } + + inline void + operator>> (icdrstream&, any_simple_type&) + { + } + +#else // XSDE_EXCEPTIONS + + inline bool icdrstream:: + operator>> (bool& x) + { + ACE_CDR::Boolean v; + + if (!cdr_.read_boolean (v)) + return false; + + x = static_cast<bool> (v); + return true; + } + + inline bool icdrstream:: + operator>> (signed char& x) + { + ACE_CDR::Octet v; + + if (!cdr_.read_octet (v)) + return false; + + x = static_cast<signed char> (v); + return true; + } + + + inline bool icdrstream:: + operator>> (unsigned char& x) + { + ACE_CDR::Octet v; + + if (!cdr_.read_octet (v)) + return false; + + x = static_cast<unsigned char> (v); + return true; + } + + inline bool icdrstream:: + operator>> (short& x) + { + ACE_CDR::Short v; + + if (!cdr_.read_short (v)) + return false; + + x = static_cast<short> (v); + return true; + } + + inline bool icdrstream:: + operator>> (unsigned short& x) + { + ACE_CDR::UShort v; + + if (!cdr_.read_ushort (v)) + return false; + + x = static_cast<unsigned short> (v); + return true; + } + + inline bool icdrstream:: + operator>> (int& x) + { + ACE_CDR::Long v; + + if (!cdr_.read_long (v)) + return false; + + x = static_cast<int> (v); + return true; + } + + inline bool icdrstream:: + operator>> (unsigned int& x) + { + ACE_CDR::ULong v; + + if (!cdr_.read_ulong (v)) + return false; + + x = static_cast<unsigned int> (v); + return true; + } + + inline bool icdrstream:: + operator>> (long& x) + { + ACE_CDR::Long v; + + if (!cdr_.read_long (v)) + return false; + + x = static_cast<long> (v); + return true; + } + + inline bool icdrstream:: + operator>> (unsigned long& x) + { + ACE_CDR::ULong v; + + if (!cdr_.read_ulong (v)) + return false; + + x = static_cast<unsigned long> (v); + return true; + } + +#ifdef XSDE_LONGLONG + inline bool icdrstream:: + operator>> (long long& x) + { + ACE_CDR::LongLong v; + + if (!cdr_.read_longlong (v)) + return false; + + x = static_cast<long long> (v); + return true; + } + + inline bool icdrstream:: + operator>> (unsigned long long& x) + { + ACE_CDR::ULongLong v; + + if (!cdr_.read_ulonglong (v)) + return false; + + x = static_cast<unsigned long long> (v); + return true; + } +#endif + + inline bool icdrstream:: + operator>> (as_size& x) + { + // Assume size is 32-bit. + // + ACE_CDR::ULong v; + + if (!cdr_.read_ulong (v)) + return false; + + x.s_ = static_cast<size_t> (v); + return true; + } + + inline bool icdrstream:: + operator>> (float& x) + { + ACE_CDR::Float v; + + if (!cdr_.read_float (v)) + return false; + + x = static_cast<float> (v); + return true; + } + + inline bool icdrstream:: + operator>> (double& x) + { + ACE_CDR::Double v; + + if (!cdr_.read_double (v)) + return false; + + x = static_cast<double> (v); + return true; + } + + inline bool + operator>> (icdrstream&, any_type&) + { + return true; + } + + inline bool + operator>> (icdrstream&, any_simple_type&) + { + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/cdr/istream.txx b/libxsde/xsde/cxx/hybrid/cdr/istream.txx new file mode 100644 index 0000000..9afc5f5 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/istream.txx @@ -0,0 +1,184 @@ +// file : xsde/cxx/hybrid/cdr/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>> (icdrstream& s, pod_seq<T>& x) + { + size_t n; + icdrstream::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>> (icdrstream& s, fix_seq<T>& x) + { + size_t n; + icdrstream::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>> (icdrstream& s, var_seq<T>& x) + { + size_t n; + icdrstream::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>> (icdrstream& s, pod_seq<T>& x) + { + size_t n; + icdrstream::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>> (icdrstream& s, fix_seq<T>& x) + { + size_t n; + icdrstream::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>> (icdrstream& s, var_seq<T>& x) + { + size_t n; + icdrstream::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/cdr/ostream.cxx b/libxsde/xsde/cxx/hybrid/cdr/ostream.cxx new file mode 100644 index 0000000..e72e5fd --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/ostream.cxx @@ -0,0 +1,88 @@ +// file : xsde/cxx/hybrid/cdr/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/cdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + // CDR strings always use 32-bit length. + // +#ifdef XSDE_STL + void ocdrstream:: + operator<< (const std::string& x) + { + if (!cdr_.write_string ( + static_cast<ACE_CDR::ULong> (x.length ()), x.c_str ())) + throw cdr_exception (); + } +#else + void ocdrstream:: + operator<< (const char* x) + { + if (!cdr_.write_string (static_cast<ACE_CDR::ULong> (strlen (x)), x)) + throw cdr_exception (); + } +#endif + + void ocdrstream:: + operator<< (const buffer& x) + { + // CDR arrays are limited to 32-bit size. + // + size_t n = x.size (); + + if (!cdr_.write_ulong (static_cast<ACE_CDR::ULong> (n)) || + !cdr_.write_octet_array ( + reinterpret_cast<const ACE_CDR::Octet*> (x.data ()), n)) + throw cdr_exception (); + } + +#else // XSDE_EXCEPTIONS + +#ifdef XSDE_STL + bool ocdrstream:: + operator<< (const std::string& x) + { + return cdr_.write_string ( + static_cast<ACE_CDR::ULong> (x.length ()), x.c_str ()); + } +#else + bool ocdrstream:: + operator<< (const char* x) + { + return cdr_.write_string ( + static_cast<ACE_CDR::ULong> (strlen (x)), x); + } +#endif + + bool ocdrstream:: + operator<< (const buffer& x) + { + // CDR arrays are limited to 32-bit size. + // + size_t n = x.size (); + + return cdr_.write_ulong (static_cast<ACE_CDR::ULong> (n)) && + cdr_.write_octet_array ( + reinterpret_cast<const ACE_CDR::Octet*> (x.data ()), n); + } + +#endif // XSDE_EXCEPTIONS + + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/cdr/ostream.hxx b/libxsde/xsde/cxx/hybrid/cdr/ostream.hxx new file mode 100644 index 0000000..6b33fe0 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/ostream.hxx @@ -0,0 +1,182 @@ +// file : xsde/cxx/hybrid/cdr/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_CDR_OSTREAM_HXX +#define XSDE_CXX_HYBRID_CDR_OSTREAM_HXX + +#include <xsde/cxx/config.hxx> + +#include <stddef.h> // size_t + +#ifdef XSDE_STL +# include <string> +#endif + +#include <ace/CDR_Stream.h> + +#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/cdr/exceptions.hxx> +#endif + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { + class ocdrstream + { + public: + explicit + ocdrstream (ACE_OutputCDR& cdr); + + ACE_OutputCDR& + 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: + ocdrstream (const ocdrstream&); + ocdrstream& operator= (const ocdrstream&); + + private: + ACE_OutputCDR& cdr_; + }; + +#ifdef XSDE_EXCEPTIONS + void operator<< (ocdrstream&, const any_type&); + void operator<< (ocdrstream&, const any_simple_type&); + void operator<< (ocdrstream&, const qname&); + void operator<< (ocdrstream&, const string_sequence&); + void operator<< (ocdrstream&, const time_zone&); + void operator<< (ocdrstream&, const date&); + void operator<< (ocdrstream&, const date_time&); + void operator<< (ocdrstream&, const duration&); + void operator<< (ocdrstream&, const gday&); + void operator<< (ocdrstream&, const gmonth&); + void operator<< (ocdrstream&, const gmonth_day&); + void operator<< (ocdrstream&, const gyear&); + void operator<< (ocdrstream&, const gyear_month&); + void operator<< (ocdrstream&, const time&); +#else + bool operator<< (ocdrstream&, const any_type&); + bool operator<< (ocdrstream&, const any_simple_type&); + bool operator<< (ocdrstream&, const qname&); + bool operator<< (ocdrstream&, const string_sequence&); + bool operator<< (ocdrstream&, const time_zone&); + bool operator<< (ocdrstream&, const date&); + bool operator<< (ocdrstream&, const date_time&); + bool operator<< (ocdrstream&, const duration&); + bool operator<< (ocdrstream&, const gday&); + bool operator<< (ocdrstream&, const gmonth&); + bool operator<< (ocdrstream&, const gmonth_day&); + bool operator<< (ocdrstream&, const gyear&); + bool operator<< (ocdrstream&, const gyear_month&); + bool operator<< (ocdrstream&, const time&); +#endif + +#ifdef XSDE_EXCEPTIONS + template <typename T> + void operator<< (ocdrstream&, const pod_seq<T>&); + + template <typename T> + void operator<< (ocdrstream&, const fix_seq<T>&); + + template <typename T> + void operator<< (ocdrstream&, const var_seq<T>&); +#else + template <typename T> + bool operator<< (ocdrstream&, const pod_seq<T>&); + + template <typename T> + bool operator<< (ocdrstream&, const fix_seq<T>&); + + template <typename T> + bool operator<< (ocdrstream&, const var_seq<T>&); +#endif + } + } +} + +#include <xsde/cxx/hybrid/cdr/ostream.ixx> +#include <xsde/cxx/hybrid/cdr/ostream.txx> + +#endif // XSDE_CXX_HYBRID_CDR_OSTREAM_HXX diff --git a/libxsde/xsde/cxx/hybrid/cdr/ostream.ixx b/libxsde/xsde/cxx/hybrid/cdr/ostream.ixx new file mode 100644 index 0000000..272c5dd --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/ostream.ixx @@ -0,0 +1,245 @@ +// file : xsde/cxx/hybrid/cdr/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 ocdrstream:: + ocdrstream (ACE_OutputCDR& cdr) + : cdr_ (cdr) + { + } + + inline ACE_OutputCDR& ocdrstream:: + impl () + { + return cdr_; + } + +#ifdef XSDE_EXCEPTIONS + + inline void ocdrstream:: + operator<< (bool x) + { + if (!cdr_.write_boolean (static_cast<ACE_CDR::Boolean> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (signed char x) + { + if (!cdr_.write_octet (static_cast<ACE_CDR::Octet> (x))) + throw cdr_exception (); + } + + + inline void ocdrstream:: + operator<< (unsigned char x) + { + if (!cdr_.write_octet (static_cast<ACE_CDR::Octet> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (short x) + { + if (!cdr_.write_short (static_cast<ACE_CDR::Short> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (unsigned short x) + { + if (!cdr_.write_ushort (static_cast<ACE_CDR::UShort> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (int x) + { + if (!cdr_.write_long (static_cast<ACE_CDR::Long> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (unsigned int x) + { + if (!cdr_.write_ulong (static_cast<ACE_CDR::ULong> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (long x) + { + if (!cdr_.write_long (static_cast<ACE_CDR::Long> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (unsigned long x) + { + if (!cdr_.write_ulong (static_cast<ACE_CDR::ULong> (x))) + throw cdr_exception (); + } + +#ifdef XSDE_LONGLONG + inline void ocdrstream:: + operator<< (long long x) + { + if (!cdr_.write_longlong (static_cast<ACE_CDR::LongLong> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (unsigned long long x) + { + if (!cdr_.write_ulonglong (static_cast<ACE_CDR::ULongLong> (x))) + throw cdr_exception (); + } +#endif + + inline void ocdrstream:: + operator<< (as_size x) + { + // Assume size is 32-bit. + // + if (!cdr_.write_ulong (static_cast<ACE_CDR::ULong> (x.s_))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (float x) + { + if (!cdr_.write_float (static_cast<ACE_CDR::Float> (x))) + throw cdr_exception (); + } + + inline void ocdrstream:: + operator<< (double x) + { + if (!cdr_.write_double (static_cast<ACE_CDR::Double> (x))) + throw cdr_exception (); + } + + inline void + operator<< (ocdrstream&, const any_type&) + { + } + + inline void + operator<< (ocdrstream&, const any_simple_type&) + { + } + +#else // XSDE_EXCEPTIONS + + inline bool ocdrstream:: + operator<< (bool x) + { + return cdr_.write_boolean (static_cast<ACE_CDR::Boolean> (x)); + } + + inline bool ocdrstream:: + operator<< (signed char x) + { + return cdr_.write_octet (static_cast<ACE_CDR::Octet> (x)); + } + + + inline bool ocdrstream:: + operator<< (unsigned char x) + { + return cdr_.write_octet (static_cast<ACE_CDR::Octet> (x)); + } + + inline bool ocdrstream:: + operator<< (short x) + { + return cdr_.write_short (static_cast<ACE_CDR::Short> (x)); + } + + inline bool ocdrstream:: + operator<< (unsigned short x) + { + return cdr_.write_ushort (static_cast<ACE_CDR::UShort> (x)); + } + + inline bool ocdrstream:: + operator<< (int x) + { + return cdr_.write_long (static_cast<ACE_CDR::Long> (x)); + } + + inline bool ocdrstream:: + operator<< (unsigned int x) + { + return cdr_.write_ulong (static_cast<ACE_CDR::ULong> (x)); + } + + inline bool ocdrstream:: + operator<< (long x) + { + return cdr_.write_long (static_cast<ACE_CDR::Long> (x)); + } + + inline bool ocdrstream:: + operator<< (unsigned long x) + { + return cdr_.write_ulong (static_cast<ACE_CDR::ULong> (x)); + } + +#ifdef XSDE_LONGLONG + inline bool ocdrstream:: + operator<< (long long x) + { + return cdr_.write_longlong (static_cast<ACE_CDR::LongLong> (x)); + } + + inline bool ocdrstream:: + operator<< (unsigned long long x) + { + return cdr_.write_ulonglong (static_cast<ACE_CDR::ULongLong> (x)); + } +#endif + + inline bool ocdrstream:: + operator<< (as_size x) + { + // Assume size is 32-bit. + // + return cdr_.write_ulong (static_cast<ACE_CDR::ULong> (x.s_)); + } + + inline bool ocdrstream:: + operator<< (float x) + { + return cdr_.write_float (static_cast<ACE_CDR::Float> (x)); + } + + inline bool ocdrstream:: + operator<< (double x) + { + return cdr_.write_double (static_cast<ACE_CDR::Double> (x)); + } + + inline bool + operator<< (ocdrstream&, const any_type&) + { + return true; + } + + inline bool + operator<< (ocdrstream&, const any_simple_type&) + { + return true; + } + +#endif // XSDE_EXCEPTIONS + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/cdr/ostream.txx b/libxsde/xsde/cxx/hybrid/cdr/ostream.txx new file mode 100644 index 0000000..1dd40df --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/ostream.txx @@ -0,0 +1,110 @@ +// file : xsde/cxx/hybrid/cdr/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<< (ocdrstream& s, const pod_seq<T>& x) + { + s << ocdrstream::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<< (ocdrstream& s, const fix_seq<T>& x) + { + s << ocdrstream::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<< (ocdrstream& s, const var_seq<T>& x) + { + s << ocdrstream::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<< (ocdrstream& s, const pod_seq<T>& x) + { + if (!(s << ocdrstream::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<< (ocdrstream& s, const fix_seq<T>& x) + { + if (!(s << ocdrstream::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<< (ocdrstream& s, const var_seq<T>& x) + { + if (!(s << ocdrstream::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/cdr/qname.cxx b/libxsde/xsde/cxx/hybrid/cdr/qname.cxx new file mode 100644 index 0000000..396d70b --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/qname.cxx @@ -0,0 +1,74 @@ +// file : xsde/cxx/hybrid/cdr/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/cdr/istream.hxx> +#include <xsde/cxx/hybrid/cdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + void + operator<< (ocdrstream& s, const qname& x) + { + s << x.prefix (); + s << x.name (); + } + + void + operator>> (icdrstream& 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<< (ocdrstream& s, const qname& x) + { + return s << x.prefix () && s << x.name (); + } + + bool + operator>> (icdrstream& 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/cdr/string-sequence.cxx b/libxsde/xsde/cxx/hybrid/cdr/string-sequence.cxx new file mode 100644 index 0000000..5ba29f2 --- /dev/null +++ b/libxsde/xsde/cxx/hybrid/cdr/string-sequence.cxx @@ -0,0 +1,107 @@ +// file : xsde/cxx/hybrid/cdr/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/cdr/istream.hxx> +#include <xsde/cxx/hybrid/cdr/ostream.hxx> + +namespace xsde +{ + namespace cxx + { + namespace hybrid + { +#ifdef XSDE_EXCEPTIONS + + void + operator<< (ocdrstream& s, const string_sequence& x) + { + s << ocdrstream::as_size (x.size ()); + + for (string_sequence::const_iterator i = x.begin (); + i != x.end (); ++i) + { + s << *i; + } + } + + void + operator>> (icdrstream& s, string_sequence& x) + { + size_t n; + icdrstream::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<< (ocdrstream& s, const string_sequence& x) + { + if (!(s << ocdrstream::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>> (icdrstream& s, string_sequence& x) + { + size_t n; + icdrstream::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 + } + } +} diff --git a/libxsde/xsde/cxx/hybrid/sequence.hxx b/libxsde/xsde/cxx/hybrid/sequence.hxx index d7f6dcb..3e43b6d 100644 --- a/libxsde/xsde/cxx/hybrid/sequence.hxx +++ b/libxsde/xsde/cxx/hybrid/sequence.hxx @@ -789,7 +789,7 @@ namespace xsde swap (var_seq&); #ifdef XSDE_EXCEPTIONS - private: + public: struct guard { ~guard () { delete p_; } 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 + } + } +} |