Fresco/Prague/include/Prague/Filter bzbuf.hh,1.4,1.5 cbuf.hh,1.3,1.4 console.hh,1.2,1.3 cstream.hh,1.2,1.3 gzbuf.hh,1.4,1.5 gzstream.hh,1.7,1.8 xdrbuf.hh,1.4,1.5 xdrstream.hh,1.3,1.4
Tobias Hunger <[email protected]> Fri, 31 Oct 2003 22:33:43 +0000
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Prague/include/Prague/Filter In directory purcel:/tmp/cvs-serv28781/Prague/include/Prague/Filter Modified Files: bzbuf.hh cbuf.hh console.hh cstream.hh gzbuf.hh gzstream.hh xdrbuf.hh xdrstream.hh Log Message: Fix up indention according to the coding style guide. Index: bzbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/bzbuf.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- bzbuf.hh 15 Jul 2003 03:50:43 -0000 1.4 +++ bzbuf.hh 31 Oct 2003 22:33:09 -0000 1.5 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -24,7 +24,7 @@ #include <streambuf> #include <cstdio> -extern "C" +extern "C" { #include <bzlib.h> } @@ -32,34 +32,34 @@ namespace Prague { -/* @Class {bzbuf : public streambuf} - * - * @Description {filter using bzip2 library} - */ -class bzbuf : public std::streambuf, private bz_stream -{ -public: - typedef char char_type; - typedef std::streampos pos_type; - typedef std::streamoff off_type; - typedef int int_type; - bzbuf(std::streambuf *, int); - virtual ~bzbuf(); - virtual int sync(); -protected: - virtual int_type underflow(); - virtual int_type uflow(); - virtual int_type overflow(int = EOF); - char_type *cbase() const { return my_comp;} - char_type *ecptr() const { return my_comp + BUFSIZ;} - char_type *cin() const { return next_in + avail_in;} - char_type *cout() const { return my_pout;} -private: - char_type *my_comp; - char_type *my_pout; - std::streambuf *my_back; -}; + //. @Class {bzbuf : public streambuf} + //. + //. @Description {filter using bzip2 library} + class bzbuf : public std::streambuf, private bz_stream + { + public: + typedef char char_type; + typedef std::streampos pos_type; + typedef std::streamoff off_type; + typedef int int_type; -}; + bzbuf(std::streambuf *, int); + virtual ~bzbuf(); + virtual int sync(); + protected: + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type overflow(int = EOF); + char_type *cbase() const { return my_comp; } + char_type *ecptr() const { return my_comp + BUFSIZ; } + char_type *cin() const { return next_in + avail_in; } + char_type *cout() const { return my_pout; } + private: + char_type *my_comp; + char_type *my_pout; + std::streambuf *my_back; + }; + +} // namespace #endif /* _bzbuf_h */ Index: cbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/cbuf.hh,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- cbuf.hh 15 Jul 2003 03:50:43 -0000 1.3 +++ cbuf.hh 31 Oct 2003 22:33:09 -0000 1.4 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -18,50 +18,49 @@ * License along with this library; if not, write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, * MA 02139, USA. - -P*/ -/* $Id$ */ + */ #ifndef _cbuf_hh #define _cbuf_hh #include <streambuf> -/* @Class {cbuf : public streambuf} - * - * @Description {suppress comments from input} - */ +//. @Class {cbuf : public streambuf} +//. +//. @Description {suppress comments from input} class cbuf: public std::streambuf { -public: - cbuf(std::streambuf *sb, char c = '#') : my_sbuf(sb), my_comment(c), my_newline(true) {} -protected: - int sync() { return my_sbuf->sync();} - inline int uflow(); - int sungetc() { return my_sbuf->sungetc();} -private: - cbuf(cbuf const &); - void operator= (cbuf const &); - std::streambuf *my_sbuf; - const char my_comment; - bool my_newline; + public: + cbuf(std::streambuf *sb, char c = '#') : my_sbuf(sb), my_comment(c), my_newline(true) { } + protected: + int sync() { return my_sbuf->sync(); } + inline int uflow(); + int sungetc() { return my_sbuf->sungetc(); } + private: + cbuf(cbuf const &); + void operator= (cbuf const &); + std::streambuf *my_sbuf; + const char my_comment; + bool my_newline; }; inline int cbuf::uflow() { - int c = my_sbuf->sbumpc(); - if (c == '\n') my_newline = true; - else if (c == my_comment) + int c = my_sbuf->sbumpc(); + if (c == '\n') my_newline = true; + else if (c == my_comment) { - do // for all lines starting with <comment> - { - do c = my_sbuf->sbumpc(); - while (c != EOF && c != '\n'); // for all letters of the line - if (my_newline && c == '\n') c = my_sbuf->sbumpc(); - } - while (c == my_comment); - if (c == '\n') my_newline = true; + do // for all lines starting with <comment> + { + do + c = my_sbuf->sbumpc(); + while (c != EOF && c != '\n'); // for all letters of the line + if (my_newline && c == '\n') c = my_sbuf->sbumpc(); + } + while (c == my_comment); + if (c == '\n') my_newline = true; } - else my_newline = false; - return c; + else my_newline = false; + return c; } #endif Index: console.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/console.hh,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- console.hh 25 Mar 2002 15:34:16 -0000 1.2 +++ console.hh 31 Oct 2003 22:33:09 -0000 1.3 @@ -1,10 +1,8 @@ -/*+P - * This file is part of OffiX, - * a C++ API for the X Window System and Unix +/* + * This file is part Fresco (http://www.fresco.org/) * Copyright (C) 1995-98 Stefan Seefeld * * this code is based on binio from Dietmar Kuehl: - * * Copyright (C) 1996 Dietmar Kuehl * Universitaet Konstanz, Lehrstuhl fuer praktische Informatik I * @@ -22,32 +20,35 @@ * License along with this library; if not, write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, * MA 02139, USA. - -P*/ -/* $Id$ */ + */ #ifndef _console_h #define _console_h #include <fstream.h> -/* @Class{console : public ofstream} - * - * @Description{console redirection} - */ -class console : public ofstream +namespace Prague { -public: - enum type {cout = 0x1, cerr = 0x2}; - console(unsigned short t, const string &filename) - { - ofstream out(filename); - if (!out) std::cerr << "console::console: couldn't open " << filename - << " for write" << std::endl; - else - { - if (t & console::cerr) ::cerr.rdbuf(out.rdbuf()); - if (t & console::cout) ::cout.rdbuf(out.rdbuf()); - } - }; -}; + + //. @Class{console : public ofstream} + //. + //. @Description{console redirection} + class console : public ofstream + { + public: + enum type {cout = 0x1, cerr = 0x2}; + console(unsigned short t, const string &filename) + { + ofstream out(filename); + if (!out) std::cerr << "console::console: couldn't open " << filename + << " for write" << std::endl; + else + { + if (t & console::cerr) ::cerr.rdbuf(out.rdbuf()); + if (t & console::cout) ::cout.rdbuf(out.rdbuf()); + } + } + }; + +} // namespace #endif /* _console_h */ Index: cstream.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/cstream.hh,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- cstream.hh 31 Aug 2000 18:52:32 -0000 1.2 +++ cstream.hh 31 Oct 2003 22:33:09 -0000 1.3 @@ -1,19 +1,43 @@ -/* $Id$ */ +/*$Id: + * + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + */ #ifndef _cstream_hh #define _cstream_hh #include <iostream> #include <Prague/Filter/cbuf.hh> -/* - * Class name : cstream - * - * Description : a specialized istream for input containing comments... - */ -class cstream : public istream +namespace Prague { -public: - cstream(istream &is, char comment = '#') : istream(new cbuf(is.rdbuf(), comment)) {} -}; + //. Class name : cstream + //. + //. Description : a specialized istream for input containing comments... + class cstream : public istream + { + public: + cstream(istream &is, char comment = '#') : + istream(new cbuf(is.rdbuf(), comment)) + { } + }; + +} // namespace #endif Index: gzbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/gzbuf.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- gzbuf.hh 27 Mar 2001 05:38:42 -0000 1.4 +++ gzbuf.hh 31 Oct 2003 22:33:09 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,46 +28,31 @@ namespace Prague { -class gzbuf : public std::streambuf -{ -public: - gzbuf(); - virtual ~gzbuf(); - gzbuf *open(const char *, int); - gzbuf *attach(int, int); - gzbuf *close(); - int setcompressionlevel(short); - int setcompressionstrategy(short); - int is_open() const {return _file != 0;} - virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, int); - virtual int sync(); -protected: - virtual int underflow(); - virtual int overflow(int = EOF); -private: - int flushbuf(); - int fillbuf(); - gzFile _file; - int _mode; - bool _owner; - char *_buf; -}; + class gzbuf : public std::streambuf + { + public: + gzbuf(); + virtual ~gzbuf(); + gzbuf *open(const char *, int); + gzbuf *attach(int, int); + gzbuf *close(); + int setcompressionlevel(short); + int setcompressionstrategy(short); + int is_open() const {return _file != 0;} + virtual std::streampos seekoff(std::streamoff, std::ios::seekdir, int); + virtual int sync(); + protected: + virtual int underflow(); + virtual int overflow(int = EOF); + private: + int flushbuf(); + int fillbuf(); + gzFile _file; + int _mode; + bool _owner; + char *_buf; + }; -}; +} // namespace #endif /* _gzbuf_h */ - - - - - - - - - - - - - - - Index: gzstream.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/gzstream.hh,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- gzstream.hh 27 Mar 2001 05:38:42 -0000 1.7 +++ gzstream.hh 31 Oct 2003 22:33:09 -0000 1.8 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,72 +28,107 @@ namespace Prague { -class gzifstream : public std::istream -{ -public: - gzifstream() : std::istream(new gzbuf()) {} - gzifstream(const char *name, int mode = std::ios::in) : std::istream(new gzbuf()) { open(name, mode);} - gzifstream(int fd, int mode = std::ios::in) : std::istream(new gzbuf()) { attach(fd, mode);} - virtual ~gzifstream() { delete rdbuf();} - gzbuf *rdbuf() { return static_cast<gzbuf *>(std::istream::rdbuf());} - void attach(int fd, int mode) { if (!gzifstream::rdbuf()->attach(fd, mode)) clear(std::ios::failbit|std::ios::badbit); else clear();} - void open(const char *name, int mode) { if (!gzifstream::rdbuf()->open(name, mode)) clear(std::ios::failbit|std::ios::badbit); else clear();} - void close() { if (!rdbuf()->close()) clear(std::ios::failbit | std::ios::badbit);} -}; + class gzifstream : public std::istream + { + public: + gzifstream() : std::istream(new gzbuf()) { } + gzifstream(const char *name, int mode = std::ios::in) : + std::istream(new gzbuf()) + { open(name, mode); } + gzifstream(int fd, int mode = std::ios::in) : + std::istream(new gzbuf()) + { attach(fd, mode); } + virtual ~gzifstream() { delete rdbuf(); } + gzbuf *rdbuf() { return static_cast<gzbuf *>(std::istream::rdbuf()); } + void attach(int fd, int mode) + { + if (!gzifstream::rdbuf()->attach(fd, mode)) + clear(std::ios::failbit|std::ios::badbit); + else clear(); + } + void open(const char *name, int mode) + { + if (!gzifstream::rdbuf()->open(name, mode)) + clear(std::ios::failbit|std::ios::badbit); + else clear(); + } + void close() + { if (!rdbuf()->close()) clear(std::ios::failbit | std::ios::badbit); } + }; -class gzofstream : public std::ostream -{ - friend gzofstream &set_compressionlevel(gzofstream &, int); - friend gzofstream &set_compressionstrategy(gzofstream &, int); -public: - gzofstream() : std::ostream(new gzbuf()) {} - gzofstream(const char *name, int mode = std::ios::out) : std::ostream(new gzbuf()) { open(name, mode);} - gzofstream(int fd, int mode = std::ios::out) : std::ostream(new gzbuf()) { attach(fd, mode);} - virtual ~gzofstream() { delete rdbuf();} - gzbuf *rdbuf() { return static_cast<gzbuf *>(std::ostream::rdbuf());} - void attach(int fd, int mode) { if (!gzofstream::rdbuf()->attach(fd, mode)) clear(std::ios::failbit|std::ios::badbit); else clear();} - void open(const char *name, int mode) { if (!gzofstream::rdbuf()->open(name, mode)) clear(std::ios::failbit|std::ios::badbit); else clear();} - void close() { if (!rdbuf()->close()) clear(std::ios::failbit | std::ios::badbit);} -}; + class gzofstream : public std::ostream + { + friend gzofstream &set_compressionlevel(gzofstream &, int); + friend gzofstream &set_compressionstrategy(gzofstream &, int); + public: + gzofstream() : std::ostream(new gzbuf()) { } + gzofstream(const char *name, int mode = std::ios::out) : + std::ostream(new gzbuf()) + { open(name, mode); } + gzofstream(int fd, int mode = std::ios::out) : + std::ostream(new gzbuf()) + { attach(fd, mode); } + virtual ~gzofstream() { delete rdbuf(); } + gzbuf *rdbuf() { return static_cast<gzbuf *>(std::ostream::rdbuf()); } + void attach(int fd, int mode) + { + if (!gzofstream::rdbuf()->attach(fd, mode)) + clear(std::ios::failbit|std::ios::badbit); + else clear(); + } + void open(const char *name, int mode) + { + if (!gzofstream::rdbuf()->open(name, mode)) + clear(std::ios::failbit|std::ios::badbit); + else clear(); + } + void close() + { + if (!rdbuf()->close()) + clear(std::ios::failbit | std::ios::badbit); + } + }; -template<class T> class gzomanip -{ - friend gzofstream &operator << <>(gzofstream &, const gzomanip<T> &); -public: - gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { } -private: - gzofstream &(*func)(gzofstream &, T); - T val; -}; + template<class T> class gzomanip + { + friend gzofstream &operator << <>(gzofstream &, const gzomanip<T> &); + public: + gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : + func(f), val(v) + { } + private: + gzofstream &(*func)(gzofstream &, T); + T val; + }; -template<class T> gzofstream &operator << (gzofstream &s, const gzomanip<T> &m) -{ - return (*m.func)(s, m.val); -} + template<class T> gzofstream &operator << (gzofstream &s, const gzomanip<T> &m) + { + return (*m.func)(s, m.val); + } -inline gzofstream &set_compressionlevel(gzofstream &s, int l) -{ - (s.rdbuf())->setcompressionlevel(l); - return s; -} + inline gzofstream &set_compressionlevel(gzofstream &s, int l) + { + (s.rdbuf())->setcompressionlevel(l); + return s; + } -inline gzofstream &set_compressionstrategy(gzofstream &s, int l) -{ - (s.rdbuf())->setcompressionstrategy(l); - return s; -} + inline gzofstream &set_compressionstrategy(gzofstream &s, int l) + { + (s.rdbuf())->setcompressionstrategy(l); + return s; + } -inline gzomanip<int> set_compressionlevel(int l) -{ - return gzomanip<int>(&set_compressionlevel,l); -} + inline gzomanip<int> set_compressionlevel(int l) + { + return gzomanip<int>(&set_compressionlevel,l); + } -inline gzomanip<int> set_compressionstrategy(int l) -{ - return gzomanip<int>(&set_compressionstrategy,l); -} + inline gzomanip<int> set_compressionstrategy(int l) + { + return gzomanip<int>(&set_compressionstrategy,l); + } -}; +} // namespace #endif /* _gzstream_hh */ Index: xdrbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/xdrbuf.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- xdrbuf.hh 15 Jul 2003 03:50:43 -0000 1.4 +++ xdrbuf.hh 31 Oct 2003 22:33:09 -0000 1.5 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.fresco.org * * this code is based on binio from Dietmar Kuehl: @@ -34,8 +34,8 @@ namespace Prague { -extern void xdrbuf_create(XDR *xdrs, std::streambuf *sb, xdr_op op); -extern void xdrbuf_reseat(XDR *xdrs, std::streambuf *sb); + extern void xdrbuf_create(XDR *xdrs, std::streambuf *sb, xdr_op op); + extern void xdrbuf_reseat(XDR *xdrs, std::streambuf *sb); }; Index: xdrstream.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/Filter/xdrstream.hh,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- xdrstream.hh 23 Sep 2000 19:15:47 -0000 1.3 +++ xdrstream.hh 31 Oct 2003 22:33:09 -0000 1.4 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * this code is based on binio from Dietmar Kuehl: * @@ -35,173 +35,284 @@ namespace Prague { -/* @Class{xdrios} - * - * @Description{ios for xdr encoding and decoding} - */ -class xdrios -{ -public: - enum operation { encode, decode}; - inline xdrios(streambuf *, operation); - virtual ~xdrios() { xdr_destroy(xdrs); operator delete(xdrs);} - streambuf *rdbuf() const { return sbuf; } - void rdbuf(streambuf *sb) { sbuf = sb; xdrbuf_reseat(xdrs, sb);} - operator bool () const { return state == TRUE;} + //. @Class{xdrios} + //. + //. @Description{ios for xdr encoding and decoding} - // I decided that it makes not much sense to have this stream - // 'protected'. It may be useful to directly encode data-types using - // the XDR stream. - XDR *xdrstream() { return xdrs;} + class xdrios + { + public: + enum operation { encode, decode}; + inline xdrios(streambuf *, operation); + virtual ~xdrios() { xdr_destroy(xdrs); operator delete(xdrs); } + streambuf *rdbuf() const { return sbuf; } + void rdbuf(streambuf *sb) { sbuf = sb; xdrbuf_reseat(xdrs, sb); } + operator bool () const { return state == TRUE; } - size_t width() const { return len;} - size_t width(size_t s){ size_t rc = len; len = s; return rc;} -protected: - bool_t state; -private: - xdrios(xdrios const &); // copying is not supported - xdrios &operator = (xdrios const &); // assignment is not supported - streambuf *sbuf; - XDR *xdrs; - size_t len; // used by the extractor for 'char*' similar to - // 'width' of 'ios', hence the naming of the - // corresponding functions below -}; + // I decided that it makes not much sense to have this stream + // 'protected'. It may be useful to directly encode data-types using + // the XDR stream. + XDR *xdrstream() { return xdrs; } -/* @Class{oxdrstream : public xdrios} - * - * @Description{XDR encoder using stream notation} - */ -class oxdrstream : public xdrios -{ -private: - oxdrstream(oxdrstream const &); // copying is not supported - oxdrstream &operator = (oxdrstream const &); // assignment is not supported + size_t width() const { return len; } + size_t width(size_t s){ size_t rc = len; len = s; return rc; } + protected: + bool_t state; + private: + xdrios(xdrios const &); // copying is not supported + xdrios &operator = (xdrios const &); // assignment is not supported + streambuf *sbuf; + XDR *xdrs; + size_t len; // used by the extractor for 'char*' similar to + // 'width' of 'ios', hence the naming of the + // corresponding functions below + }; -public: - oxdrstream(streambuf *sb) : xdrios(sb, encode) {} - ~oxdrstream() {} + //. @Class{oxdrstream : public xdrios} + //. + //.@Description{XDR encoder using stream notation} + class oxdrstream : public xdrios + { + private: + oxdrstream(oxdrstream const &); // copying is not supported + oxdrstream &operator = (oxdrstream const &); // assignment is not supported - oxdrstream &operator << (bool b) { bool_t tbool = b ? TRUE : FALSE; state = state == TRUE && xdr_bool(xdrstream(), &tbool); return *this;} + public: + oxdrstream(streambuf *sb) : xdrios(sb, encode) { } + ~oxdrstream() { } - oxdrstream &operator << (char c) { state = state == TRUE && xdr_char(xdrstream(), &c); return *this;} - oxdrstream &operator << (unsigned char c) { state = state == TRUE && xdr_u_char(xdrstream(), &c); return *this;} - oxdrstream &operator << (signed char c) { state = state == TRUE && xdr_char(xdrstream(), reinterpret_cast<char *> (&c)); return *this;} + oxdrstream &operator << (bool b) + { + bool_t tbool = b ? TRUE : FALSE; + state = state == TRUE && xdr_bool(xdrstream(), &tbool); + return *this; + } - oxdrstream &operator << (double d) { state = state == TRUE && xdr_double(xdrstream(), &d); return *this;} - oxdrstream &operator << (float f) { state = state == TRUE && xdr_float(xdrstream(), &f); return *this;} + oxdrstream &operator << (char c) + { + state = state == TRUE && xdr_char(xdrstream(), &c); + return *this; + } + oxdrstream &operator << (unsigned char c) + { + state = state == TRUE && xdr_u_char(xdrstream(), &c); + return *this; + } + oxdrstream &operator << (signed char c) + { + state = state == TRUE && xdr_char(xdrstream(), reinterpret_cast<char *> (&c)); + return *this; + } - oxdrstream &operator << (int i) { state = state == TRUE && xdr_int(xdrstream(), &i); return *this;} - oxdrstream &operator << (long l) { state = state == TRUE && xdr_long(xdrstream(), &l); return *this;} - oxdrstream &operator << (short s) { state = state == TRUE && xdr_short(xdrstream(), &s); return *this;} + oxdrstream &operator << (double d) + { + state = state == TRUE && xdr_double(xdrstream(), &d); + return *this; + } + oxdrstream &operator << (float f) + { + state = state == TRUE && xdr_float(xdrstream(), &f); + return *this; + } - oxdrstream &operator << (unsigned int i) { state = state == TRUE && xdr_u_int(xdrstream(), &i); return *this;} - oxdrstream &operator << (unsigned long l) { state = state == TRUE && xdr_u_long(xdrstream(), &l); return *this;} - oxdrstream &operator << (unsigned short s) { state = state == TRUE && xdr_u_short(xdrstream(), &s); return *this;} + oxdrstream &operator << (int i) + { + state = state == TRUE && xdr_int(xdrstream(), &i); + return *this; + } + oxdrstream &operator << (long l) + { + state = state == TRUE && xdr_long(xdrstream(), &l); + return *this; + } + oxdrstream &operator << (short s) + { + state = state == TRUE && xdr_short(xdrstream(), &s); + return *this; + } - inline oxdrstream &operator << (char const *); - inline oxdrstream &operator << (const string &); -}; + oxdrstream &operator << (unsigned int i) + { + state = state == TRUE && xdr_u_int(xdrstream(), &i); + return *this; + } + oxdrstream &operator << (unsigned long l) + { + state = state == TRUE && xdr_u_long(xdrstream(), &l); + return *this; + } + oxdrstream &operator << (unsigned short s) + { + state = state == TRUE && xdr_u_short(xdrstream(), &s); + return *this; + } -/* @Class{ofxdrstream : public oxdrstream} - * - * @Description{output data in XDR format to a file} - */ -class ofxdrstream : public oxdrstream -{ -private: - ofxdrstream(ofxdrstream const &); // copying is not supported - ofxdrstream &operator = (ofxdrstream const &); // assignment is not supported -public: - ofxdrstream(char const *fname) : oxdrstream((new filebuf())->open(fname, ios::out|ios::binary)) {} - ~ofxdrstream() { filebuf *fb = static_cast<filebuf *> (rdbuf()); rdbuf(0); delete fb;} -}; + inline oxdrstream &operator << (char const *); + inline oxdrstream &operator << (const string &); + }; -/* @Class{ixdrstream : public xdrios} - * - * @Description{XDR decoder using stream notation} - */ -class ixdrstream : public xdrios -{ -private: - ixdrstream(ixdrstream const &); // copying is not supported - ixdrstream &operator = (ixdrstream const &); // assignment is not supported + //.@Class{ofxdrstream : public oxdrstream} + //. + //. @Description{output data in XDR format to a file} + class ofxdrstream : public oxdrstream + { + private: + ofxdrstream(ofxdrstream const &); // copying is not supported + ofxdrstream &operator = (ofxdrstream const &); // assignment is not supported + public: + ofxdrstream(char const *fname) : + oxdrstream((new filebuf())->open(fname, ios::out|ios::binary)) + { } + ~ofxdrstream() + { + filebuf *fb = static_cast<filebuf *> (rdbuf()); + rdbuf(0); + delete fb; + } + }; -public: - ixdrstream(streambuf *sb) : xdrios(sb, decode) {} - ~ixdrstream() {} + //. @Class{ixdrstream : public xdrios} + //. + //. @Description{XDR decoder using stream notation} + class ixdrstream : public xdrios + { + private: + ixdrstream(ixdrstream const &); // copying is not supported + ixdrstream &operator = (ixdrstream const &); // assignment is not supported + public: + ixdrstream(streambuf *sb) : xdrios(sb, decode) { } + ~ixdrstream() { } - ixdrstream &operator >> (bool &b) { bool_t tbool; state = state == TRUE && xdr_bool(xdrstream(), &tbool); b = tbool == TRUE ? true : false; return *this;} + ixdrstream &operator >> (bool &b) + { + bool_t tbool; + state = state == TRUE && xdr_bool(xdrstream(), &tbool); + b = tbool == TRUE ? true : false; + return *this; + } - ixdrstream &operator >> (char &c) { state = state == TRUE && xdr_char(xdrstream(), &c); return *this;} - ixdrstream &operator >> (unsigned char &c) { state = state == TRUE && xdr_u_char(xdrstream(), &c); return *this;} - ixdrstream &operator >> (signed char &c) { state = state == TRUE && xdr_char(xdrstream(), reinterpret_cast<char *> (&c)); return *this; } + ixdrstream &operator >> (char &c) + { + state = state == TRUE && xdr_char(xdrstream(), &c); + return *this; + } + ixdrstream &operator >> (unsigned char &c) + { + state = state == TRUE && xdr_u_char(xdrstream(), &c); + return *this; + } + ixdrstream &operator >> (signed char &c) + { + state = state == TRUE && xdr_char(xdrstream(), reinterpret_cast<char *> (&c)); + return *this; + } - ixdrstream &operator >> (double &d) { state = state == TRUE && xdr_double(xdrstream(), &d); return *this; } - ixdrstream &operator >> (float &f) { state = state == TRUE && xdr_float(xdrstream(), &f); return *this; } + ixdrstream &operator >> (double &d) + { + state = state == TRUE && xdr_double(xdrstream(), &d); + return *this; + } + ixdrstream &operator >> (float &f) + { + state = state == TRUE && xdr_float(xdrstream(), &f); + return *this; + } - ixdrstream &operator >> (int &i) { state = state == TRUE && xdr_int(xdrstream(), &i); return *this; } - ixdrstream &operator >> (long &l) { state = state == TRUE && xdr_long(xdrstream(), &l); return *this; } - ixdrstream &operator >> (short &s) { state = state == TRUE && xdr_short(xdrstream(), &s); return *this; } + ixdrstream &operator >> (int &i) + { + state = state == TRUE && xdr_int(xdrstream(), &i); + return *this; + } + ixdrstream &operator >> (long &l) + { + state = state == TRUE && xdr_long(xdrstream(), &l); + return *this; + } + ixdrstream &operator >> (short &s) + { + state = state == TRUE && xdr_short(xdrstream(), &s); + return *this; + } - ixdrstream &operator >> (unsigned int &i) { state = state == TRUE && xdr_u_int(xdrstream(), &i); return *this; } - ixdrstream &operator >> (unsigned long &l) { state = state == TRUE && xdr_u_long(xdrstream(), &l); return *this; } - ixdrstream &operator >> (unsigned short &s) { state = state == TRUE && xdr_u_short(xdrstream(), &s); return *this; } + ixdrstream &operator >> (unsigned int &i) + { + state = state == TRUE && xdr_u_int(xdrstream(), &i); + return *this; + } + ixdrstream &operator >> (unsigned long &l) + { + state = state == TRUE && xdr_u_long(xdrstream(), &l); + return *this; + } + ixdrstream &operator >> (unsigned short &s) + { + state = state == TRUE && xdr_u_short(xdrstream(), &s); + return *this; + } - inline ixdrstream &operator >> (char *); - inline ixdrstream &operator >> (string &); -}; - -/* @Class{ifxdrstream : public ixdrstream} - * - * @Description{input data in XDR format from a file} - */ -class ifxdrstream : public ixdrstream -{ -private: - ifxdrstream(ifxdrstream const &); // copying is not supported - ifxdrstream &operator = (ifxdrstream const &); // assignment is not supported -public: - ifxdrstream(char const *fname) : ixdrstream((new filebuf())->open(fname, ios::in|ios::binary)) {} - ~ifxdrstream() { filebuf *fb = static_cast<filebuf *> (rdbuf()); rdbuf(0); delete fb;} -}; + inline ixdrstream &operator >> (char *); + inline ixdrstream &operator >> (string &); + }; -inline xdrios::xdrios(streambuf *sb, xdrios::operation op) - : state(TRUE), sbuf(sb), xdrs(static_cast<XDR *> (operator new(sizeof(XDR)))), len(0) -{ - xdrbuf_create(xdrs, sb, op == encode? XDR_ENCODE: XDR_DECODE); -} + //. @Class{ifxdrstream : public ixdrstream} + //. + //. @Description{input data in XDR format from a file} + class ifxdrstream : public ixdrstream + { + private: + ifxdrstream(ifxdrstream const &); // copying is not supported + ifxdrstream &operator = (ifxdrstream const &); // assignment is not supported + public: + ifxdrstream(char const *fname) : + ixdrstream((new filebuf())->open(fname, ios::in|ios::binary)) + { } + ~ifxdrstream() + { + filebuf *fb = static_cast<filebuf *> (rdbuf()); + rdbuf(0); + delete fb; + } + }; -inline oxdrstream &oxdrstream::operator << (char const *str) -{ - unsigned int len = strlen(str) + 1; // save the termination character, too - state = state == TRUE && xdr_bytes(xdrstream(), const_cast<char **> (&str), &len, len); - return *this; -} + inline xdrios::xdrios(streambuf *sb, xdrios::operation op) : + state(TRUE), + sbuf(sb), + xdrs(static_cast<XDR *>(operator new(sizeof(XDR)))), + len(0) + { + xdrbuf_create(xdrs, sb, op == encode? XDR_ENCODE: XDR_DECODE); + } -inline oxdrstream &oxdrstream::operator << (const string &str) -{ - return *this << str.c_str(); -} + inline oxdrstream &oxdrstream::operator << (char const *str) + { + unsigned int len = strlen(str) + 1; // save the termination character, too + state = state == TRUE && xdr_bytes(xdrstream(), const_cast<char **> (&str), &len, len); + return *this; + } -inline ixdrstream &ixdrstream::operator >> (char *str) -{ - assert(width() != 0); - size_t len = width(); - state = state == TRUE && xdr_bytes(xdrstream(), &str, &len, len); - return *this; -} + inline oxdrstream &oxdrstream::operator << (const string &str) + { + return *this << str.c_str(); + } -inline ixdrstream &ixdrstream::operator >> (string &str) -{ - size_t len = width(); - char *buf = new char [len]; - state = state == TRUE && xdr_bytes(xdrstream(), &buf, &len, len); - str = buf; - delete [] buf; - return *this; -} + inline ixdrstream &ixdrstream::operator >> (char *str) + { + assert(width() != 0); + size_t len = width(); + state = state == TRUE && xdr_bytes(xdrstream(), &str, &len, len); + return *this; + } -}; + inline ixdrstream &ixdrstream::operator >> (string &str) + { + size_t len = width(); + char *buf = new char [len]; + state = state == TRUE && xdr_bytes(xdrstream(), &buf, &len, len); + str = buf; + delete [] buf; + return *this; + } + +} // namespace #endif /* xdrstream_hh */