Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

# 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
    00093     //-----------------------------------------------------------------------
    00094     template <class T>
    00095     inline T* CBuffer<T>::Lock(ulong nOffset, ulong nSize, ulong nFlags)
    00096     {
    00097         return reinterpret_cast<T*>(m_Buffer->Lock(nOffset * sizeof(T), nSize * sizeof(T), nFlags));
    00098     }
    00099
    00100     //-----------------------------------------------------------------------
    00101     template <class T>
    00102     inline void CBuffer<T>::Unlock()
    00103     {
    00104         m_Buffer->Unlock();
    00105     }
    00106
    00107     //-----------------------------------------------------------------------
    00108     template <class T>
    00109     inline void CBuffer<T>::Fill(const T* pData, size_t nCount)
    00110     {
    00111         Assert(pData != NULL);
    00112
    00113         T* pMyData = Lock();
    00114         std::copy(pData, pData + nCount, pMyData);
    00115         Unlock();
    00116     }
    00117
    00118     //-----------------------------------------------------------------------
    00119     template <class T>
    00120     inline void CBuffer<T>::Release()
    00121     {
    00122         m_Buffer = NULL;
    00123     }
    00124
    00125     //-----------------------------------------------------------------------
    00126     template <class T>
    00127     inline const IBufferBase* CBuffer<T>::GetBuffer() const
    00128     {
    00129         return m_Buffer;
    00130     }
    00131
    00132     //-----------------------------------------------------------------------
    00133     template <class T>
    00134     inline ulong CBuffer<T>::GetCount() const
    00135     {
    00136         return m_Buffer->m_nCount;
    00137     }
    00138
    00139 } // namespace Keos
    00140
    00141 #endif // KEOS_BUFFER_H