gwnavgeneration/containers/tlsarray.h Source File

tlsarray.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 #ifndef Navigation_ArrayTLS_H
9 #define Navigation_ArrayTLS_H
10 
16 
17 
18 namespace Kaim
19 {
20 
21 // ArrayTLS is a ArrayDH that always uses GeneratorMemory::TlsHeap()
22 // This avoid to pass GeneratorMemory::TlsHeap() to ArrayDH constructors
23 template<class T>
24 class KyArrayTLS : public KyArrayDH<T, MemStat_NavDataGen>
25 {
26 public:
27  typedef T ValueType;
28  typedef KyArrayTLS SelfType;
29  typedef KyArrayDH<T, MemStat_NavDataGen> BaseType;
30 
31  KyArrayTLS() : BaseType(GeneratorMemory::TlsHeap()) {}
32  explicit KyArrayTLS(int size) : BaseType(GeneratorMemory::TlsHeap(), size) {}
33  KyArrayTLS(const SelfType& a) : BaseType(a) {}
34  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
35 
36  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
37  bool DoesContain(const ValueType& value) const { return ArrayAlg::DoesContain<SelfType,ValueType>(*this, value); }
38  void RemoveConsecutiveDuplicates() { return ArrayAlg::RemoveConsecutiveDuplicates<SelfType>(*this); }
39 };
40 
41 
42 // ArrayTLS_POD is a ArrayDH_POD that always uses GeneratorMemory::TlsHeap()
43 // This avoid to pass GeneratorMemory::TlsHeap() to ArrayDH_POD constructors
44 template<class T>
45 class KyArrayTLS_POD : public ArrayDH_POD<T, MemStat_NavDataGen>
46 {
47 public:
48  typedef T ValueType;
49  typedef KyArrayTLS_POD SelfType;
50  typedef ArrayDH_POD<T, MemStat_NavDataGen> BaseType;
51 
52  KyArrayTLS_POD() : BaseType(GeneratorMemory::TlsHeap()) {}
53  explicit KyArrayTLS_POD(int size) : BaseType(GeneratorMemory::TlsHeap(), size) {}
54  KyArrayTLS_POD(const SelfType& a) : BaseType(a) {}
55  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
56 
57  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
58  bool DoesContain(const ValueType& value) const { return ArrayAlg::DoesContain<SelfType,ValueType>(*this, value); }
59  void RemoveConsecutiveDuplicates() { return ArrayAlg::RemoveConsecutiveDuplicates<SelfType>(*this); }
60 };
61 
62 // ArrayTLS_POD is a ArrayDH_POD that always uses GeneratorMemory::TlsHeap()
63 // This avoid to pass GeneratorMemory::TlsHeap() to ArrayDH_POD constructors
64 template<class T>
65 class KyArrayTLS_CPP : public ArrayDH_CPP<T, MemStat_NavDataGen>
66 {
67 public:
68  typedef T ValueType;
69  typedef KyArrayTLS_CPP SelfType;
70  typedef ArrayDH_CPP<T, MemStat_NavDataGen> BaseType;
71 
72  KyArrayTLS_CPP() : BaseType(GeneratorMemory::TlsHeap()) {}
73  explicit KyArrayTLS_CPP(int size) : BaseType(GeneratorMemory::TlsHeap(), size) {}
74  KyArrayTLS_CPP(const SelfType& a) : BaseType(a) {}
75  const SelfType& operator=(const SelfType& a) { BaseType::operator=(a); return *this; }
76 
77  KyUInt32 GetCount() const { return (KyUInt32)BaseType::GetSize(); }
78  bool DoesContain(const ValueType& value) const { return ArrayAlg::DoesContain<SelfType,ValueType>(*this, value); }
79  void RemoveConsecutiveDuplicates() { return ArrayAlg::RemoveConsecutiveDuplicates<SelfType>(*this); }
80 };
81 
82 class BitFieldTLS : public BitFieldBase
83 {
84  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_NavDataGen)
85 public:
86  explicit BitFieldTLS() : BitFieldBase() {}
87  explicit BitFieldTLS(KyUInt32 bitsCount) : BitFieldBase() { Resize(bitsCount); }
88  void Resize(KyUInt32 newBitsCount) { Resize_(newBitsCount, MemStat_NavDataGen, GeneratorMemory::TlsHeap()); }
89  void Reserve(KyUInt32 newBitsCount) { Reserve_(newBitsCount, MemStat_NavDataGen, GeneratorMemory::TlsHeap()); }
90 };
91 
92 template <class T, typename Comparator = DefaultLess<T>, typename BinaryHeapIndexTracker = BinaryHeapIndexTracker_None<T> >
93 class BinaryHeapTls : public BinaryHeap<T, KyArrayTLS<T>, Comparator, BinaryHeapIndexTracker>
94 {
95 };
96 
97 template <class T, typename Comparator = DefaultLess<T>, typename BinaryHeapIndexTracker = BinaryHeapIndexTracker_None<T> >
98 class BinaryHeapTLS_CPP : public BinaryHeap<T, KyArrayTLS_CPP<T>, Comparator, BinaryHeapIndexTracker>
99 {
100 };
101 
102 
103 } // namespace Kaim
104 
105 
106 #endif // Navigation_ArrayTLS_H
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