aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-03-08 17:23:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-03-08 17:23:30 +0200
commit0bce70a0e483294b83b8bf9d5468838a63405612 (patch)
treed11afb4998d6980435c15c4df6e40b1979531672 /libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx
parent6c63b913179127e09ed7d9da8920493ccceec6ce (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/xdr/string-sequence.cxx')
-rw-r--r--libxsde/xsde/cxx/hybrid/xdr/string-sequence.cxx107
1 files changed, 107 insertions, 0 deletions
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
+ }
+ }
+}