CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
OdPlatformStreamer.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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-2024 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#ifndef _OD_PLATFORMSTREAMER_H_
26#define _OD_PLATFORMSTREAMER_H_
27
28#include "OdPlatform.h"
29#include "OdStreamBuf.h"
30#include "OdString.h"
31
37{
38public:
44 static OdInt8 rdInt8 (OdStreamBuf& streamBuf);
50 static OdUInt8 rdUInt8 (OdStreamBuf& streamBuf);
56 static OdInt16 rdInt16 (OdStreamBuf& streamBuf);
62 static OdUInt16 rdUInt16 (OdStreamBuf& streamBuf);
68 static OdInt32 rdInt32 (OdStreamBuf& streamBuf);
74 static OdUInt32 rdUInt32 (OdStreamBuf& streamBuf);
80 static OdInt64 rdInt64 (OdStreamBuf& streamBuf);
86 static OdUInt64 rdUInt64 (OdStreamBuf& streamBuf);
92 static float rdFloat (OdStreamBuf& streamBuf);
98 static double rdDouble (OdStreamBuf& streamBuf);
104 static void rd2Doubles(OdStreamBuf& streamBuf, void* doubles);
110 static void rd3Doubles(OdStreamBuf& streamBuf, void* doubles);
117 static void rdDoubles (OdStreamBuf& streamBuf, int numDoubles, void* doubles);
123 static void wrInt8 (OdStreamBuf& streamBuf, OdInt8 value);
129 static void wrUInt8 (OdStreamBuf& streamBuf, OdUInt8 value);
135 static void wrInt16 (OdStreamBuf& streamBuf, OdInt16 value);
141 static void wrUInt16 (OdStreamBuf& streamBuf, OdUInt16 value);
147 static void wrInt32 (OdStreamBuf& streamBuf, OdInt32 value);
153 static void wrUInt32 (OdStreamBuf& streamBuf, OdUInt32 value);
159 static void wrInt64 (OdStreamBuf& streamBuf, OdInt64 value);
165 static void wrUInt64 (OdStreamBuf& streamBuf, OdUInt64 value);
171 static void wrFloat (OdStreamBuf& streamBuf, float value);
177 static void wrDouble (OdStreamBuf& streamBuf, double value);
183 static void wr2Doubles(OdStreamBuf& streamBuf, const void* doubles);
189 static void wr3Doubles(OdStreamBuf& streamBuf, const void* doubles);
196 static void wrDoubles (OdStreamBuf& streamBuf, int numDoubles, const void* doubles);
197
211
223 inline static void putUnicodeStrToBuffer(const OdString& val, OdUInt8*& buffer);
224
228 inline static void wrString(OdStreamBuf& streamBuf, const OdString& val);
229
233 inline static OdString rdString(OdStreamBuf& streamBuf);
234};
235
237{
238 return static_cast<OdInt8>(streamBuf.getByte());
239}
241{
242 return streamBuf.getByte();
243}
245{
246 OdInt16 res;
247 streamBuf.getBytes(&res, sizeof(res));
249 return res;
250}
252{
253 OdUInt16 res;
254 streamBuf.getBytes(&res, sizeof(res));
256 return res;
257}
259{
260 OdInt32 res;
261 streamBuf.getBytes(&res, sizeof(res));
263 return res;
264}
266{
267 OdUInt32 res;
268 streamBuf.getBytes(&res, sizeof(res));
270 return res;
271}
273{
274 OdInt64 res;
275 streamBuf.getBytes(&res, sizeof(res));
276 odSwap8Bytes(&res);
277 return res;
278}
280{
281 OdUInt64 res;
282 streamBuf.getBytes(&res, sizeof(res));
283 odSwap8Bytes(&res);
284 return res;
285}
287{
288 float res;
289 streamBuf.getBytes(&res, sizeof(res));
290 odSwap4Bytes(&res);
291 return res;
292}
294{
295 double res;
296 ODA_ASSUME(sizeof(res) == 8)
297 streamBuf.getBytes(&res, 8);
298 odSwap8Bytes(&res);
299 // if unnormalized or NaN or infinity, set it to 0.0
300 if (!isValidNonZeroIEEEDouble((OdUInt8 *)&res))
301 return 0.0;
302 return res;
303}
304
305inline void OdPlatformStreamer::rd2Doubles(OdStreamBuf& streamBuf, void* pRes2Doubles)
306{
307 ODA_ASSUME(sizeof(double) == 8)
308 streamBuf.getBytes(pRes2Doubles, sizeof(double)*2);
309 fixDouble((double*)pRes2Doubles);
310 fixDouble((double*)pRes2Doubles+1);
311}
312inline void OdPlatformStreamer::rd3Doubles(OdStreamBuf& streamBuf, void* pRes3Doubles)
313{
314 ODA_ASSUME(sizeof(double) == 8)
315 streamBuf.getBytes(pRes3Doubles, sizeof(double)*3);
316 fixDouble((double*)pRes3Doubles);
317 fixDouble((double*)pRes3Doubles+1);
318 fixDouble((double*)pRes3Doubles+2);
319}
320inline void OdPlatformStreamer::rdDoubles(OdStreamBuf& streamBuf, int n, void* pResDoubles)
321{
322 ODA_ASSUME(sizeof(double) == 8)
323 streamBuf.getBytes(pResDoubles, sizeof(double)*n);
324 double* pD = (double*)pResDoubles;
325 while (n--) { fixDouble(pD++); }
326}
327
329{
330 streamBuf.putByte(static_cast<OdUInt8>(val));
331}
333{
334 streamBuf.putByte(val);
335}
337{
339 streamBuf.putBytes(&val, sizeof(val));
340}
342{
344 streamBuf.putBytes(&val, sizeof(val));
345}
347{
349 streamBuf.putBytes(&val, sizeof(val));
350}
352{
354 streamBuf.putBytes(&val, sizeof(val));
355}
357{
358 odSwap8Bytes(&val);
359 streamBuf.putBytes(&val, sizeof(val));
360}
362{
363 odSwap8Bytes(&val);
364 streamBuf.putBytes(&val, sizeof(val));
365}
366inline void OdPlatformStreamer::wrFloat(OdStreamBuf& streamBuf, float val)
367{
368 odSwap4Bytes(&val);
369 streamBuf.putBytes(&val, sizeof(val));
370}
371inline void OdPlatformStreamer::wrDouble(OdStreamBuf& streamBuf, double val)
372{
373 ODA_ASSUME(sizeof(double) == 8)
374 odSwap8Bytes(&val);
375 streamBuf.putBytes(&val, sizeof(val));
376}
377
379{
380 OdString ret;
381#if ODCHAR_IS_INT16LE
382 if (size == -1)
383 {
384 // null terminated
385 ret = (OdChar*)buffer;
386 buffer += ((ret.getLength() + 1) * 2);
387 }
388 else
389 {
390 OdUInt8* pBuf = (OdUInt8*)ret.getBuffer(size);
391 OD_BYTES_FROM_BUFFPTR(buffer, pBuf, (((size_t)size)<<1));
392 ret.releaseBuffer(size);
393 }
394#else
395 OdInt32 finalSize = size;
396 if (size == -1 && buffer)
397 {
398 // null terminated
399 size = 1;
400 OdUInt16* tmp16 = (OdUInt16*)buffer;
401 for ( ; *tmp16; tmp16++)
402 size++;
403 finalSize = size - 1;
404 }
405 OdChar* pBuf = ret.getBuffer(size);
406 for (OdInt32 i = 0; i < size; i++)
407 {
409 }
410 *pBuf = L'\0';
411 ret.releaseBuffer(finalSize);
412#endif
413
414 return ret;
415}
416
417#ifndef ODCHAR_IS_INT16LE
418#error "OdaDefs.h must be included before OdPlatformStreamer.h"
419#endif
420
422{
423 OdInt32 nLen = val.getLength();
424#if ODCHAR_IS_INT16LE
425 OD_BYTES_TO_BUFFPTR(buffer, val.c_str(), nLen*sizeof(OdChar));
426#else
427 const OdChar* p = val.c_str();
428 for (OdInt32 i = 0; i < nLen; i++)
429 {
431 }
432#endif
433}
434
436{
437 OdInt32 nLen = val.getLength();
438 wrInt32(streamBuf, nLen);
439#if ODCHAR_IS_INT16LE
440 streamBuf.putBytes(val.c_str(), nLen * 2);
441#else
442 const OdChar* p = val.c_str();
443 for (OdInt32 i = 0; i < nLen; ++i)
444 wrUInt16(streamBuf, (OdUInt16)*p++);
445#endif
446}
447
449{
450 OdString ret;
451 OdInt32 nLen = rdInt32(streamBuf);
452 OdChar* pBuf = ret.getBufferSetLength(nLen);
453#if ODCHAR_IS_INT16LE
454 streamBuf.getBytes(pBuf, nLen * 2);
455#else
456 for (OdInt32 i = 0; i < nLen; ++i)
457 *pBuf++ = rdUInt16(streamBuf);
458#endif
459 return ret;
460}
461
462
463// Verify that preprocessor symbol ODCHAR_IS_INT16LE has been correctly defined
464#if ODCHAR_IS_INT16LE
465#ifdef ODA_BIGENDIAN
466#error "ODCHAR_IS_INT16LE is defined for a big endian platform"
467#endif
468ODA_ASSUME(sizeof(OdChar) == 2);
469#endif
470
471
472#ifdef ODA_BIGENDIAN
473
474inline void OdPlatformStreamer::wr2Doubles(OdStreamBuf& streamBuf, const void* p2Doubles)
475{
476 wrDouble(streamBuf, *(((double*)p2Doubles)+0));
477 wrDouble(streamBuf, *(((double*)p2Doubles)+1));
478}
479inline void OdPlatformStreamer::wr3Doubles(OdStreamBuf& streamBuf, const void* p3Doubles)
480{
481 wrDouble(streamBuf, *(((double*)p3Doubles)+0));
482 wrDouble(streamBuf, *(((double*)p3Doubles)+1));
483 wrDouble(streamBuf, *(((double*)p3Doubles)+2));
484}
485inline void OdPlatformStreamer::wrDoubles(OdStreamBuf& streamBuf, int n, const void* pDoubles)
486{
487 const double* pD = (const double*)pDoubles;
488 while (n--)
489 {
490 wrDouble(streamBuf, *pD);
491 pD++;
492 }
493}
494
495#else // #ifdef ODA_BIGENDIAN
496
497inline void OdPlatformStreamer::wr2Doubles(OdStreamBuf& streamBuf, const void* p2Doubles)
498{
499 ODA_ASSUME(sizeof(double) == 8)
500 streamBuf.putBytes(p2Doubles, sizeof(double)*2);
501}
502inline void OdPlatformStreamer::wr3Doubles(OdStreamBuf& streamBuf, const void* p3Doubles)
503{
504 ODA_ASSUME(sizeof(double) == 8)
505 streamBuf.putBytes(p3Doubles, sizeof(double)*3);
506}
507inline void OdPlatformStreamer::wrDoubles(OdStreamBuf& streamBuf, int n, const void* pDoubles)
508{
509 ODA_ASSUME(sizeof(double) == 8)
510 streamBuf.putBytes(pDoubles, sizeof(double) * n);
511}
512
513#endif // ODA_BIGENDIAN
514
515#endif // _OD_PLATFORMSTREAMER_H_
516
#define ODA_ASSUME(expr)
Definition DebugStuff.h:180
#define OD_INT16_TO_BUFFPTR(pBuffPtr, val)
#define odSwap4BytesNumber(n)
#define odSwap4Bytes(bytes)
#define OD_BYTES_TO_BUFFPTR(pBuffPtr, FromBuff, nCount)
#define OD_INT16_FROM_BUFFPTR(pBuffPtr)
#define odSwap8Bytes(bytes)
#define OD_BYTES_FROM_BUFFPTR(pBuffPtr, ResBuff, nCount)
#define odSwap2BytesNumber(n)
unsigned int OdUInt32
short OdInt16
signed char OdInt8
unsigned short OdUInt16
int OdInt32
unsigned char OdUInt8
wchar_t OdChar
static void rd3Doubles(OdStreamBuf &streamBuf, void *doubles)
static OdString getUnicodeStrFromBuffer(const OdUInt8 *&buffer, OdInt32 size)
static OdInt64 rdInt64(OdStreamBuf &streamBuf)
static OdUInt16 rdUInt16(OdStreamBuf &streamBuf)
static void wrUInt16(OdStreamBuf &streamBuf, OdUInt16 value)
static OdString rdString(OdStreamBuf &streamBuf)
static OdUInt8 rdUInt8(OdStreamBuf &streamBuf)
static OdInt16 rdInt16(OdStreamBuf &streamBuf)
static float rdFloat(OdStreamBuf &streamBuf)
static void wr2Doubles(OdStreamBuf &streamBuf, const void *doubles)
static void wrInt8(OdStreamBuf &streamBuf, OdInt8 value)
static void wrFloat(OdStreamBuf &streamBuf, float value)
static void wrUInt32(OdStreamBuf &streamBuf, OdUInt32 value)
static void wrInt16(OdStreamBuf &streamBuf, OdInt16 value)
static OdInt32 rdInt32(OdStreamBuf &streamBuf)
static void wrDoubles(OdStreamBuf &streamBuf, int numDoubles, const void *doubles)
static void rd2Doubles(OdStreamBuf &streamBuf, void *doubles)
static void wrUInt64(OdStreamBuf &streamBuf, OdUInt64 value)
static double rdDouble(OdStreamBuf &streamBuf)
static OdInt8 rdInt8(OdStreamBuf &streamBuf)
static void wrUInt8(OdStreamBuf &streamBuf, OdUInt8 value)
static void wrInt64(OdStreamBuf &streamBuf, OdInt64 value)
static OdUInt64 rdUInt64(OdStreamBuf &streamBuf)
static void wr3Doubles(OdStreamBuf &streamBuf, const void *doubles)
static void wrString(OdStreamBuf &streamBuf, const OdString &val)
static void rdDoubles(OdStreamBuf &streamBuf, int numDoubles, void *doubles)
static OdUInt32 rdUInt32(OdStreamBuf &streamBuf)
static void wrDouble(OdStreamBuf &streamBuf, double value)
static void wrInt32(OdStreamBuf &streamBuf, OdInt32 value)
static void putUnicodeStrToBuffer(const OdString &val, OdUInt8 *&buffer)
virtual OdUInt8 getByte()
virtual void getBytes(void *buffer, OdUInt32 numBytes)
virtual void putByte(OdUInt8 value)
virtual void putBytes(const void *buffer, OdUInt32 numBytes)
OdChar * getBufferSetLength(int length)
OdChar * getBuffer(int minBufLength)
const OdChar * c_str() const
Definition OdString.h:205
void releaseBuffer(int newLength=-1)
int getLength() const
Definition OdString.h:135
GLuint buffer
Definition gles2_ext.h:178
GLsizeiptr size
Definition gles2_ext.h:182
GLsizei const GLfloat * value
Definition gles2_ext.h:302