diff options
Diffstat (limited to 'Build/source/utils/asymptote/xstream.h')
-rw-r--r-- | Build/source/utils/asymptote/xstream.h | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/Build/source/utils/asymptote/xstream.h b/Build/source/utils/asymptote/xstream.h index 3c7c94e1158..b7947ee3e9d 100644 --- a/Build/source/utils/asymptote/xstream.h +++ b/Build/source/utils/asymptote/xstream.h @@ -27,10 +27,10 @@ #include <sys/types.h> #include <rpc/types.h> - + #define quad_t long long #define u_quad_t unsigned long long - + #if defined(__CYGWIN__) || defined(__FreeBSD__) #include <sys/select.h> #define u_char unsigned char @@ -39,12 +39,19 @@ #define u_long unsigned long extern "C" int fseeko(FILE *, off_t, int); extern "C" off_t ftello(FILE *); -#endif +#endif #ifdef __APPLE__ #include <rpc/xdr.h> -extern bool_t xdr_long(XDR *__xdrs, long *__lp); -extern bool_t xdr_u_long(XDR *__xdrs, u_long *__ulp); + +inline bool_t xdr_long(XDR *__xdrs, long *__lp) { + return xdr_longlong_t(__xdrs,(long long *) __lp); +} + +inline bool_t xdr_u_long(XDR *__xdrs, unsigned long *__lp) { + return xdr_u_longlong_t(__xdrs,(unsigned long long *) __lp); +} + #endif #ifdef _POSIX_SOURCE @@ -56,7 +63,7 @@ extern bool_t xdr_u_long(XDR *__xdrs, u_long *__ulp); #endif namespace xdr { - + class xbyte { unsigned char c; public: @@ -73,9 +80,9 @@ public: enum io_state {goodbit=0, eofbit=1, failbit=2, badbit=4}; enum open_mode {in=1, out=2, app=8, trunc=16}; enum seekdir {beg=SEEK_SET, cur=SEEK_CUR, end=SEEK_END}; -private: +private: int _state; -public: +public: int good() const { return _state == 0; } int eof() const { return _state & eofbit; } int fail() const { return !good();} @@ -94,11 +101,11 @@ public: xstream() {buf=NULL;} void precision(int) {} - + xstream& seek(off_t pos, seekdir dir=beg) { if(buf) { clear(); - if(fseeko(buf,pos,dir) != 0) set(failbit); + if(fseeko(buf,pos,dir) != 0) set(failbit); } return *this; } @@ -114,7 +121,7 @@ public: {if(!xdr_##N(&xdro, &x)) set(badbit); return *this;} class ixstream : virtual public xstream { -protected: +protected: XDR xdri; public: void open(const char *filename, open_mode=in) { @@ -123,25 +130,25 @@ public: if(buf) xdrstdio_create(&xdri,buf,XDR_DECODE); else set(badbit); } - + void close() { if(buf) { #ifndef _CRAY xdr_destroy(&xdri); -#endif +#endif fclose(buf); buf=NULL; } } - + ixstream() {} ixstream(const char *filename) {open(filename);} ixstream(const char *filename, open_mode mode) {open(filename,mode);} virtual ~ixstream() {close();} - + typedef ixstream& (*imanip)(ixstream&); ixstream& operator >> (imanip func) { return (*func)(*this); } - + IXSTREAM(int,int); IXSTREAM(unsigned int,u_int); IXSTREAM(long,long); @@ -151,12 +158,12 @@ public: IXSTREAM(short,short); IXSTREAM(unsigned short,u_short); IXSTREAM(char,char); -#ifndef _CRAY +#ifndef _CRAY IXSTREAM(unsigned char,u_char); -#endif +#endif IXSTREAM(float,float); IXSTREAM(double,double); - + ixstream& operator >> (xbyte& x) { x=fgetc(buf); if(x.byte() == EOF) set(eofbit); @@ -165,7 +172,7 @@ public: }; class oxstream : virtual public xstream { -protected: +protected: XDR xdro; public: void open(const char *filename, open_mode mode=trunc) { @@ -174,27 +181,27 @@ public: if(buf) xdrstdio_create(&xdro,buf,XDR_ENCODE); else set(badbit); } - + void close() { if(buf) { #ifndef _CRAY xdr_destroy(&xdro); -#endif +#endif fclose(buf); buf=NULL; } } - + oxstream() {} oxstream(const char *filename) {open(filename);} oxstream(const char *filename, open_mode mode) {open(filename,mode);} virtual ~oxstream() {close();} oxstream& flush() {if(buf) fflush(buf); return *this;} - + typedef oxstream& (*omanip)(oxstream&); oxstream& operator << (omanip func) { return (*func)(*this); } - + OXSTREAM(int,int); OXSTREAM(unsigned int,u_int); OXSTREAM(long,long); @@ -204,12 +211,12 @@ public: OXSTREAM(short,short); OXSTREAM(unsigned short,u_short); OXSTREAM(char,char); -#ifndef _CRAY +#ifndef _CRAY OXSTREAM(unsigned char,u_char); -#endif +#endif OXSTREAM(float,float); OXSTREAM(double,double); - + oxstream& operator << (xbyte x) { if(fputc(x.byte(),buf) == EOF) set(badbit); return *this; @@ -235,18 +242,18 @@ public: xdrstdio_create(&xdro,buf,XDR_ENCODE); } else set(badbit); } - + void close() { if(buf) { #ifndef _CRAY xdr_destroy(&xdri); xdr_destroy(&xdro); -#endif +#endif fclose(buf); buf=NULL; } } - + ioxstream() {} ioxstream(const char *filename) {open(filename);} ioxstream(const char *filename, open_mode mode) {open(filename,mode);} |