aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/xdr/istream.ixx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2009-04-13 21:05:41 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2009-04-13 21:05:41 +0200
commitbb3143a129b91e6442a14ec1a6b05ff62c5d8b55 (patch)
treef287c29c073a8a2d0eb20bfcbd52538755173b87 /libxsde/xsde/cxx/hybrid/xdr/istream.ixx
parentb2e52f3b1b95889f28baacfe1e7d4ffc570a6685 (diff)
Rework XDR code to be more portable
Also don't link to libnsl by default since not all platforms have it.
Diffstat (limited to 'libxsde/xsde/cxx/hybrid/xdr/istream.ixx')
-rw-r--r--libxsde/xsde/cxx/hybrid/xdr/istream.ixx140
1 files changed, 44 insertions, 96 deletions
diff --git a/libxsde/xsde/cxx/hybrid/xdr/istream.ixx b/libxsde/xsde/cxx/hybrid/xdr/istream.ixx
index 86dd0ec..b2e7dad 100644
--- a/libxsde/xsde/cxx/hybrid/xdr/istream.ixx
+++ b/libxsde/xsde/cxx/hybrid/xdr/istream.ixx
@@ -9,6 +9,12 @@ namespace xsde
{
namespace hybrid
{
+ extern "C"
+ typedef bool_t (*ixdr_longlong_p) (XDR*, long long*);
+
+ extern "C"
+ typedef bool_t (*ixdr_u_longlong_p) (XDR*, unsigned long long*);
+
inline ixdrstream::
ixdrstream (XDR& xdr)
: xdr_ (xdr)
@@ -37,9 +43,9 @@ namespace xsde
inline void ixdrstream::
operator>> (signed char& x)
{
- int8_t v;
+ char v;
- if (!xdr_int8_t (&xdr_, &v))
+ if (!xdr_char (&xdr_, &v))
throw xdr_exception ();
x = static_cast<signed char> (v);
@@ -49,64 +55,44 @@ namespace xsde
inline void ixdrstream::
operator>> (unsigned char& x)
{
- uint8_t v;
-
- if (!xdr_uint8_t (&xdr_, &v))
+ if (!xdr_u_char (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<unsigned char> (v);
}
inline void ixdrstream::
operator>> (short& x)
{
- int16_t v;
-
- if (!xdr_int16_t (&xdr_, &v))
+ if (!xdr_short (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<short> (v);
}
inline void ixdrstream::
operator>> (unsigned short& x)
{
- uint16_t v;
-
- if (!xdr_uint16_t (&xdr_, &v))
+ if (!xdr_u_short (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<unsigned short> (v);
}
inline void ixdrstream::
operator>> (int& x)
{
- int32_t v;
-
- if (!xdr_int32_t (&xdr_, &v))
+ if (!xdr_int (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<int> (v);
}
inline void ixdrstream::
operator>> (unsigned int& x)
{
- uint32_t v;
-
- if (!xdr_uint32_t (&xdr_, &v))
+ if (!xdr_u_int (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<unsigned int> (v);
}
inline void ixdrstream::
operator>> (long& x)
{
- int32_t v;
+ int v;
- if (!xdr_int32_t (&xdr_, &v))
+ if (!xdr_int (&xdr_, &v))
throw xdr_exception ();
x = static_cast<long> (v);
@@ -115,9 +101,9 @@ namespace xsde
inline void ixdrstream::
operator>> (unsigned long& x)
{
- uint32_t v;
+ unsigned int v;
- if (!xdr_uint32_t (&xdr_, &v))
+ if (!xdr_u_int (&xdr_, &v))
throw xdr_exception ();
x = static_cast<unsigned long> (v);
@@ -127,23 +113,21 @@ namespace xsde
inline void ixdrstream::
operator>> (long long& x)
{
- int64_t v;
+ ixdr_longlong_p f =
+ reinterpret_cast<ixdr_longlong_p> (::xdr_longlong_t);
- if (!xdr_int64_t (&xdr_, &v))
+ if (!f (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<long long> (v);
}
inline void ixdrstream::
operator>> (unsigned long long& x)
{
- uint64_t v;
+ ixdr_u_longlong_p f =
+ reinterpret_cast<ixdr_u_longlong_p> (::xdr_u_longlong_t);
- if (!xdr_uint64_t (&xdr_, &v))
+ if (!f (&xdr_, &x))
throw xdr_exception ();
-
- x = static_cast<unsigned long long> (v);
}
#endif
@@ -152,9 +136,9 @@ namespace xsde
{
// Assume size is 32-bit.
//
- uint32_t v;
+ unsigned int v;
- if (!xdr_uint32_t (&xdr_, &v))
+ if (!xdr_u_int (&xdr_, &v))
throw xdr_exception ();
x.s_ = static_cast<size_t> (v);
@@ -201,9 +185,9 @@ namespace xsde
inline bool ixdrstream::
operator>> (signed char& x)
{
- int8_t v;
+ char v;
- if (!xdr_int8_t (&xdr_, &v))
+ if (!xdr_char (&xdr_, &v))
return false;
x = static_cast<signed char> (v);
@@ -214,69 +198,39 @@ namespace xsde
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;
+ return xdr_u_char (&xdr_, &x);
}
inline bool ixdrstream::
operator>> (short& x)
{
- int16_t v;
-
- if (!xdr_int16_t (&xdr_, &v))
- return false;
-
- x = static_cast<short> (v);
- return true;
+ return xdr_short (&xdr_, &x);
}
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;
+ return xdr_u_short (&xdr_, &x);
}
inline bool ixdrstream::
operator>> (int& x)
{
- int32_t v;
-
- if (!xdr_int32_t (&xdr_, &v))
- return false;
-
- x = static_cast<int> (v);
- return true;
+ return xdr_int (&xdr_, &x);
}
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;
+ return xdr_u_int (&xdr_, &x);
}
inline bool ixdrstream::
operator>> (long& x)
{
- int32_t v;
+ int v;
- if (!xdr_int32_t (&xdr_, &v))
+ if (!xdr_int (&xdr_, &v))
return false;
x = static_cast<long> (v);
@@ -286,9 +240,9 @@ namespace xsde
inline bool ixdrstream::
operator>> (unsigned long& x)
{
- uint32_t v;
+ unsigned int v;
- if (!xdr_uint32_t (&xdr_, &v))
+ if (!xdr_u_int (&xdr_, &v))
return false;
x = static_cast<unsigned long> (v);
@@ -299,25 +253,19 @@ namespace xsde
inline bool ixdrstream::
operator>> (long long& x)
{
- int64_t v;
-
- if (!xdr_int64_t (&xdr_, &v))
- return false;
+ ixdr_longlong_p f =
+ reinterpret_cast<ixdr_longlong_p> (::xdr_longlong_t);
- x = static_cast<long long> (v);
- return true;
+ return f (&xdr_, &x);
}
inline bool ixdrstream::
operator>> (unsigned long long& x)
{
- uint64_t v;
+ ixdr_u_longlong_p f =
+ reinterpret_cast<ixdr_u_longlong_p> (::xdr_u_longlong_t);
- if (!xdr_uint64_t (&xdr_, &v))
- return false;
-
- x = static_cast<unsigned long long> (v);
- return true;
+ return f (&xdr_, &x);
}
#endif
@@ -326,9 +274,9 @@ namespace xsde
{
// Assume size is 32-bit.
//
- uint32_t v;
+ unsigned int v;
- if (!xdr_uint32_t (&xdr_, &v))
+ if (!xdr_u_int (&xdr_, &v))
return false;
x.s_ = static_cast<size_t> (v);