## Public API Reference

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# 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 "csutil/pooledscfclass.h"
    00029 #include "csutil/scf_implementation.h"
    00030 #include "iutil/databuff.h"
    00031
    00035 class csParasiticDataBufferBase :
    00036   public scfImplementation1<csParasiticDataBufferBase, iDataBuffer>
    00037 {
    00038 protected:
    00039   csRef<iDataBuffer> parentBuffer;
    00040   uint8* data;
    00041   size_t size;
    00042
    00043   void SetContents (iDataBuffer* parent, size_t offs, size_t size)
    00044   {
    00045     parentBuffer = parent;
    00046     data = parent->GetUint8 () + offs;
    00047     size_t parRemaining = parent->GetSize () - offs;
    00048     if (size == (size_t)~0)
    00049       csParasiticDataBufferBase::size = parRemaining;
    00050     else
    00051       csParasiticDataBufferBase::size = MIN(size, parRemaining);
    00052   }
    00053
    00054   csParasiticDataBufferBase (iDataBuffer* parent, size_t offs,
    00055     size_t size = (size_t)~0)
    00056     : 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 CS_CRYSTALSPACE_EXPORT 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
    00120 class CS_CRYSTALSPACE_EXPORT csParasiticDataBufferPooled :
    00121   public csParasiticDataBufferBase
    00122 {
    00123 public:
    00124   SCF_DECLARE_IBASE_POOLED_EXTERN(CS_CRYSTALSPACE_EXPORT,
    00125     csParasiticDataBufferPooled);
    00126
    00127   virtual ~csParasiticDataBufferPooled ()
    00128   {
    00129     SCF_DESTRUCT_IBASE();
    00130   }
    00131
    00136   void SetContents (iDataBuffer* parent, size_t offs,
    00137     size_t size = (size_t)~0)
    00138   {
    00139     csParasiticDataBufferBase::SetContents (parent, offs, size);
    00140   }
    00141 protected:
    00142   csParasiticDataBufferPooled (Pool* pool) : csParasiticDataBufferBase()
    00143   {
    00144     SCF_CONSTRUCT_IBASE_POOLED (pool);
    00145   }
    00146 };
    00147
    00148 #endif // __CS_CSUTIL_PARASITICDATABUFFER_H__