mutable instead of const_cast for nicer code

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5636 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2008-05-08 10:27:32 +00:00
parent 709ed79b5b
commit 09df47d0f2
2 changed files with 8 additions and 10 deletions

View file

@ -263,12 +263,10 @@ void *MMapFile::get(int offset, int *sizep) const
size += offset - alignedoffset; size += offset - alignedoffset;
#ifdef _WIN32 #ifdef _WIN32
const_cast<MMapFile*>(this)->m_pView = m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size);
MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0, alignedoffset, size);
#else #else
const_cast<MMapFile*>(this)->m_pView = m_pView = mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset);
mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset); m_iMappedSize = *sizep = size;
const_cast<MMapFile*>(this)->m_iMappedSize = *sizep = size;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
@ -297,11 +295,11 @@ void *MMapFile::getmore(int offset, int size) const
#ifndef _WIN32 #ifndef _WIN32
int iMappedSizeBackup = m_iMappedSize; int iMappedSizeBackup = m_iMappedSize;
#endif #endif
const_cast<MMapFile*>(this)->m_pView = 0; m_pView = 0;
pView = get(offset, size); pView = get(offset, size);
const_cast<MMapFile*>(this)->m_pView = pViewBackup; m_pView = pViewBackup;
#ifndef _WIN32 #ifndef _WIN32
const_cast<MMapFile*>(this)->m_iMappedSize = iMappedSizeBackup; m_iMappedSize = iMappedSizeBackup;
#endif #endif
return pView; return pView;
} }

View file

@ -74,8 +74,8 @@ class MMapFile : public IMMap
int m_hFileDesc; int m_hFileDesc;
int m_iMappedSize; int m_iMappedSize;
#endif #endif
void *m_pView; mutable void *m_pView;
int m_iSize; mutable int m_iSize;
BOOL m_bReadOnly; BOOL m_bReadOnly;
BOOL m_bTempHandle; BOOL m_bTempHandle;