/***************************************************************************1* Copyright (C) 2008 by Sindre Aamås *2* [email protected] *3* *4* This program is free software; you can redistribute it and/or modify *5* it under the terms of the GNU General Public License version 2 as *6* published by the Free Software Foundation. *7* *8* This program is distributed in the hope that it will be useful, *9* but WITHOUT ANY WARRANTY; without even the implied warranty of *10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *11* GNU General Public License version 2 for more details. *12* *13* You should have received a copy of the GNU General Public License *14* version 2 along with this program; if not, write to the *15* Free Software Foundation, Inc., *16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *17***************************************************************************/18#ifndef ARRAY_H19#define ARRAY_H2021#include <cstddef>22#include "uncopyable.h"2324template<typename T>25class Array : Uncopyable {26T *a;27std::size_t sz;2829public:30explicit Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {}31~Array() { delete []a; }32void reset(const std::size_t size = 0) { delete []a; a = size ? new T[size] : 0; sz = size; }33std::size_t size() const { return sz; }34T * get() const { return a; }35operator T*() const { return a; }36};3738template<typename T>39class ScopedArray : Uncopyable {40T *a_;4142public:43explicit ScopedArray(T *a = 0) : a_(a) {}44~ScopedArray() { delete []a_; }45void reset(T *a = 0) { delete []a_; a_ = a; }46T * release() { T *a = a_; a_ = 0; return a; }47T * get() const { return a_; }48operator T*() const { return a_; }49};5051#endif525354