24 #ifndef OPENSUBDIV3_VTR_STACK_BUFFER_H
25 #define OPENSUBDIV3_VTR_STACK_BUFFER_H
27 #include "../version.h"
30 namespace OPENSUBDIV_VERSION {
49 template <
typename TYPE,
unsigned int SIZE>
67 operator TYPE
const * ()
const {
return _data; }
68 operator TYPE * () {
return _data; }
70 size_type
GetSize()
const {
return _size; }
73 void Reserve(size_type capacity);
78 StackBuffer& operator=(
const StackBuffer<TYPE,SIZE> &) {
return *
this; }
80 void allocate(size_type capacity);
92 char _staticData[SIZE *
sizeof(TYPE)];
100 template <
typename TYPE,
unsigned int SIZE>
102 StackBuffer<TYPE,SIZE>::allocate(size_type capacity) {
107 _dynamicData =
static_cast<char*
>(::operator
new(capacity *
sizeof(TYPE)));
109 _data =
reinterpret_cast<TYPE*
>(_dynamicData);
110 _capacity = capacity;
113 template <
typename TYPE,
unsigned int SIZE>
115 StackBuffer<TYPE,SIZE>::deallocate() {
117 ::operator
delete(_dynamicData);
119 _data =
reinterpret_cast<TYPE*
>(_staticData);
127 template <
typename TYPE,
unsigned int SIZE>
129 StackBuffer<TYPE,SIZE>::construct() {
131 for (size_type i = 0; i < _size; ++i) {
132 (void)
new (&_data[i]) TYPE;
135 template <
typename TYPE,
unsigned int SIZE>
137 StackBuffer<TYPE,SIZE>::destruct() {
139 for (size_type i = 0; i < _size; ++i) {
147 template <
typename TYPE,
unsigned int SIZE>
150 _data(reinterpret_cast<TYPE*>(_staticData)),
157 template <
typename TYPE,
unsigned int SIZE>
160 _data(reinterpret_cast<TYPE*>(_staticData)),
171 template <
typename TYPE,
unsigned int SIZE>
182 template <
typename TYPE,
unsigned int SIZE>
186 if (capacity > _capacity) {
193 template <
typename TYPE,
unsigned int SIZE>
200 }
else if (size > _capacity) {
212 using namespace OPENSUBDIV_VERSION;
size_type GetSize() const
void Reserve(size_type capacity)
void SetSize(size_type size)