CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
FlatMemStream.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24
25
26
27// FlatMemStream.h: interface for the OdMemoryStream class.
28//
30
31#if !defined(_ODFLATMEMSTREAM_H_INCLUDED_)
32#define _ODFLATMEMSTREAM_H_INCLUDED_
33
34#include "TD_PackPush.h"
35
36#include "OdStreamBuf.h"
37
38class OdFlatMemStream;
43
51
52//DOM-IGNORE-BEGIN
53template <class TBase = OdEmptyBaseClass>
54class OdStreamPosImpl : public TBase {
55protected:
58public:
61 OdUInt64 tell() { return m_nCurPos; }
63 bool isEof() { return left()==0; }
65};
66//DOM-IGNORE-END
67
73template <class TBase = OdEmptyBaseClass>
74class OdFlatMemStreamImpl : public OdStreamPosImpl<TBase> {
75protected:
76 using OdStreamPosImpl<TBase>::m_nEndPos;
77 using OdStreamPosImpl<TBase>::m_nCurPos;
79public:
83 OdUInt8* data() { return (OdUInt8*)m_pMemData; }
84
85 using OdStreamPosImpl<TBase>::left;
86protected:
93 virtual void append(OdUInt64 numBytes) { throw OdError(eNotOpenForWrite); }
94
99public:
100 inline OdFlatMemStreamImpl() { init(0, 0, 0); }
101
102 OdFlatMemStreamImpl(void* buffer, OdUInt64 numBytes, OdUInt64 nCurPos)
103 { init(buffer, numBytes, nCurPos); }
104
111 inline void init(void* buffer, OdUInt64 numBytes, OdUInt64 curPosition = 0);
112
114 void getBytes(void* buffer, OdUInt32 numBytes);
115
116 // overrides existing byte(s)
118 void putBytes(const void* buffer, OdUInt32 numBytes);
119};
120
121
128{
129protected:
130 inline OdFlatMemStream() {}
131public:
139 static OdFlatMemStreamPtr createNew(void* buffer, OdUInt64 numBytes, OdUInt64 curPosition = 0);
140
141 void copyDataTo(OdStreamBuf* pDestination, OdUInt64 sourceStart, OdUInt64 sourceEnd);
142};
143
144
151{
152 void init(OdUInt64 numBytes) { OdFlatMemStream::init(odrxAlloc((size_t)numBytes), numBytes); }
153public:
162};
163
164
165template<class TBase>
166inline void OdFlatMemStreamImpl<TBase>::init(void* pMemData, OdUInt64 nSize, OdUInt64 nCurPos) {
167 m_pMemData = pMemData;
168 m_nEndPos = nCurPos + nSize;
169 m_nCurPos = nCurPos;
170}
171
172
173template<class TBase>
175 OdUInt64 nNewPos;
176 switch(whence) {
178 nNewPos = m_nEndPos + offset;
179 break;
181 nNewPos = m_nCurPos + offset;
182 break;
184 nNewPos = offset;
185 break;
186 default:
187 throw OdError(eInvalidInput);
188 break;
189 };
190 if(nNewPos > m_nEndPos)
191 throw OdError(eEndOfFile);
192 return (m_nCurPos = nNewPos);
193}
194
195template<class TBase>
197 if(left()==0)
198 throw OdError(eEndOfFile);
199 return *(data() + m_nCurPos++);
200}
201
202template<class TBase>
204 if(left() < nLen)
205 throw OdError(eEndOfFile);
206 ::memcpy(buffer, data()+m_nCurPos, nLen);
207 m_nCurPos += nLen;
208}
209
210template<class TBase>
212 if(m_nCurPos < m_nEndPos)
213 *(data() + m_nCurPos++) = val;
214 else
215 throw OdError(eEndOfFile);
216}
217
218template<class TBase>
220 if(m_nCurPos + nLen <= m_nEndPos) {
221 ::memcpy(data()+m_nCurPos, buffer, nLen);
222 m_nCurPos += nLen;
223 } else {
224 throw OdError(eEndOfFile);
225 }
226}
227
228
229#include "TD_PackPop.h"
230
231#endif // !defined(_ODFLATMEMSTREAM_H_INCLUDED_)
232
OdSmartPtr< OdFlatMemStream > OdFlatMemStreamPtr
Definition: FlatMemStream.h:42
ALLOCDLL_EXPORT void * odrxAlloc(size_t nBytes)
ALLOCDLL_EXPORT void odrxFree(void *pMemBlock)
unsigned int OdUInt32
unsigned char OdUInt8
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
ODRX_DECLARE_MEMBERS(OdFlatMemStream)
static OdFlatMemStreamPtr createNew(void *buffer, OdUInt64 numBytes, OdUInt64 curPosition=0)
void copyDataTo(OdStreamBuf *pDestination, OdUInt64 sourceStart, OdUInt64 sourceEnd)
OdFlatMemStreamImpl(void *buffer, OdUInt64 numBytes, OdUInt64 nCurPos)
void putByte(OdUInt8 value)
void putBytes(const void *buffer, OdUInt32 numBytes)
virtual void append(OdUInt64 numBytes)
Definition: FlatMemStream.h:93
void init(void *buffer, OdUInt64 numBytes, OdUInt64 curPosition=0)
void getBytes(void *buffer, OdUInt32 numBytes)
static OdFlatMemStreamPtr createNew(OdUInt64 numBytes)
Definition: Int64.h:43
OdUInt64 seek(OdInt64 offset, OdDb::FilerSeekType seekType)
OdUInt64 left()
Definition: FlatMemStream.h:59
OdUInt64 m_nCurPos
Definition: FlatMemStream.h:57
OdUInt64 length()
Definition: FlatMemStream.h:60
OdUInt64 m_nEndPos
Definition: FlatMemStream.h:56
OdUInt64 tell()
Definition: FlatMemStream.h:61
GLuint buffer
Definition: gles2_ext.h:178
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition: gles2_ext.h:110
GLintptr offset
Definition: gles2_ext.h:183
GLsizei const GLfloat * value
Definition: gles2_ext.h:302
FilerSeekType
Definition: OdStreamBuf.h:49
@ kSeekFromCurrent
Definition: OdStreamBuf.h:51
@ kSeekFromStart
Definition: OdStreamBuf.h:50
@ kSeekFromEnd
Definition: OdStreamBuf.h:52