aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/xdr/ostream.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/ostream.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/ostream.cxx')
-rw-r--r--libxsde/xsde/cxx/hybrid/xdr/ostream.cxx92
1 files changed, 92 insertions, 0 deletions
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
+
+ }
+ }
+}