Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

/home/jeroen/FOX/fox/fox-1.7.33/include/FXStream.h
00001 /********************************************************************************
00002 *                                                                               *
00003 *       P e r s i s t e n t   S t o r a g e   S t r e a m   C l a s s e s       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2012 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXSTREAM_H
00022 #define FXSTREAM_H
00023 
00024 
00025 namespace FX {
00026 
00027 
00029 enum FXStreamDirection {
00030   FXStreamDead=0,               
00031   FXStreamSave=1,               
00032   FXStreamLoad=2                
00033   };
00034 
00035 
00037 enum FXStreamStatus {
00038   FXStreamOK=0,                 
00039   FXStreamEnd=1,                
00040   FXStreamFull=2,               
00041   FXStreamNoWrite=3,            
00042   FXStreamNoRead=4,             
00043   FXStreamFormat=5,             
00044   FXStreamUnknown=6,            
00045   FXStreamAlloc=7,              
00046   FXStreamFailure=8             
00047   };
00048 
00049 
00051 enum FXWhence {
00052   FXFromStart=0,                
00053   FXFromCurrent=1,              
00054   FXFromEnd=2                   
00055   };
00056 
00057 
00079 class FXAPI FXStream {
00080 protected:
00081   FXHash             hash;      // Hash table
00082   const FXObject    *parent;    // Parent object
00083   FXuchar           *begptr;    // Begin of buffer
00084   FXuchar           *endptr;    // End of buffer
00085   FXuchar           *wrptr;     // Write pointer
00086   FXuchar           *rdptr;     // Read pointer
00087   FXlong             pos;       // Position
00088   FXStreamDirection  dir;       // Direction of current transfer
00089   FXStreamStatus     code;      // Status code
00090   FXuint             seq;       // Sequence number
00091   FXbool             owns;      // Stream owns buffer
00092   FXbool             swap;      // Swap bytes on readin
00093 protected:
00094 
00099   virtual FXuval writeBuffer(FXuval count);
00100 
00105   virtual FXuval readBuffer(FXuval count);
00106 
00107 public:
00108 
00115   FXStream(const FXObject* cont=NULL);
00116 
00123   FXbool open(FXStreamDirection save_or_load,FXuchar* data=NULL,FXuval size=8192UL,FXbool owned=false);
00124 
00126   virtual FXbool flush();
00127 
00129   virtual FXbool close();
00130 
00132   FXuval getSpace() const;
00133 
00135   void setSpace(FXuval sp);
00136 
00138   void setOwned(FXbool owned){ owns=owned; }
00139 
00141   FXbool isOwned() const { return owns; }
00142 
00144   FXStreamStatus status() const { return code; }
00145 
00147   FXbool eof() const { return code!=FXStreamOK; }
00148 
00150   void setError(FXStreamStatus err);
00151 
00153   FXStreamDirection direction() const { return dir; }
00154 
00156   const FXObject* container() const { return parent; }
00157 
00159   FXlong position() const { return pos; }
00160 
00162   virtual FXbool position(FXlong offset,FXWhence whence=FXFromStart);
00163 
00167   void swapBytes(FXbool s){ swap=s; }
00168 
00172   FXbool swapBytes() const { return swap; }
00173 
00179   void setBigEndian(FXbool big);
00180 
00184   FXbool isBigEndian() const;
00185 
00187   FXStream& operator<<(const FXuchar& v);
00188   FXStream& operator<<(const FXchar& v){ return *this << reinterpret_cast<const FXuchar&>(v); }
00189   FXStream& operator<<(const FXbool& v){ return *this << reinterpret_cast<const FXuchar&>(v); }
00190   FXStream& operator<<(const FXushort& v);
00191   FXStream& operator<<(const FXshort& v){ return *this << reinterpret_cast<const FXushort&>(v); }
00192   FXStream& operator<<(const FXuint& v);
00193   FXStream& operator<<(const FXint& v){ return *this << reinterpret_cast<const FXuint&>(v); }
00194   FXStream& operator<<(const FXfloat& v){ return *this << reinterpret_cast<const FXuint&>(v); }
00195   FXStream& operator<<(const FXdouble& v);
00196   FXStream& operator<<(const FXlong& v){ return *this << reinterpret_cast<const FXdouble&>(v); }
00197   FXStream& operator<<(const FXulong& v){ return *this << reinterpret_cast<const FXdouble&>(v); }
00198 
00200   FXStream& save(const FXuchar* p,FXuval n);
00201   FXStream& save(const FXchar* p,FXuval n){ return save(reinterpret_cast<const FXuchar*>(p),n); }
00202   FXStream& save(const FXbool* p,FXuval n){ return save(reinterpret_cast<const FXuchar*>(p),n); }
00203   FXStream& save(const FXushort* p,FXuval n);
00204   FXStream& save(const FXshort* p,FXuval n){ return save(reinterpret_cast<const FXushort*>(p),n); }
00205   FXStream& save(const FXuint* p,FXuval n);
00206   FXStream& save(const FXint* p,FXuval n){ return save(reinterpret_cast<const FXuint*>(p),n); }
00207   FXStream& save(const FXfloat* p,FXuval n){ return save(reinterpret_cast<const FXuint*>(p),n); }
00208   FXStream& save(const FXdouble* p,FXuval n);
00209   FXStream& save(const FXlong* p,FXuval n){ return save(reinterpret_cast<const FXdouble*>(p),n); }
00210   FXStream& save(const FXulong* p,FXuval n){ return save(reinterpret_cast<const FXdouble*>(p),n); }
00211 
00213   FXStream& operator>>(FXuchar& v);
00214   FXStream& operator>>(FXchar& v){ return *this >> reinterpret_cast<FXuchar&>(v); }
00215   FXStream& operator>>(FXbool& v){ return *this >> reinterpret_cast<FXuchar&>(v); }
00216   FXStream& operator>>(FXushort& v);
00217   FXStream& operator>>(FXshort& v){ return *this >> reinterpret_cast<FXushort&>(v); }
00218   FXStream& operator>>(FXuint& v);
00219   FXStream& operator>>(FXint& v){ return *this >> reinterpret_cast<FXuint&>(v); }
00220   FXStream& operator>>(FXfloat& v){ return *this >> reinterpret_cast<FXuint&>(v); }
00221   FXStream& operator>>(FXdouble& v);
00222   FXStream& operator>>(FXlong& v){ return *this >> reinterpret_cast<FXdouble&>(v); }
00223   FXStream& operator>>(FXulong& v){ return *this >> reinterpret_cast<FXdouble&>(v); }
00224 
00226   FXStream& load(FXuchar* p,FXuval n);
00227   FXStream& load(FXchar* p,FXuval n){ return load(reinterpret_cast<FXuchar*>(p),n); }
00228   FXStream& load(FXbool* p,FXuval n){ return load(reinterpret_cast<FXuchar*>(p),n); }
00229   FXStream& load(FXushort* p,FXuval n);
00230   FXStream& load(FXshort* p,FXuval n){ return load(reinterpret_cast<FXushort*>(p),n); }
00231   FXStream& load(FXuint* p,FXuval n);
00232   FXStream& load(FXint* p,FXuval n){ return load(reinterpret_cast<FXuint*>(p),n); }
00233   FXStream& load(FXfloat* p,FXuval n){ return load(reinterpret_cast<FXuint*>(p),n); }
00234   FXStream& load(FXdouble* p,FXuval n);
00235   FXStream& load(FXlong* p,FXuval n){ return load(reinterpret_cast<FXdouble*>(p),n); }
00236   FXStream& load(FXulong* p,FXuval n){ return load(reinterpret_cast<FXdouble*>(p),n); }
00237 
00239   FXStream& saveObject(const FXObject* v);
00240 
00242   FXStream& loadObject(FXObject*& v);
00243 
00245   FXStream& addObject(const FXObject* v);
00246 
00248   virtual ~FXStream();
00249   };
00250 
00251 }
00252 
00253 #endif

Copyright © 1997-2011 Jeroen van der Zijp