diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2009-03-08 17:23:30 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2009-03-08 17:23:30 +0200 |
commit | 0bce70a0e483294b83b8bf9d5468838a63405612 (patch) | |
tree | d11afb4998d6980435c15c4df6e40b1979531672 /libxsde/xsde/cxx/hybrid/cdr/istream.txx | |
parent | 6c63b913179127e09ed7d9da8920493ccceec6ce (diff) |
Add support for binary representations
xsde/cxx/hybrid/insertion-*: insertion operators generator
xsde/cxx/hybrid/extraction-*: extraction operators generator
libxsde/xsde/cxx/hybrid/cdr/: CDR support code
libxsde/xsde/cxx/hybrid/xdr/: XDR support code
tests/cxx/hybrid/binary/: new tests
examples/cxx/hybrid/binary/: new examples
documentation/cxx/hybrid/guide/: new chapter
Diffstat (limited to 'libxsde/xsde/cxx/hybrid/cdr/istream.txx')
-rw-r--r-- | libxsde/xsde/cxx/hybrid/cdr/istream.txx | 184 |
1 files changed, 184 insertions, 0 deletions
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 + } + } +} |