⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmdatatypememmappedfile.h

📁 TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language inter
💻 H
字号:
#ifndef VM_DATA_TYPE_MEM_MAPPED_FILE_H_INCLUDED
#define VM_DATA_TYPE_MEM_MAPPED_FILE_H_INCLUDED
/*****************************************************************************/
/*                           HEADER FILE                                     */
/*****************************************************************************/
/*
       $Archive:  $

      $Revision:  $
          $Date:  $
        $Author:  $

   Description:  Class derived from VMMemMappedFile that implements the memory
                 mapped file derivation specific to the TOOL data types

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
/*****************************************************************************/

#include "VMMemMappedFile.h"

// returned errors
#define BLOCK_FULL		 	  -1
#define LOCK_FAILURE	 	  -2
#define MISSING_HEADER	 	-3
#define DATA_BLOCK_FAILED	-4
#define HEADER_SIZE       20

#define OKAY                          0
#define DEFAULT_DATA_TRANSFER_SIZE    4048


///////////////////////////////////////////////////////////////////////////////
//
// Each data value written to the memory mapped file is preceeded by a data 
// header that describes the nature of the data immediately following the
// header
//
class VMDataTransferHeader
{
public:
  char          m_chStatus;
  char          m_chRecType;
  unsigned long m_ulRecSize;
  unsigned long m_ulRecCount;
  unsigned long m_ulFlags;
  char          m_achReserved[ 6 ];

  VMDataTransferHeader( int iRecType, unsigned long ulRecSize, unsigned long ulRecCount, unsigned long ulFlags )
  {
    m_chStatus   = ( ulRecCount ) ? 1 : 0;
    m_chRecType  = iRecType;
    m_ulRecSize  = ulRecSize;
    m_ulRecCount = ulRecCount;
    m_ulFlags    = ulFlags;
  }
  long DataSize( void ) { return( m_ulRecCount * m_ulRecSize ); };  // bytes of stored data, does not include header size
  int  HasData( void )  { return( m_chStatus ); };
};


class VMDataTransferBlock : public VMMemMappedFile
{
public:
  VMDataTransferBlock( char* pchFileName, DWORD dwSize );
  ~VMDataTransferBlock( void );
	
  int HasData( void ) 
  { return( ( m_poCurRecHeader ) ? (int)m_poCurRecHeader->m_chStatus : 0 ); };

  int GetRecType( void ) 
  { return( ( m_poCurRecHeader ) ? (int)m_poCurRecHeader->m_chRecType : 0 ); }; 

  long GetRecSize( void ) 
  { return( ( m_poCurRecHeader ) ? m_poCurRecHeader->m_ulRecSize : 0 ); };

  long GetRecCount( void ) 
  { return( ( m_poCurRecHeader ) ? m_poCurRecHeader->m_ulRecCount : 0 ); };

  long GetDataSize( void ) 
  { return( ( m_poCurRecHeader ) ? m_poCurRecHeader->m_ulRecCount * m_poCurRecHeader->m_ulRecSize : 0 ); };

  void* MoveToEnd( void ) 
  { return( (char*)m_pvRawData + GetDataSize() ); };


  VMDataTransferHeader* GetNextHeader( int iRecType = 0 );
  VMDataTransferHeader* GetFirstHeader( int iRecType = 0 );

  void* ReadFirstRecord( int iRecType, void* pchBuffer );
  void* ReadRecord( int iRecType, int iRecNum, void* pchBuffer );

  long AppendData( int iRecType, void* pvData, int iRecordCount = 1 );
  long AppendHeader( int iRecType, unsigned long ulRecSize, unsigned long ulRecCount, unsigned long ulFlags = 0 );
  long WriteHeader( int iRecType, unsigned long ulRecSize, unsigned long ulRecCount, unsigned long ulFlags = 0 );
  inline int WriteHeader( VMDataTransferHeader& roHeader )
  { 
    return( WriteHeader( roHeader.m_chRecType, roHeader.m_ulRecSize, roHeader.m_ulRecCount, roHeader.m_ulFlags ) );
  }

  void ClearAll( void );  // erase all data from block
  unsigned long GetFlags( void ){ return( ( m_poCurRecHeader ) ? m_poCurRecHeader->m_ulFlags : 0 ); };

protected:

  virtual long PostProcessReadData( void* pvMemMappedDataBuffer, void* pvYourData );
  virtual long PreProcessWriteData( void* pvMemMappedDataBuffer, 
                                    void* pvToYourData, 
                                    DWORD dwBufferSize );
	
  void*                 m_pvRawData;     // mapped pointer to actual memory area
  VMDataTransferHeader* m_poCurRecHeader;	
  int                   m_iCurrentRecord;
};


#endif


/*****************************************************************************/
/* Check-in history */
/*
*$Log:   $
*/
/*****************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -