gwnavruntime/blob/blobref.h Source File

blobref.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
10 
11 
14 
15 
16 namespace Kaim
17 {
18 
19 
20 class BlobRefImpl
21 {
22  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
23 
24 public:
25  // Constructs a new instance of this class.
26  KY_INLINE BlobRefImpl() : m_shallowBlobSize(0), m_offset(0) {}
27 
28  KY_INLINE void* Ptr() const
29  {
30  if (m_shallowBlobSize == 0)
31  return nullptr;
32  else
33  return (void*)((char*)&m_offset + m_offset);
34  }
35 
36 public:
37  KyUInt32 m_shallowBlobSize;
38  KyInt32 m_offset;
39 
40 private:
41  BlobRefImpl& operator=(const BlobRefImpl& other);
42  BlobRefImpl(const BlobRefImpl& other);
43 };
44 
45 
46 
50 template <class T>
51 class BlobRef
52 {
53  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
54 
55 public:
56  KY_INLINE BlobRef() {}
57 
58  KY_INLINE T* Ptr() const { return (T*)m_impl.Ptr(); }
59 
60  KY_INLINE KyUInt32 ShallowBlobSize() const { return m_impl.m_shallowBlobSize; }
61 public:
62  BlobRefImpl m_impl;
63 
64 private:
65  BlobRef& operator=(const BlobRef& blobRef);
66  BlobRef(const BlobRef& blobRef);
67 };
68 
69 
70 // --------------------------------- inline implementation ---------------------------------
71 
72 template <class T>
73 void SwapEndianness(Endianness::Target e, BlobRef<T>& self)
74 {
76  {
77  // use count and values once they have been swapped
78  SwapEndianness(e, self.m_impl.m_shallowBlobSize);
79  SwapEndianness(e, self.m_impl.m_offset);
80 
81  if (self.m_impl.m_shallowBlobSize != 0)
82  SwapEndianness(e, *self.Ptr());
83  }
84  else
85  {
86  // use shallowBlobSize and value before they are swapped
87  KyUInt32 shallowBlobSize = self.m_impl.m_shallowBlobSize;
88  T* value = self.Ptr();
89 
90  SwapEndianness(e, self.m_impl.m_shallowBlobSize);
91  SwapEndianness(e, self.m_impl.m_offset);
92 
93  if (shallowBlobSize != 0)
94  SwapEndianness(e, *value);
95  }
96 }
97 
98 
99 }
100 
101 
102 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
The same endianness type as the current platform.
Definition: endianness.h:29
A BlobRef is a type of reference that is compatible with the blob serialization framework.
Definition: blobref.h:51
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24