csutil/parasiticdatabuffer.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2005 by Jorrit Tyberghein 00003 (C) 2005 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00024 #ifndef __CS_CSUTIL_PARASITICDATABUFFER_H__ 00025 #define __CS_CSUTIL_PARASITICDATABUFFER_H__ 00026 00027 #include "csextern.h" 00028 #include "csgeom/math.h" 00029 #include "csutil/pooledscfclass.h" 00030 #include "csutil/scf_implementation.h" 00031 #include "iutil/databuff.h" 00032 00036 class csParasiticDataBufferBase : 00037 public scfImplementation1<csParasiticDataBufferBase, iDataBuffer> 00038 { 00039 protected: 00040 csRef<iDataBuffer> parentBuffer; 00041 uint8* data; 00042 size_t size; 00043 00044 void SetContents (iDataBuffer* parent, size_t offs, size_t size) 00045 { 00046 parentBuffer = parent; 00047 data = parent->GetUint8 () + offs; 00048 size_t parRemaining = parent->GetSize () - offs; 00049 if (size == (size_t)~0) 00050 csParasiticDataBufferBase::size = parRemaining; 00051 else 00052 csParasiticDataBufferBase::size = csMin (size, parRemaining); 00053 } 00054 00055 csParasiticDataBufferBase (iDataBuffer* parent, size_t offs, 00056 size_t size = (size_t)~0) : scfImplementationType (this) 00057 { 00058 SetContents (parent, offs, size); 00059 } 00060 00061 csParasiticDataBufferBase () 00062 : scfImplementationType (this), data(0), size(0) 00063 {} 00064 public: 00065 virtual ~csParasiticDataBufferBase () { } 00066 00067 virtual size_t GetSize () const 00068 { return size; } 00069 virtual char* GetData () const 00070 { return (char*)data; } 00071 inline char *operator * () const 00072 { return (char *)GetData (); } 00073 inline int8* GetInt8 () 00074 { return (int8 *)GetData (); } 00075 inline uint8* GetUint8 () 00076 { return (uint8 *)GetData (); } 00077 }; 00078 00082 class csParasiticDataBuffer 00083 : public scfImplementationExt0<csParasiticDataBuffer, 00084 csParasiticDataBufferBase> 00085 { 00086 public: 00095 csParasiticDataBuffer (iDataBuffer* parent, size_t offs, 00096 size_t size = (size_t)~0) 00097 : scfImplementationType (this, parent, offs, size) 00098 { 00099 } 00100 00101 virtual ~csParasiticDataBuffer () 00102 { 00103 } 00104 }; 00105 00117 class csParasiticDataBufferPooled : 00118 public scfImplementationPooled< 00119 scfImplementationExt0<csParasiticDataBufferPooled, 00120 csParasiticDataBufferBase> > 00121 { 00122 public: 00131 csParasiticDataBufferPooled (iDataBuffer* parent, size_t offs, 00132 size_t size = (size_t)~0) : scfPooledImplementationType (this, parent, 00133 offs, size) { } 00134 }; 00135 00136 #endif // __CS_CSUTIL_PARASITICDATABUFFER_H__
Generated for Crystal Space 2.1 by doxygen 1.6.1
