Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGBinaryDataHandler.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef _BINARYDATAHANDLER_H_
00040 #define _BINARYDATAHANDLER_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include <OSGConfig.h>
00046 #include <OSGBase.h>
00047 #include <OSGBaseTypes.h>
00048 #include <OSGException.h>
00049 #include <OSGBaseFunctions.h>
00050 
00051 #include <vector>
00052 #include <list>
00053 #include <string>
00054 
00055 OSG_BEGIN_NAMESPACE
00056 
00060 class OSG_BASE_DLLMAPPING BinaryDataHandler 
00061 {
00062     /*==========================  PUBLIC  =================================*/
00063 
00064   public:
00065 
00066     /*---------------------------------------------------------------------*/
00070     struct ReadError : public Exception 
00071     {
00072         ReadError(const Char8 *reason);
00073     };
00074     
00075     struct WriteError : public Exception 
00076     {
00077         WriteError(const Char8 *reason);
00078     };
00079  
00081     /*---------------------------------------------------------------------*/
00085     BinaryDataHandler(UInt32 zeroCopyThreshold = 0,
00086                       bool   networkOrder      = true);
00087 
00089     /*---------------------------------------------------------------------*/
00093     virtual ~BinaryDataHandler(void); 
00094 
00096     /*---------------------------------------------------------------------*/
00100     void put       (      void const   *src,   UInt32 size);
00101     void putAndFree(      MemoryHandle  src,   UInt32 size);
00102 
00103     void putValue  (const bool         &value              );
00104     void putValue  (const UInt8        &value              );
00105     void putValue  (const UInt16       &value              );
00106     void putValue  (const UInt32       &value              );
00107     void putValue  (const UInt64       &value              );
00108     void putValue  (const Int8         &value              );
00109     void putValue  (const Int16        &value              );
00110     void putValue  (const Int32        &value              );
00111     void putValue  (const Int64        &value              );
00112     void putValue  (const Real16       &value              );
00113     void putValue  (const Real32       &value              );
00114     void putValue  (const Real64       &value              );
00115     void putValue  (const Real128      &value              );
00116     void putValue  (const std::string  &value              );
00117 
00118     void putValues (const bool         *value, UInt32 size);
00119     void putValues (const UInt8        *value, UInt32 size);
00120     void putValues (const UInt16       *value, UInt32 size);
00121     void putValues (const UInt32       *value, UInt32 size);
00122     void putValues (const UInt64       *value, UInt32 size);
00123     void putValues (const Int8         *value, UInt32 size);
00124     void putValues (const Int16        *value, UInt32 size);
00125     void putValues (const Int32        *value, UInt32 size);
00126     void putValues (const Int64        *value, UInt32 size);
00127     void putValues (const Real16       *value, UInt32 size);
00128     void putValues (const Real32       *value, UInt32 size);
00129     void putValues (const Real64       *value, UInt32 size);
00130     void putValues (const Real128      *value, UInt32 size);
00131     void putValues (const std::string  *value, UInt32 size);
00132 
00134     /*---------------------------------------------------------------------*/
00138     void get        (void         *dst,   UInt32 size);
00139     void getAndAlloc(MemoryHandle &src,   UInt32 size);
00140 
00141     void getValue   (bool         &value             );
00142     void getValue   (UInt8        &value             );
00143     void getValue   (UInt16       &value             );
00144     void getValue   (UInt32       &value             );
00145     void getValue   (UInt64       &value             );
00146     void getValue   (Int8         &value             );
00147     void getValue   (Int16        &value             );
00148     void getValue   (Int32        &value             );
00149     void getValue   (Int64        &value             );
00150     void getValue   (Real16       &value             );
00151     void getValue   (Real32       &value             );
00152     void getValue   (Real64       &value             );
00153     void getValue   (Real128      &value             );
00154     void getValue   (std::string  &value             );
00155     
00156     void getValues  (bool         *value, UInt32 size);
00157     void getValues  (UInt8        *value, UInt32 size);
00158     void getValues  (UInt16       *value, UInt32 size);
00159     void getValues  (UInt32       *value, UInt32 size);
00160     void getValues  (UInt64       *value, UInt32 size);
00161     void getValues  (Int8         *value, UInt32 size);
00162     void getValues  (Int16        *value, UInt32 size);
00163     void getValues  (Int32        *value, UInt32 size);
00164     void getValues  (Int64        *value, UInt32 size);
00165     void getValues  (Real16       *value, UInt32 size);
00166     void getValues  (Real32       *value, UInt32 size);
00167     void getValues  (Real64       *value, UInt32 size);
00168     void getValues  (Real128      *value, UInt32 size);
00169     void getValues  (std::string  *value, UInt32 size);
00170 
00172     /*---------------------------------------------------------------------*/
00176     virtual void forceCopy      (void      );
00177     virtual void forceDirectIO  (void      );
00178 
00179             void flush          (void      );
00180 
00181             void setNetworkOrder(bool value);
00182             bool getNetworkOrder(void      );
00183 
00185     /*=========================  PROTECTED  ===============================*/
00186 
00187   protected:
00188 
00191     struct MemoryBlock 
00192     {
00193       public:
00194 
00195         MemoryBlock             (MemoryHandle m, UInt32 s, UInt32 ds = 0);
00196 
00197         MemoryHandle getMem     (void                                   );
00198         void         setMem     (MemoryHandle m                         );
00199 
00200         UInt32       getSize    (void                                   );
00201         void         setSize    (UInt32 dataSize                        );
00202 
00203         UInt32       getDataSize(void                                   );
00204         void         setDataSize(UInt32 dataSize                        );
00205 
00206       private:
00207 
00208         MemoryHandle  _mem;
00209         UInt32        _size;
00210         UInt32        _dataSize;
00211     };
00212 
00213     typedef std::vector<MemoryBlock>  BuffersT;
00214     typedef std::list  <MemoryHandle> FreeMemT;
00215 
00216     /*---------------------------------------------------------------------*/
00220     BuffersT           _readBuffers;
00221     BuffersT           _writeBuffers;
00222     BuffersT           _zeroCopyBuffers;
00223     UInt32             _zeroCopyThreshold;
00224 
00225     FreeMemT           _freeMem;
00226     BuffersT::iterator _currentReadBuffer;
00227     UInt32             _currentReadBufferPos;
00228     BuffersT::iterator _currentWriteBuffer;
00229     UInt32             _currentWriteBufferPos;
00230     
00231     bool               _networkOrder;
00232     
00234     /*---------------------------------------------------------------------*/
00238             BuffersT::iterator readBufBegin(void                      );
00239             BuffersT::iterator readBufEnd  (void                      );
00240             void               readBufAdd  (MemoryHandle  mem, 
00241                                             UInt32        size,
00242                                             UInt32        dataSize = 0);
00243             void               readBufClear(void                      );
00244 
00245     virtual void               read        (MemoryHandle   src,
00246                                             UInt32         size       );
00247     virtual void               readBuffer  (void                      );
00248 
00250     /*---------------------------------------------------------------------*/
00254             BuffersT::iterator writeBufBegin(void                     );
00255             BuffersT::iterator writeBufEnd  (void                     );
00256             void               writeBufAdd  (MemoryHandle mem, 
00257                                              UInt32       size,
00258                                              UInt32       dataSize = 0);
00259             void               writeBufClear(void                     );
00260 
00261     virtual void               write        (MemoryHandle   src,    
00262                                              UInt32         size      );
00263     virtual void               writeBuffer  (void                     );
00264 
00266     /*---------------------------------------------------------------------*/
00270     bool isReadBufferEmpty(void);
00271 
00273     /*==========================  PRIVATE  ================================*/
00274 
00275   private:
00276 
00277     /*---------------------------------------------------------------------*/
00281     void pushBuffer(void);
00282     void pullBuffer(void);
00283     void freeMem   (void);
00284 
00287     BinaryDataHandler(const BinaryDataHandler &source);
00289     void operator =(const BinaryDataHandler &source);
00290 };
00291 
00292 OSG_END_NAMESPACE
00293 
00294 #include "OSGBinaryDataHandler.inl"
00295 
00296 #define OSGBINARYDATAHANDLER_HEADER_CVSID "@(#)$Id: $"
00297 
00298 #endif /* _BINARYDATAHANDLER_H_ */

Generated on Thu Aug 25 04:01:18 2005 for OpenSG by  doxygen 1.4.3