gwnavruntime/database/stitchdatamanagerutils.h Source File

stitchdatamanagerutils.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: JUBA - secondary contact: NOBODY
9 #ifndef Navigation_StitchDataManagerUtils_H
10 #define Navigation_StitchDataManagerUtils_H
11 
13 
14 
15 namespace Kaim
16 {
17 
18 class MemoryManagerUtils
19 {
20 public:
21 
22 
23  template<class T>
24  static bool IsMemoryAlignedForClass(T* memory)
25  {
26  return IsMemoryAlignedForClassFromClassSize<(KyUInt32)sizeof(T)>((char*)memory);
27  }
28 
29  template<class T>
30  static KyUInt32 GetPaddingForMemory(char* memory)
31  {
32  return GetPaddingForMemoryFromClassSize<(KyUInt32)sizeof(T)>(memory);
33  }
34 
35  template<class T>
36  static KyUInt32 GetPaddingForBytesCount(KyUInt32 currentBytesCount)
37  {
38  return GetPaddingForBytesCountFromClassSize<(KyUInt32)sizeof(T)>((UPInt)currentBytesCount);
39  }
40 
41  template<KyUInt32 sizeOfClass>
42  static inline bool IsMemoryAlignedForClassFromClassSize(char* memory)
43  {
44  return GetPaddingForMemoryFromClassSize<sizeOfClass>(memory) == 0;
45  }
46 
47  template<KyUInt32 sizeOfClass>
48  static inline KyUInt32 GetPaddingForMemoryFromClassSize(char* memory)
49  {
50  return GetPaddingForBytesCountFromClassSize<sizeOfClass>((UPInt)memory);
51  }
52 
53  template<KyUInt32 sizeOfClass>
54  static inline KyUInt32 GetPaddingForBytesCountFromClassSize(UPInt currentBytesCount)
55  {
56  if ((sizeOfClass & 0x1) != 0)
57  // no padding
58  return 0;
59  else if ((sizeOfClass & 0x2) != 0)
60  // padding to be 2 bytes aligned
61  // need one 1 byte more if currentBytesCount is not already even
62  return (KyUInt32)(currentBytesCount & 0x1);
63  else
64  {
65 #ifndef KY_64BIT_POINTERS
66  // padding to be 4 bytes aligned
67  // add
68  return (KyUInt32)((4 - (currentBytesCount & 0x3)) & 0x3);
69 #else
70  if ((sizeOfClass & 0x4) != 0)
71  // padding to be 4 bytes aligned
72  return (KyUInt32)((4 - (currentBytesCount & 0x3)) & 0x3);
73  else
74  // padding to be 8 bytes aligned
75  return (KyUInt32)((8 - (currentBytesCount & 0x7)) & 0x7);
76 #endif
77  }
78 
79  }
80 
81 
82 };
83 
84 
85 }
86 
87 #endif //Navigation_StitchDataManagerUtils_H
88 
Definition: gamekitcrowddispersion.h:20
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36