gwnavruntime/blob/blobarray.h Source File

blobarray.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 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef Navigation_BlobArray_H
10 #define Navigation_BlobArray_H
11 
12 
15 
16 
17 namespace Kaim
18 {
19 
27 template <class T>
28 class BlobArray
29 {
30  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
31 public:
32  typedef T ValueType;
33 
34  // ---------------------------------- Public Member Functions ----------------------------------
35 
36  BlobArray() : m_count(0), m_offset(0) {}
37 
39  KY_INLINE const T* GetValues() const { return (const T*)((char*)&m_offset + m_offset); }
40 
42  KY_INLINE T* GetValues() { return (T*)((char*)&m_offset + m_offset); }
43 
44  KY_INLINE KyUInt32 GetCount() const { return m_count; }
45 
46 public: // internal
49 };
50 
51 
52 
53 // --------------------------------- inline implementation ---------------------------------
54 
55 template <class T>
56 void SwapEndianness(Endianness::Target e, BlobArray<T>& self)
57 {
59  {
60  // use count and values once they have been swapped
61  SwapEndianness(e, self.m_count);
62  SwapEndianness(e, self.m_offset);
63 
64  T* values = self.GetValues();
65  for (KyUInt32 i = 0; i < self.m_count; ++i)
66  SwapEndianness(e, values[i]);
67  }
68  else
69  {
70  // use count and values before they are swapped
71  KyUInt32 count = self.m_count;
72  T* values = self.GetValues();
73 
74  SwapEndianness(e, self.m_count);
75  SwapEndianness(e, self.m_offset);
76 
77  for (KyUInt32 i = 0; i < count; ++i)
78  SwapEndianness(e, values[i]);
79  }
80 }
81 
82 
83 // Helper template function to initialiaze Array<> from BlobArray<>
84 // Each element of the Array<> is initialized with operator=(blobElement)
85 template <class ArrayT, class BlobArrayT>
86 void InitArrayFromBlobArray_Assign(ArrayT& kyArray, const BlobArrayT& blobArray)
87 {
88  const typename BlobArrayT::ValueType* blobValues = blobArray.GetValues();
89  KyUInt32 blobValuesCount = blobArray.GetCount();
90  kyArray.Clear();
91  kyArray.Resize(blobValuesCount);
92  for (KyUInt32 i = 0; i < blobValuesCount; ++i)
93  kyArray[i] = blobValues[i];
94 }
95 
96 // Helper template function to initialiaze Array<> from BlobArray<>
97 // Each element of the Array<> is initialized with InitFromBlob(blobElement)
98 template <class ArrayT, class BlobArrayT>
99 void InitArrayFromBlobArray_InitFromBlob(ArrayT& kyArray, const BlobArrayT& blobArray)
100 {
101  const typename BlobArrayT::ValueType* blobValues = blobArray.GetValues();
102  KyUInt32 blobValuesCount = blobArray.GetCount();
103  kyArray.Clear();
104  kyArray.Resize(blobValuesCount);
105  for (KyUInt32 i = 0; i < blobValuesCount; ++i)
106  kyArray[i].InitFromBlob(blobValues[i]);
107 }
108 
109 // Helper template function to initialize Array<String> from BlobArray<BlobArray<char> >
110 template <class ArrayT, class BlobArrayT>
111 void InitArrayFromBlobArray_String(ArrayT& kyArray, const BlobArrayT& blobArray)
112 {
113  const typename BlobArrayT::ValueType* blobValues = blobArray.GetValues();
114  KyUInt32 blobValuesCount = blobArray.GetCount();
115  kyArray.Clear();
116  kyArray.Resize(blobValuesCount);
117  for (KyUInt32 i = 0; i < blobValuesCount; ++i)
118  kyArray[i] = blobValues[i].GetValues();
119 }
120 
121 
122 }
123 
124 #endif
KyInt32 m_offset
Set by BLOB_ARRAY and BLOB_ARRAY_COPY during BaseBlobBuilder::DoBuild(). Do not modify.
Definition: blobarray.h:56
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
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:35
A BlobArray an array that is compatible with the blob serialization framework.
Definition: blobarray.h:28
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
KyUInt32 m_count
The number of elements in this BlobArray. Set by BLOB_ARRAY and BLOB_ARRAY_COPY during BaseBlobBuilde...
Definition: blobarray.h:55
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
const T * GetValues() const
Retrieves a const pointer to the data stored in this array.
Definition: blobarray.h:44