7#ifndef OPENSUBDIV3_VTR_STACK_BUFFER_H
8#define OPENSUBDIV3_VTR_STACK_BUFFER_H
10#include "../version.h"
13namespace OPENSUBDIV_VERSION {
32template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE = false>
36 typedef unsigned int size_type;
41 StackBuffer(size_type size);
50 operator TYPE
const * ()
const {
return _data; }
51 operator TYPE * () {
return _data; }
53 size_type GetSize()
const {
return _size; }
55 void SetSize(size_type size);
56 void Reserve(size_type capacity);
60 StackBuffer(
const StackBuffer<TYPE,SIZE,POD_TYPE> &) { }
61 StackBuffer& operator=(
const StackBuffer<TYPE,SIZE,POD_TYPE> &) {
return *
this; }
63 void allocate(size_type capacity);
75 char _staticData[SIZE *
sizeof(TYPE)];
83template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
85StackBuffer<TYPE,SIZE,POD_TYPE>::allocate(size_type capacity) {
90 _dynamicData =
static_cast<char*
>(::operator
new(capacity *
sizeof(TYPE)));
92 _data =
reinterpret_cast<TYPE*
>(_dynamicData);
96template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
98StackBuffer<TYPE,SIZE,POD_TYPE>::deallocate() {
100 ::operator
delete(_dynamicData);
102 _data =
reinterpret_cast<TYPE*
>(_staticData);
112template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
114StackBuffer<TYPE,SIZE,POD_TYPE>::construct() {
116 for (size_type i = 0; i < _size; ++i) {
117 (void)
new (&_data[i]) TYPE;
120template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
122StackBuffer<TYPE,SIZE,POD_TYPE>::destruct() {
124 for (size_type i = 0; i < _size; ++i) {
132template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
134StackBuffer<TYPE,SIZE,POD_TYPE>::StackBuffer() :
135 _data(reinterpret_cast<TYPE*>(_staticData)),
142template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
144StackBuffer<TYPE,SIZE,POD_TYPE>::StackBuffer(size_type size) :
145 _data(reinterpret_cast<TYPE*>(_staticData)),
158template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
160StackBuffer<TYPE,SIZE,POD_TYPE>::~StackBuffer() {
171template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
173StackBuffer<TYPE,SIZE,POD_TYPE>::Reserve(size_type capacity) {
175 if (capacity > _capacity) {
184template <
typename TYPE,
unsigned int SIZE,
bool POD_TYPE>
186StackBuffer<TYPE,SIZE,POD_TYPE>::SetSize(size_type size)
193 }
else if (size > _capacity) {
207using namespace OPENSUBDIV_VERSION;