From bb3143a129b91e6442a14ec1a6b05ff62c5d8b55 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 13 Apr 2009 21:05:41 +0200 Subject: Rework XDR code to be more portable Also don't link to libnsl by default since not all platforms have it. --- libxsde/xsde/cxx/hybrid/xdr/ostream.ixx | 96 ++++++++++++++++----------------- 1 file changed, 46 insertions(+), 50 deletions(-) (limited to 'libxsde/xsde/cxx/hybrid/xdr/ostream.ixx') diff --git a/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx b/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx index 64c8a26..c6b9c0f 100644 --- a/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx +++ b/libxsde/xsde/cxx/hybrid/xdr/ostream.ixx @@ -9,6 +9,12 @@ namespace xsde { namespace hybrid { + extern "C" + typedef bool_t (*oxdr_longlong_p) (XDR*, long long*); + + extern "C" + typedef bool_t (*oxdr_u_longlong_p) (XDR*, unsigned long long*); + inline oxdrstream:: oxdrstream (XDR& xdr) : xdr_ (xdr) @@ -35,9 +41,9 @@ namespace xsde inline void oxdrstream:: operator<< (signed char x) { - int8_t v = static_cast (x); + char v = static_cast (x); - if (!xdr_int8_t (&xdr_, &v)) + if (!xdr_char (&xdr_, &v)) throw xdr_exception (); } @@ -45,63 +51,53 @@ namespace xsde inline void oxdrstream:: operator<< (unsigned char x) { - uint8_t v = static_cast (x); - - if (!xdr_uint8_t (&xdr_, &v)) + if (!xdr_u_char (&xdr_, &x)) throw xdr_exception (); } inline void oxdrstream:: operator<< (short x) { - int16_t v = static_cast (x); - - if (!xdr_int16_t (&xdr_, &v)) + if (!xdr_short (&xdr_, &x)) throw xdr_exception (); } inline void oxdrstream:: operator<< (unsigned short x) { - uint16_t v = static_cast (x); - - if (!xdr_uint16_t (&xdr_, &v)) + if (!xdr_u_short (&xdr_, &x)) throw xdr_exception (); } inline void oxdrstream:: operator<< (int x) { - int32_t v = static_cast (x); - - if (!xdr_int32_t (&xdr_, &v)) + if (!xdr_int (&xdr_, &x)) throw xdr_exception (); } inline void oxdrstream:: operator<< (unsigned int x) { - uint32_t v = static_cast (x); - - if (!xdr_uint32_t (&xdr_, &v)) + if (!xdr_u_int (&xdr_, &x)) throw xdr_exception (); } inline void oxdrstream:: operator<< (long x) { - int32_t v = static_cast (x); + int v = static_cast (x); - if (!xdr_int32_t (&xdr_, &v)) + if (!xdr_int (&xdr_, &v)) throw xdr_exception (); } inline void oxdrstream:: operator<< (unsigned long x) { - uint32_t v = static_cast (x); + unsigned int v = static_cast (x); - if (!xdr_uint32_t (&xdr_, &v)) + if (!xdr_u_int (&xdr_, &v)) throw xdr_exception (); } @@ -109,18 +105,20 @@ namespace xsde inline void oxdrstream:: operator<< (long long x) { - int64_t v = static_cast (x); + oxdr_longlong_p f = + reinterpret_cast (::xdr_longlong_t); - if (!xdr_int64_t (&xdr_, &v)) + if (!f (&xdr_, &x)) throw xdr_exception (); } inline void oxdrstream:: operator<< (unsigned long long x) { - uint64_t v = static_cast (x); + oxdr_u_longlong_p f = + reinterpret_cast (::xdr_u_longlong_t); - if (!xdr_uint64_t (&xdr_, &v)) + if (!f (&xdr_, &x)) throw xdr_exception (); } #endif @@ -130,9 +128,9 @@ namespace xsde { // Assume size is 32-bit. // - uint32_t v = static_cast (x.s_); + unsigned int v = static_cast (x.s_); - if (!xdr_uint32_t (&xdr_, &v)) + if (!xdr_u_int (&xdr_, &v)) throw xdr_exception (); } @@ -172,73 +170,71 @@ namespace xsde inline bool oxdrstream:: operator<< (signed char x) { - int8_t v = static_cast (x); - return xdr_int8_t (&xdr_, &v); + char v = static_cast (x); + return xdr_char (&xdr_, &v); } - inline bool oxdrstream:: operator<< (unsigned char x) { - uint8_t v = static_cast (x); - return xdr_uint8_t (&xdr_, &v); + return xdr_u_char (&xdr_, &x); } inline bool oxdrstream:: operator<< (short x) { - int16_t v = static_cast (x); - return xdr_int16_t (&xdr_, &v); + return xdr_short (&xdr_, &x); } inline bool oxdrstream:: operator<< (unsigned short x) { - uint16_t v = static_cast (x); - return xdr_uint16_t (&xdr_, &v); + return xdr_u_short (&xdr_, &x); } inline bool oxdrstream:: operator<< (int x) { - int32_t v = static_cast (x); - return xdr_int32_t (&xdr_, &v); + return xdr_int (&xdr_, &x); } inline bool oxdrstream:: operator<< (unsigned int x) { - uint32_t v = static_cast (x); - return xdr_uint32_t (&xdr_, &v); + return xdr_u_int (&xdr_, &x); } inline bool oxdrstream:: operator<< (long x) { - int32_t v = static_cast (x); - return xdr_int32_t (&xdr_, &v); + int v = static_cast (x); + return xdr_int (&xdr_, &v); } inline bool oxdrstream:: operator<< (unsigned long x) { - uint32_t v = static_cast (x); - return xdr_uint32_t (&xdr_, &v); + unsigned int v = static_cast (x); + return xdr_u_int (&xdr_, &v); } #ifdef XSDE_LONGLONG inline bool oxdrstream:: operator<< (long long x) { - int64_t v = static_cast (x); - return xdr_int64_t (&xdr_, &v); + oxdr_longlong_p f = + reinterpret_cast (::xdr_longlong_t); + + return f (&xdr_, &x); } inline bool oxdrstream:: operator<< (unsigned long long x) { - uint64_t v = static_cast (x); - return xdr_uint64_t (&xdr_, &v); + oxdr_u_longlong_p f = + reinterpret_cast (::xdr_u_longlong_t); + + return f (&xdr_, &x); } #endif @@ -247,8 +243,8 @@ namespace xsde { // Assume size is 32-bit. // - uint32_t v = static_cast (x.s_); - return xdr_uint32_t (&xdr_, &v); + unsigned int v = static_cast (x.s_); + return xdr_u_int (&xdr_, &v); } inline bool oxdrstream:: -- cgit v1.1