MemoryFilter.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 #ifndef _MEMORYFILTER_H_
00013 #define _MEMORYFILTER_H_
00014 
00015 #include <SIBCUtil.h>
00016 #include <SIBCString.h>
00017 #include "SIBCArray.h"
00018 
00019 #include "CXSIFilter.h"
00020 
00021 #define MEMORY_FILTER_NAME      "MEMORY"
00022 #define MEMORY_FILTER_ID        "mem"
00023 
00024 #define BUFFER_SIZE             (128 * 1024)
00025 
00027 /* 
00028 * This class will gather up to a certain size of data until it calls its subfilter to
00029 * write or it will read up to a certain size in one go and answer to request until it
00030 * has exhausted the data at which point it will ask its subfilter for more data.
00031 */
00032 class CMemoryFilter : public CXSIFilter
00033 {
00034 public:
00038     CMemoryFilter();
00042     virtual ~CMemoryFilter();
00043 
00048     int Open ( CSIBCString in_szFilename,  _SI_FILE_MODE in_Mode );
00051     int Close ();
00052     
00058     int Read ( SI_Char * out_pBuffer, SI_Long in_lSize );
00064     int Write( SI_Char * in_pBuffer,  SI_Long in_lSize );
00065 
00066 
00070     int Eof();
00074     int Tell();
00075 
00076     void WriteHeader();
00077     void            SetHeader ( CSIBCString in_szHeader );
00078     CSIBCString     GetHeader () { return GetLastHeader(); }
00079 static              CSIBCString GetLastHeader();
00080 private:
00081     void    Flush();
00082     void    FillBuffer();
00083 
00084     char    *m_pBuffer;
00085     int m_lPosition;
00086     SI_Long m_lSizeRead;
00087     bool    m_bHeaderSkipped;
00088     bool    m_bReadMode;
00089 static      SI_Char                 m_cHeader[17];
00090 static      CSIBCArray<SI_Char*>    m_blocks;
00091 static      CSIBCArray<SI_Int>      m_blockSize;
00092     SI_Long m_lBufIndex;
00093 };
00094 
00095 #endif