23#if !defined(LOOS_XDR_HPP)
31#include <loos_defs.hpp>
56 XDRReader(std::istream* s) : stream(s), need_to_swab(false) {
58 if (*(
reinterpret_cast<char*
>(&test)) == 0x34) {
64 std::istream*
get(
void) {
return(stream); }
67 template<
typename T> uint
read(T* p) {
72 stream->read(
reinterpret_cast<char*
>(&result),
sizeof(
block_type));
73 if (
sizeof(T) > 1 && need_to_swab)
74 result =
swab(result);
77 return(!stream->fail());
84 stream->read(
reinterpret_cast<char*
>(&result),
sizeof(
double));
86 result =
swab(result);
89 return(!stream->fail());
93 template<
typename T> uint
read(T& t) {
return(
read(&t)); }
98 template<
typename T> uint
read(T* ary,
const uint n) {
100 for (i=0; i<n &&
read(ary+i); ++i) ;
121 stream->read(buf, rndup);
128 uint
read(boost::shared_ptr<char>& p) {
133 char* s =
new char[n+1];
136 p = boost::shared_ptr<char>(s);
140 uint
read(std::string& s) {
141 boost::shared_ptr<char> p;
146 s = std::string(p.get());
152 std::istream* stream;
169 if (*(
reinterpret_cast<char*
>(&test)) == 0x34) {
177 if (*(
reinterpret_cast<char*
>(&test)) == 0x34) {
183 std::ostream*
get(
void) {
return(stream); }
185 void setStream(std::ostream* o) { stream = o; }
192 template<
typename T> uint
write(
const T& p) {
198 T* up =
reinterpret_cast<T*
>(&u);
201 if (
sizeof(T) > 1 && need_to_swab)
205 stream->write(
reinterpret_cast<char*
>(&u),
sizeof(
block_type));
207 return(!(stream->bad()));
217 double* up =
reinterpret_cast<double*
>(&u);
223 stream->write(
reinterpret_cast<char*
>(&u),
sizeof(
double));
225 return(!stream->fail());
230 template<
typename T> uint
write(
const T* ary,
const uint n) {
232 for (i=0; i<n &&
write(ary[i]); ++i) ;
237 uint
write(
const char* p,
const uint n) {
240 static bool init(
false);
252 stream->write(buf, rndup);
254 return(stream->fail() ? 0 : n);
264 uint
write(
const std::string& s) {
return(
write(s.c_str())); }
267 std::ostream* stream;
This class provides some facility for handling XDR data.
Definition xdr.hpp:48
uint read(T *p)
Read a single datum.
Definition xdr.hpp:67
std::istream * get(void)
Returns the stored istream pointer.
Definition xdr.hpp:64
XDRReader(std::istream *s)
Constructor determines need to convert data at instantiation.
Definition xdr.hpp:56
unsigned int block_type
Type (and hence size) of the external block.
Definition xdr.hpp:51
uint read(char *p, uint n)
Read in an opaque array of n-bytes (same as xdr_opaque)
Definition xdr.hpp:106
uint read(T *ary, const uint n)
Read an n-array of data.
Definition xdr.hpp:98
uint read(boost::shared_ptr< char > &p)
Same as xdr_string.
Definition xdr.hpp:128
uint write(const char *p, const uint n)
Writes an opaque array of n-bytes.
Definition xdr.hpp:237
uint write(const T *ary, const uint n)
Writes an n-array of data.
Definition xdr.hpp:230
uint write(const double &p)
Overload for double-precision.
Definition xdr.hpp:214
unsigned int block_type
Type (and hence size) of the external block.
Definition xdr.hpp:163
uint write(const char *p)
Writes a C-string (ie xdr_string)
Definition xdr.hpp:258
XDRWriter(std::ostream *s)
Constructor determines need to convert data at instantiation.
Definition xdr.hpp:175
std::ostream * get(void)
Returns the stored istream pointer.
Definition xdr.hpp:183
uint write(const T &p)
Writes a single datum.
Definition xdr.hpp:192
Namespace for most things not already encapsulated within a class.
Definition version.cpp:3
T swab(const T &datum)
Returns a byte-swapped copy of an arbitrary type.
Definition utils.hpp:306
Exception indicating internal XDR error.
Definition exceptions.hpp:89