Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

hyp.file.chunkx.h

00001 /*
00002 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
00003  Ephydryne Components.
00004  Ephydryne is a part of the Hyperion Project.
00005 ----------------------------------------------------------
00006  Copyright (c) 2001 Pierre Rebours.
00007 
00008  This library is free software; you can redistribute it and/or
00009  modify it under the terms of the GNU Lesser General Public
00010  License as published by the Free Software Foundation; either
00011  version 2.1 of the License, or (at your option) any later version.
00012 
00013  This library is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  
00017  See hyp.license.txt file for more information about the license.
00018  
00019  Web: http://lagrandeporte.multimania.com/hyperion
00020  Email: pierre_rebours@yahoo.com
00021 ----------------------------------------------------------
00022  CVS
00023  $Log$
00024  
00025  Creation 02/05/01 Pierre Rebours
00026 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
00027 */
00028 
00029 #ifndef _hyp_file_chunkx_h_
00030 #define _hyp_file_chunkx_h_
00031 
00032 class CChunkBase
00033 {
00034 public:
00035         char* m_pChunk;
00036         DWORD m_Size;
00037         int m_Offset;
00038 
00039         CChunkBase() : m_pChunk(0),m_Size(0),m_Offset(0) {}
00040 
00041         inline DWORD Size(void) const {
00042                 return m_Size;
00043         }
00044         inline void* Chunk(void) const {
00045                 return static_cast<void*>(m_pChunk);
00046         }
00047 };
00048 
00049 class CChunkMemory :
00050 public CChunkBase
00051 {
00052         
00053 public:
00054         CChunkMemory(const DWORD& size) {
00055                 m_Size=size;
00056                 m_pChunk=new char[size];
00057                 memset(m_pChunk,0,size);
00058                 m_Offset=0;
00059         }
00060         ~CChunkMemory() {
00061                 delete[] m_pChunk;
00062         }
00063 
00064 
00065         template<class T>
00066         void InsertData(const T* p_data) {
00067                 hyp_ASSERT(m_Offset+sizeof(T)<=m_Size);
00068                 memcpy(&m_pChunk[m_Offset],p_data,sizeof(T));
00069                 m_Offset+=sizeof(T);
00070         }
00071 
00072         template<class T>
00073         void InsertBases(const T& bases) {
00074                 DWORD dw_value=bases.size();
00075                 InsertData(&dw_value);
00076         
00077                 for(int i=0;i<bases.size();i++) {
00078                         dw_value=bases[i].label;
00079                         InsertData(&dw_value);
00080                         dw_value=bases[i].vertices_global.size();
00081                         InsertData(&dw_value);
00082                         
00083                         for(int j=0;j<bases[i].vertices_global.size();j++) {
00084                                 dw_value=bases[i].vertices_global[j];
00085                                 InsertData(&dw_value);
00086                         }
00087                         
00088                         for(j=0;j<bases[i].vertices_local.size();j++) {
00089                                 dw_value=bases[i].vertices_local[j];
00090                                 InsertData(&dw_value);
00091                         }
00092                 }
00093         }
00094 };
00095 
00096 class CChunkMemoryRead :
00097 public CChunkBase
00098 {
00099 public:
00100         CChunkMemoryRead(LPDIRECTXFILEDATA p_data)
00101         {
00102                 p_data->GetData(NULL,&m_Size,(void**)&m_pChunk);
00103         }
00104 
00105         template<class T>
00106         void Extract(T* p_data) {
00107                 hyp_ASSERT(m_Offset+sizeof(T)<=m_Size);
00108                 memcpy(p_data,&m_pChunk[m_Offset],sizeof(T));
00109                 m_Offset+=sizeof(T);
00110         }
00111 };
00112 
00113         
00114 
00115 #endif

Top of Page
written by Pierre Rebours © 2000-2001. Terms of Use.