haiku/headers/os/support/StackOrHeapArray.h
Jonathan Schleifer 76b12d6056 StackOrHeapArray: Add missing include of cstddef.
Signed-off-by: Jérôme Duval <jerome.duval@gmail.com>
2014-01-13 19:14:49 +01:00

44 lines
686 B
C++

/*
* Copyright 2012, Jonathan Schleifer <js@webkeks.org>. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SUPPORT_STACKORHEAPARRAY_H
#define _SUPPORT_STACKORHEAPARRAY_H
#include <cstddef>
#include <new>
template <typename Type, int StackSize>
class BStackOrHeapArray {
public:
BStackOrHeapArray(size_t count)
{
if (count > StackSize)
fData = new(std::nothrow) Type[count];
else
fData = fStackData;
}
~BStackOrHeapArray()
{
if (fData != fStackData)
delete[] fData;
}
bool IsValid() const
{
return fData != NULL;
}
operator Type*()
{
return fData;
}
private:
Type fStackData[StackSize];
Type* fData;
};
#endif