31 #if !defined(_MEMORYSTREAMIMPL_H_INCLUDED_)
32 #define _MEMORYSTREAMIMPL_H_INCLUDED_
51 template <
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;
178 template <
class TBase>
181 PAGE* pNext, *pCurr = m_pFirstPage;
184 pNext = pCurr->m_pNextPage;
191 template <
class TBase>
194 PAGE* pPage = (PAGE*)::
odrxAlloc(
sizeof(PAGE)-1+m_nPageDataSize);
197 pPage->m_pPrevPage = m_pLastPage;
198 pPage->m_pNextPage = 0;
201 m_pLastPage->m_pNextPage = pPage;
204 pPage->m_nPageStartAddr = pPage->m_pPrevPage->m_nPageStartAddr + m_nPageDataSize;
208 m_pFirstPage = m_pCurrPage = pPage;
209 pPage->m_nPageStartAddr = 0;
215 template <
class TBase>
225 if(!m_pCurrPage->m_pNextPage)
228 if(m_pCurrPage->m_pNextPage)
230 m_pCurrPage = m_pCurrPage->m_pNextPage;
231 m_nCurPos += leftInCurPage();
237 template <
class TBase>
244 nNewPos = m_nEndPos +
offset;
247 nNewPos = m_nCurPos +
offset;
261 if(nNewPos != m_nCurPos)
263 if (nNewPos > m_nEndPos)
266 OdInt64 nFromEnd = m_nEndPos - nNewPos;
268 bool bForward =
false;
272 if (nNewPos >= m_pCurrPage->m_nPageStartAddr)
284 m_pCurrPage = m_pLastPage;
289 if (nFromEnd < ((
OdInt64)nNewPos - (
OdInt64)m_pCurrPage->m_nPageStartAddr))
291 m_pCurrPage = m_pLastPage;
297 if (nNewPos < (m_pCurrPage->m_nPageStartAddr - nNewPos))
299 m_pCurrPage = m_pFirstPage;
307 m_pCurrPage = m_pFirstPage;
312 m_pCurrPage = m_pLastPage;
318 nNewPos = nNewPos / m_nPageDataSize * m_nPageDataSize ;
319 while(m_pCurrPage && m_pCurrPage->m_nPageStartAddr < nNewPos)
321 m_pCurrPage = m_pCurrPage->m_pNextPage;
326 while(m_pCurrPage->m_nPageStartAddr > m_nCurPos)
328 m_pCurrPage = m_pCurrPage->m_pPrevPage;
335 template <
class TBase>
338 #ifndef TD_STRICT_ALIGNMENT
339 if (leftInCurPage() >= nLen)
345 template <
class TBase>
349 if(m_nCurPos < m_nEndPos)
351 OdUInt32 nPosInPage = posInCurPage();
352 ret = m_pCurrPage->m_data[nPosInPage];
354 if ((nPosInPage + 1) == m_nPageDataSize)
355 m_pCurrPage = m_pCurrPage->m_pNextPage;
364 template <
class TBase>
370 OdUInt64 nNewPos = m_nCurPos + nLen;
371 if(nNewPos <= m_nEndPos)
377 ::memcpy(pDest, currPos(), nToCopy);
384 nToCopy =
odmin(m_nPageDataSize, nLen);
385 ::memcpy(pDest, m_pCurrPage->m_data, nToCopy);
390 if(m_nCurPos && (m_nCurPos % m_nPageDataSize)==0)
391 m_pCurrPage = m_pCurrPage->m_pNextPage;
399 template <
class TBase>
406 OdUInt64 nPosInPage = posInCurPage();
407 m_pCurrPage->m_data[nPosInPage] = val;
409 m_nEndPos =
odmax(m_nCurPos, m_nEndPos);
410 if ((nPosInPage + 1) == m_nPageDataSize)
411 m_pCurrPage = m_pCurrPage->m_pNextPage;
414 template <
class TBase>
425 ::memcpy(currPos(), pSrc, nToCopy);
432 nToCopy =
odmin(m_nPageDataSize, nLen);
433 ::memcpy(m_pCurrPage->m_data, pSrc, nToCopy);
437 m_nCurPos += nToCopy;
438 if(m_nCurPos && (m_nCurPos % m_nPageDataSize)==0)
439 m_pCurrPage = m_pCurrPage->m_pNextPage;
440 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
const OdUInt8 * currPos() const
OdUInt32 leftInCurPage() const
OdUInt64 allocated() const
OdUInt64 seek(OdInt64 offset, OdDb::FilerSeekType whence)
OdUInt32 pageDataSize() const
OdMemoryStreamImpl(OdUInt32 nPageDataSize=0x400)
const void * pageAlignedAddress(OdUInt32 nLen)
void reserve(OdUInt64 nSize)