31 #if !defined(_MEMORYSTREAMIMPL_H_INCLUDED_)
32 #define _MEMORYSTREAMIMPL_H_INCLUDED_
51 template <
class TBase = OdMemoryStreamDummyBase>
150 m_pCurrPage = m_pFirstPage;
159 m_pLastPage = m_pCurrPage;
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);
445 #endif // !defined(_MEMORYSTREAMIMPL_H_INCLUDED_)