KeosBuffer.h

Go to the documentation of this file.
00001 /*
00002  * This source file is part of KEOS (Free 3D Engine)
00003  * For the latest info, see http://www.keosengine.org/
00004  * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
00005  *
00006  * This program is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU Lesser General Public License as published by the Free Software
00008  * Foundation; either version 2 of the License, or (at your option) any later
00009  * version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License along with
00016  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00017  * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00018  * http://www.gnu.org/copyleft/lesser.txt.
00019  *
00020  */
00021 
00022 #ifndef KEOS_BUFFER_H
00023 #define KEOS_BUFFER_H
00024 
00025 #include "KeosPrerequisites.h"
00026 #include "KeosBufferBase.h"
00027 
00028 namespace Keos
00029 {
00030   //-----------------------------------------------------------------------
00033   template <class T>
00034   class CBuffer
00035   {
00036   public :
00037 
00041     CBuffer(IBufferBase* pBuffer = NULL);
00042 
00049     T* Lock(ulong nOffset = 0, ulong nSize = 0, ulong nFlags = 0);
00050 
00053     void Unlock();
00054 
00059     void Fill(const T* pData, size_t nCount);
00060 
00063     void Release();
00064 
00068     const IBufferBase* GetBuffer() const;
00069 
00073     ulong GetCount() const;
00074 
00075   private :
00076 
00078     CSmartPtr<IBufferBase> m_Buffer;
00079   };
00080 
00081   //=======================================================================
00082   // CBuffer inline functions
00083   //=======================================================================
00084 
00085   //-----------------------------------------------------------------------
00086   template <class T>
00087   inline CBuffer<T>::CBuffer(IBufferBase* pBuffer) :
00088       m_Buffer(pBuffer)
00089   {}
00090 
00091   //-----------------------------------------------------------------------
00092   template <class T>
00093   inline T* CBuffer<T>::Lock(ulong nOffset, ulong nSize, ulong nFlags)
00094   {
00095     return reinterpret_cast<T*>(m_Buffer->Lock(nOffset * sizeof(T), nSize * sizeof(T), nFlags));
00096   }
00097 
00098   //-----------------------------------------------------------------------
00099   template <class T>
00100   inline void CBuffer<T>::Unlock()
00101   {
00102     m_Buffer->Unlock();
00103   }
00104 
00105   //-----------------------------------------------------------------------
00106   template <class T>
00107   inline void CBuffer<T>::Fill(const T* pData, size_t nCount)
00108   {
00109     Assert(pData != NULL);
00110 
00111     T* pMyData = Lock();
00112     std::copy(pData, pData + nCount, pMyData);
00113     Unlock();
00114   }
00115 
00116   //-----------------------------------------------------------------------
00117   template <class T>
00118   inline void CBuffer<T>::Release()
00119   {
00120     m_Buffer = NULL;
00121   }
00122 
00123   //-----------------------------------------------------------------------
00124   template <class T>
00125   inline const IBufferBase* CBuffer<T>::GetBuffer() const
00126   {
00127     return m_Buffer;
00128   }
00129 
00130   //-----------------------------------------------------------------------
00131   template <class T>
00132   inline ulong CBuffer<T>::GetCount() const
00133   {
00134     return m_Buffer->m_nCount;
00135   }
00136 
00137 } // namespace Keos
00138 
00139 #endif // KEOS_BUFFER_H

Generated on Fri Mar 9 14:29:01 2007 for Keos by  doxygen 1.5.1-p1