| ## 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) : scfImplementationType (this)
    00056   {
    00057     SetContents (parent, offs, size);
    00058   }
    00059
    00060   csParasiticDataBufferBase ()
    00061     : scfImplementationType (this), data(0), size(0)
    00062   {}
    00063 public:
    00064   virtual ~csParasiticDataBufferBase () { }
    00065
    00066   virtual size_t GetSize () const
    00067   { return size; }
    00068   virtual char* GetData () const
    00069   { return (char*)data; }
    00070   inline char *operator * () const
    00071   { return (char *)GetData (); }
    00072   inline int8* GetInt8 ()
    00073   { return (int8 *)GetData (); }
    00074   inline uint8* GetUint8 ()
    00075   { return (uint8 *)GetData (); }
    00076 };
    00077
    00081 class csParasiticDataBuffer
    00082   : public scfImplementationExt0<csParasiticDataBuffer,
    00083         csParasiticDataBufferBase>
    00084 {
    00085 public:
    00094   csParasiticDataBuffer (iDataBuffer* parent, size_t offs,
    00095     size_t size = (size_t)~0)
    00096     : scfImplementationType (this, parent, offs, size)
    00097   {
    00098   }
    00099
    00100   virtual ~csParasiticDataBuffer ()
    00101   {
    00102   }
    00103 };
    00104
    00116 class csParasiticDataBufferPooled :
    00117   public scfImplementationPooled<
    00118     scfImplementationExt0<csParasiticDataBufferPooled,
    00119                           csParasiticDataBufferBase> >
    00120 {
    00121 public:
    00130   csParasiticDataBufferPooled (iDataBuffer* parent, size_t offs,
    00131     size_t size = (size_t)~0) : scfPooledImplementationType (this, parent,
    00132     offs, size) { }
    00133 };
    00134
    00135 #endif // __CS_CSUTIL_PARASITICDATABUFFER_H__