gwnavruntime/blob/blobref.h Source File

blobref.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 
9 // primary contact: GUAL - secondary contact: NOBODY
10 #ifndef Navigation_BlobRef_H
11 #define Navigation_BlobRef_H
12 
13 
16 
17 
18 namespace Kaim
19 {
20 
21 
22 class BlobRefImpl
23 {
24  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
25 
26 public:
27  // Constructs a new instance of this class.
28  KY_INLINE BlobRefImpl() : m_shallowBlobSize(0), m_offset(0) {}
29 
30  KY_INLINE void* Ptr() const
31  {
32  if (m_shallowBlobSize == 0)
33  return KY_NULL;
34  else
35  return (void*)((char*)&m_offset + m_offset);
36  }
37 
38 public:
39  KyUInt32 m_shallowBlobSize;
40  KyInt32 m_offset;
41 
42 private:
43  BlobRefImpl& operator=(const BlobRefImpl& other);
44  BlobRefImpl(const BlobRefImpl& other);
45 };
46 
47 
48 
52 template <class T>
53 class BlobRef
54 {
55  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
56 
57 public:
58  KY_INLINE BlobRef() {}
59 
60  KY_INLINE T* Ptr() const { return (T*)m_impl.Ptr(); }
61 
62  KY_INLINE KyUInt32 ShallowBlobSize() const { return m_impl.m_shallowBlobSize; }
63 public:
64  BlobRefImpl m_impl;
65 
66 private:
67  BlobRef& operator=(const BlobRef& blobRef);
68  BlobRef(const BlobRef& blobRef);
69 };
70 
71 
72 // --------------------------------- inline implementation ---------------------------------
73 
74 template <class T>
75 void SwapEndianness(Endianness::Target e, BlobRef<T>& self)
76 {
78  {
79  // use count and values once they have been swapped
80  SwapEndianness(e, self.m_impl.m_shallowBlobSize);
81  SwapEndianness(e, self.m_impl.m_offset);
82 
83  if (self.m_impl.m_shallowBlobSize != 0)
84  SwapEndianness(e, *self.Ptr());
85  }
86  else
87  {
88  // use shallowBlobSize and value before they are swapped
89  KyUInt32 shallowBlobSize = self.m_impl.m_shallowBlobSize;
90  T* value = self.Ptr();
91 
92  SwapEndianness(e, self.m_impl.m_shallowBlobSize);
93  SwapEndianness(e, self.m_impl.m_offset);
94 
95  if (shallowBlobSize != 0)
96  SwapEndianness(e, *value);
97  }
98 }
99 
100 
101 }
102 
103 
104 #endif
105 
The same endianness type as the current platform.
Definition: endianness.h:37
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
A BlobRef is a type of reference that is compatible with the blob serialization framework.
Definition: blobref.h:58
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36