oaMapFile.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // oaMapFile.h
00003 //
00004 // This file contains the definitions for the oaMapFile class. This utility
00005 // class extend oaFile to manage a memory-mapped disk file. Capabilities
00006 // supported include:
00007 //
00008 // 1)   The oaMapFile class implements the basic file-mapping capability,
00009 //      which is used by oaMapFileWindow for each memory-mapped portion of the
00010 //      file.
00011 // 2)   The oaMapFile class supports byte-swapping in order to support files
00012 //      across machine types.
00013 // 3)   This class support files whose size is larger than 32 bits. As part
00014 //      of this support, the API allows any 32-bit window of the file to be
00015 //      mapped at a time.
00016 // 4)   Newly created files must be handled carefully, because zero sized files
00017 //      cannot be mapped. For this reason, the mapping size is checked, and if
00018 //      zero, the map is not created.
00019 // 5)   oaMapFile supports changing the size of the underlying file while one
00020 //      or more oaMapFileWindows are open, with the restriction that while
00021 //      the file size is being changed by one thread, there must not be any
00022 //      attempt by other threads to read or write to the file.
00023 //
00024 // Note that the Win32 and UNIX versions of this class are quite different due
00025 // to the differences in how file mapping is supported.
00026 //
00027 // *****************************************************************************
00028 // Except as specified in the OpenAccess terms of use of Cadence or Silicon
00029 // Integration Initiative, this material may not be copied, modified,
00030 // re-published, uploaded, executed, or distributed in any way, in any medium,
00031 // in whole or in part, without prior written permission from Cadence.
00032 //
00033 //                Copyright 2002-2005 Cadence Design Systems, Inc.
00034 //                           All Rights Reserved.
00035 //
00036 //  $Author: icftcm $
00037 //  $Revision: #1 $
00038 //  $Date: 2010/08/09 $
00039 //  $State: Exp $
00040 // *****************************************************************************
00041 // *****************************************************************************
00042 
00043 
00044 
00045 #if !defined(oaMapFile_P)
00046 #define oaMapFile_P
00047 
00048 
00049 
00050 // *****************************************************************************
00051 // Nested includes
00052 // *****************************************************************************
00053 #include "oaFile.h"
00054 
00055 
00056 
00057 // *****************************************************************************
00058 // Declare and define types in the OpenAccess namespace.
00059 // *****************************************************************************
00060 BEGIN_OA_NAMESPACE
00061 
00062 
00063 
00064 // *****************************************************************************
00065 // Forward Public Class Declarations
00066 // *****************************************************************************
00067 class oaMapFileWindow;
00068 
00069 
00070 
00071 // *****************************************************************************
00072 // oaMapFile
00073 // *****************************************************************************
00074 class OA_BASE_DLL_API oaMapFile : public oaFile {
00075 public:
00076                             oaMapFile(const oaString &nameIn);
00077     virtual                 ~oaMapFile();
00078 
00079     oaByte                  *map(oaUInt4    &size,
00080                                  oaUInt8    &offset,
00081                                  void       *mapLoc = NULL);
00082     void                    unmap(oaByte    *mapLoc,
00083                                   oaUInt4   size);
00084 
00085     void                    setSize(oaUInt8 size);
00086     oaUInt8                 getMappableSize() const;
00087 
00088     oaMapFileWindow         *getFirstWindow() const;
00089     void                    closeWindows();
00090 
00091     oaBoolean               isMapped() const;
00092 
00093     oaBoolean               getSwap() const;
00094     void                    setSwap(oaBoolean swapIn);
00095 
00096 protected:
00097     void                    initMapping(oaUInt8 size);
00098     void                    destroyMapping();
00099 
00100     void                    addWindow(oaMapFileWindow *window);
00101     void                    removeWindow(oaMapFileWindow *window);
00102 
00103     oaUInt8                 mappableSize;
00104     oaUInt4                 numMappedWindows;
00105     oaMapFileWindow         *firstWindow;
00106     oaBoolean               swap;
00107 
00108 #if defined(OA_WINDOWS)
00109     // Note that we define a handle as a void* in order to avoid a dependency
00110     // on Windows.h in the public headers. The handle will be cast to the
00111     // correct type of HANDLE when used.
00112     void                    *mapHandle;
00113 #endif
00114 
00115     static const oaUInt4    alignment;
00116     static const oaUInt4    granularity;
00117 
00118     friend class oaMapFileWindow;
00119 };
00120 
00121 
00122 
00123 END_OA_NAMESPACE
00124 
00125 #endif

Return to top of page