Программирование на языке MFC

Мой второй блог в серии программирования

Конструктор класса CArchive


Исходный текст конструктора клас-саа CArchive находится в файле агссоге.срр:

Пример

CArchive::CArchive(CFile* pFile, UINT nMode, int nBufSize, void* lpBuf) :

m_strFileName(pFile->GetFilePath() )

{

ASSERT_VALID(pFile);

// initialize members not dependent on allocated buffer

m_nMode = nMode; m_pFile = pFile; m_pSchemaMap = NULL; m_pLoadArray = NULL; m_pDocument = NULL; m_bForceFlat = TRUE;

m_nObjectSchema = (UINT)-l; // start with invalid schema

if (IsStoringO )

m_nGrowSize = nBlockSize; else

m_nGrowSize = nGrowSize; m_nHashSize = nHashSize;

// initialize the buffer. minimum size is 128 m_lpBufStart = (BYTE*)lpBuf; m_bUserBuf = TRUE; m_bDirectBuffer = FALSE;

if (nBufSize < nBufSizeMin) {

// force use of private buffer of minimum size m_nBufSize = nBufSizeMin; m_lpBufStart = NULL;

}

else

m_nBufSize = nBufSize;

nBufSize = m_nBufSize; if (m_lpBufStart == NULL) {

// check for CFile providing buffering support m_bDirectBuffer =

m_pPile->GetBufferPtr(CFile::bufferCheck); if (!m_bDirectBuffer) {

// no support for direct buffering, // allocate new buffer m_lpBufStart = new BYTE[m_nBufSize]; m_bUserBuf = FALSE;

}

else {

I/ CFile* supports direct buffering! nBufSize = 0; // will trigger initial FillBuffer

}

}

if (!m_bDirectBuffer) {

ASSERT(m_lpBufStart !=NULL);

ASSERT(AfxIsValidAddress(m_lpBufStart,

nBufSize, IsStoring()));

}

m_lpBufMax = m_lpBufStart + nBufSize;

m_lpBufCur = (IsLoading()) ? m_lpBufMax : m_lpBufStart;
ASSERT (m_pStoreMap == NULL);
// same as m_pLoadArray

}

Похожие статьи: