31#if !defined(_MEMORYSTREAMIMPL_H_INCLUDED_)
32#define _MEMORYSTREAMIMPL_H_INCLUDED_
51template <
class TBase = OdMemoryStreamDummyBase>
80 if(m_pCurrPage->m_pPrevPage)
84 m_pCurrPage = m_pCurrPage->m_pPrevPage;
150 m_pCurrPage = m_pFirstPage;
157 PAGE* pNext, *pCurr = m_pCurrPage->m_pNextPage;
158 m_pCurrPage->m_pNextPage = 0;
159 m_pLastPage = m_pCurrPage;
163 pNext = pCurr->m_pNextPage;
179template <
class TBase>
182 PAGE* pNext, *pCurr = m_pFirstPage;
185 pNext = pCurr->m_pNextPage;
192template <
class TBase>
195 PAGE* pPage = (PAGE*)
::odrxAlloc(
sizeof(PAGE)-1+m_nPageDataSize);
198 pPage->m_pPrevPage = m_pLastPage;
199 pPage->m_pNextPage = 0;
202 m_pLastPage->m_pNextPage = pPage;
205 pPage->m_nPageStartAddr = pPage->m_pPrevPage->m_nPageStartAddr + m_nPageDataSize;
209 m_pFirstPage = m_pCurrPage = pPage;
210 pPage->m_nPageStartAddr = 0;
216template <
class TBase>
226 if(!m_pCurrPage->m_pNextPage)
229 if(m_pCurrPage->m_pNextPage)
231 m_pCurrPage = m_pCurrPage->m_pNextPage;
232 m_nCurPos += leftInCurPage();
238template <
class TBase>
245 nNewPos = m_nEndPos +
offset;
248 nNewPos = m_nCurPos +
offset;
262 if(nNewPos != m_nCurPos)
264 if (nNewPos > m_nEndPos)
267 OdInt64 nFromEnd = m_nEndPos - nNewPos;
269 bool bForward =
false;
273 if (nNewPos >= m_pCurrPage->m_nPageStartAddr)
285 m_pCurrPage = m_pLastPage;
290 if (nFromEnd < ((
OdInt64)nNewPos - (
OdInt64)m_pCurrPage->m_nPageStartAddr))
292 m_pCurrPage = m_pLastPage;
298 if (nNewPos < (m_pCurrPage->m_nPageStartAddr - nNewPos))
300 m_pCurrPage = m_pFirstPage;
308 m_pCurrPage = m_pFirstPage;
313 m_pCurrPage = m_pLastPage;
319 nNewPos = nNewPos / m_nPageDataSize * m_nPageDataSize ;
320 while(m_pCurrPage && m_pCurrPage->m_nPageStartAddr < nNewPos)
322 m_pCurrPage = m_pCurrPage->m_pNextPage;
327 while(m_pCurrPage->m_nPageStartAddr > m_nCurPos)
329 m_pCurrPage = m_pCurrPage->m_pPrevPage;
336template <
class TBase>
339#ifndef TD_STRICT_ALIGNMENT
340 if (leftInCurPage() >= nLen)
346template <
class TBase>
350 if(m_nCurPos < m_nEndPos)
352 OdUInt32 nPosInPage = posInCurPage();
353 ret = m_pCurrPage->m_data[nPosInPage];
355 if ((nPosInPage + 1) == m_nPageDataSize)
356 m_pCurrPage = m_pCurrPage->m_pNextPage;
365template <
class TBase>
371 OdUInt64 nNewPos = m_nCurPos + nLen;
372 if(nNewPos <= m_nEndPos)
378 ::memcpy(pDest, currPos(), nToCopy);
385 nToCopy =
odmin(m_nPageDataSize, nLen);
386 ::memcpy(pDest, m_pCurrPage->m_data, nToCopy);
391 if(m_nCurPos && (m_nCurPos % m_nPageDataSize)==0)
392 m_pCurrPage = m_pCurrPage->m_pNextPage;
400template <
class TBase>
407 OdUInt64 nPosInPage = posInCurPage();
408 m_pCurrPage->m_data[nPosInPage] = val;
410 m_nEndPos =
odmax(m_nCurPos, m_nEndPos);
411 if ((nPosInPage + 1) == m_nPageDataSize)
412 m_pCurrPage = m_pCurrPage->m_pNextPage;
415template <
class TBase>
426 ::memcpy(currPos(), pSrc, nToCopy);
433 nToCopy =
odmin(m_nPageDataSize, nLen);
434 ::memcpy(m_pCurrPage->m_data, pSrc, nToCopy);
438 m_nCurPos += nToCopy;
439 if(m_nCurPos && (m_nCurPos % m_nPageDataSize)==0)
440 m_pCurrPage = m_pCurrPage->m_pNextPage;
441 m_nEndPos =
odmax(m_nCurPos, m_nEndPos);
ALLOCDLL_EXPORT void * odrxAlloc(size_t nBytes)
ALLOCDLL_EXPORT void odrxFree(void *pMemBlock)
void putBytes(const void *buffer, OdUInt32 nLen)
void seekNextPage(bool bCreateNew=false)
void getBytes(void *buffer, OdUInt32 nLen)
OdUInt32 posInCurPage() const
void putByte(OdUInt8 val)
void setPageDataSize(OdUInt32 nPageSize)
OdUInt64 curPageNo() const
OdUInt32 leftInCurPage() const
OdMemoryStreamImpl(OdUInt32 nPageDataSize=0x2000)
OdUInt64 allocated() const
OdUInt64 seek(OdInt64 offset, OdDb::FilerSeekType whence)
const OdUInt8 * currPos() const
OdUInt32 pageDataSize() const
const void * pageAlignedAddress(OdUInt32 nLen)
void reserve(OdUInt64 nSize)