"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSFileLib/Src/HighLevel/LSFFileMap.h

00001 
00017 #ifndef __LSF_FILEMAP_H__
00018 #define __LSF_FILEMAP_H__
00019 
00020 #include "../LSFFileLib.h"
00021 
00022 namespace lsf {
00023 
00031         class CFileMap {
00032         public :
00033                 // == Various constructors.
00034                 LSE_CALL                                CFileMap();
00035                 LSE_CALL                                ~CFileMap();
00036 
00037 
00038                 // == Functions.
00049                 LSBOOL LSE_CALL                 CreateFileMap( const LSCHAR * _pcFile, LSF_OPEN_FILE _ofOpenType = LSF_OF_READ, LSUINT32 _ui32BufferSize = 0UL );
00050 
00061                 LSBOOL LSE_CALL                 CreateFileMap( const LSWCHAR_T * _pwcFile, LSF_OPEN_FILE _ofOpenType = LSF_OF_READ, LSUINT32 _ui32BufferSize = 0UL );
00062 
00066                 LSVOID LSE_CALL                 Reset();
00067 
00076                 LSUINT32 LSE_CALL               ReadBytes( LSVOID * _pvBuffer, LSUINT64 _ui64Offset, LSUINT32 _ui32Total ) const;
00077 
00086                 LSUINT32 LSE_CALL               WriteBytes( const LSUINT8 * _pui8Buffer, LSUINT64 _ui64Offset, LSUINT32 _ui32Total );
00087 
00093                 LSUINT64 LSE_CALL               GetFileSize() const;
00094 
00095         protected :
00096                 // == Members.
00097                 // Our file map.
00098                 LSF_FILE_MAP                    m_fmMap;
00099 
00100                 // Have we mapped a file?
00101                 LSBOOL                                  m_bMapped;
00102 
00103                 // Address we have mapped.
00104                 mutable LSVOID *                m_pvAddr;
00105 
00106                 // Size of the mapping.
00107                 LSUINTPTR                               m_uiptrSize;
00108 
00109                 // Current size of the mapping.
00110                 mutable LSUINTPTR               m_uiptrCurSize;
00111 
00112                 // Size of the file.
00113                 LSUINT64                                m_ui64FileSize;
00114 
00115                 // Currently buffered offset.
00116                 mutable LSUINT64                m_ui64Offset;
00117 
00118 
00119                 // == Functions.
00130                 LSUINT64 LSE_CALL               GetBaseOffset( LSUINT64 _ui64Offset ) const;
00131 
00142                 LSUINT8 * LSE_CALL              GetBuffer( LSUINT64 _ui64Offset, LSUINT32 &_ui32MaxLen ) const;
00143         };
00144 
00145 
00146         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00147         // DEFINITIONS
00148         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00154         LSE_INLINE LSUINT64 LSE_CALL CFileMap::GetFileSize() const {
00155                 return m_ui64FileSize;
00156         }
00157 
00168         LSE_INLINE LSUINT64 LSE_CALL CFileMap::GetBaseOffset( LSUINT64 _ui64Offset ) const {
00169                 if ( _ui64Offset < (m_uiptrSize >> 1UL) ) { return 0UL; }
00170                 if ( m_ui64FileSize <= m_uiptrSize ) { return 0UL; }
00171                 return ((_ui64Offset + (m_uiptrSize >> 2UL)) & (~((m_uiptrSize >> 1UL) - 1UL))) - (m_uiptrSize >> 1UL);
00172         }
00173 
00174 }       // namespace lsf
00175 
00176 #endif  // __LSF_FILEMAP_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator