Main Page Class List Class Members

NvBlastFixedArray.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27
28
29 #ifndef NVBLASTFIXEDARRAY_H
30 #define NVBLASTFIXEDARRAY_H
31
32 #include "NvBlastAssert.h"
33 #include "NvBlastMemory.h"
34
35 namespace Nv
36 {
37 namespace Blast
38 {
39
63 template <class T>
64 class FixedArray
65 {
66 public:
67 explicit FixedArray() : m_size(0)
68 {
69 }
70
71 static size_t requiredMemorySize(uint32_t capacity)
72 {
73 return align16(sizeof(FixedArray<T>)) + align16(capacity * sizeof(T));
74 }
75
76 NV_FORCE_INLINE T& pushBack(T& t)
77 {
78 new (data() + m_size) T(t);
79 return data()[m_size++];
80 }
81
82 T popBack()
83 {
84 NVBLAST_ASSERT(m_size);
85 T t = data()[m_size - 1];
86 data()[--m_size].~T();
87 return t;
88 }
89
90 void clear()
91 {
92 for(T* first = data(); first < data() + m_size; ++first)
93 first->~T();
94 m_size = 0;
95 }
96
97 NV_FORCE_INLINE void forceSize_Unsafe(uint32_t s)
98 {
99 m_size = s;
100 }
101
102 NV_FORCE_INLINE T& operator[](uint32_t idx)
103 {
104 NVBLAST_ASSERT(idx < m_size);
105 return data()[idx];
106 }
107
108 NV_FORCE_INLINE const T& operator[](uint32_t idx) const
109 {
110 NVBLAST_ASSERT(idx < m_size);
111 return data()[idx];
112 }
113
114 NV_FORCE_INLINE T& at(uint32_t idx)
115 {
116 NVBLAST_ASSERT(idx < m_size);
117 return data()[idx];
118 }
119
120 NV_FORCE_INLINE const T& at(uint32_t idx) const
121 {
122 NVBLAST_ASSERT(idx < m_size);
123 return data()[idx];
124 }
125
126 NV_FORCE_INLINE uint32_t size() const
127 {
128 return m_size;
129 }
130
131 private:
132 uint32_t m_size;
133
134 NV_FORCE_INLINE T* data()
135 {
136 return (T*)((char*)this + sizeof(FixedArray<T>));
137 }
138
139 private:
140 FixedArray(const FixedArray& that);
141 };
142
143 } // namespace Blast
144 } // namespace Nv
145
146 #endif // ifndef NVBLASTFIXEDARRAY_H
Nv::Blast::FixedArray::FixedArray
FixedArray()
Definition: NvBlastFixedArray.h:67
Nv::Blast::FixedArray::forceSize_Unsafe
NV_FORCE_INLINE void forceSize_Unsafe(uint32_t s)
Definition: NvBlastFixedArray.h:97
Nv::Blast::FixedArray
Definition: NvBlastFixedArray.h:64
NVBLAST_ASSERT
#define NVBLAST_ASSERT(exp)
Definition: NvBlastAssert.h:37
Nv::Blast::FixedArray::clear
void clear()
Definition: NvBlastFixedArray.h:90
Nv::Blast::FixedArray::size
NV_FORCE_INLINE uint32_t size() const
Definition: NvBlastFixedArray.h:126
Nv::Blast::FixedArray::requiredMemorySize
static size_t requiredMemorySize(uint32_t capacity)
Definition: NvBlastFixedArray.h:71
NvBlastMemory.h
Nv::Blast::FixedArray::at
NV_FORCE_INLINE const T & at(uint32_t idx) const
Definition: NvBlastFixedArray.h:120
Nv::Blast::FixedArray::at
NV_FORCE_INLINE T & at(uint32_t idx)
Definition: NvBlastFixedArray.h:114
Nv::Blast::FixedArray::operator[]
NV_FORCE_INLINE const T & operator[](uint32_t idx) const
Definition: NvBlastFixedArray.h:108
Nv::Blast::align16
NV_INLINE T align16(T value)
Definition: NvBlastMemory.h:46
Nv::Blast::FixedArray::pushBack
NV_FORCE_INLINE T & pushBack(T &t)
Definition: NvBlastFixedArray.h:76
Nv::Blast::FixedArray::popBack
T popBack()
Definition: NvBlastFixedArray.h:82
Nv
Definition: NvBlastArray.h:37
NvBlastAssert.h
NV_FORCE_INLINE
#define NV_FORCE_INLINE
Definition: NvPreprocessor.h:365
Nv::Blast::FixedArray::operator[]
NV_FORCE_INLINE T & operator[](uint32_t idx)
Definition: NvBlastFixedArray.h:102