diff src/sdl/Array.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/sdl/Array.h	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,40 @@
     1.4 +/***************************************************************************
     1.5 + *   Copyright (C) 2008 by Sindre Aam�s                                    *
     1.6 + *   aamas@stud.ntnu.no                                                    *
     1.7 + *                                                                         *
     1.8 + *   This program is free software; you can redistribute it and/or modify  *
     1.9 + *   it under the terms of the GNU General Public License version 2 as     *
    1.10 + *   published by the Free Software Foundation.                            *
    1.11 + *                                                                         *
    1.12 + *   This program is distributed in the hope that it will be useful,       *
    1.13 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    1.14 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    1.15 + *   GNU General Public License version 2 for more details.                *
    1.16 + *                                                                         *
    1.17 + *   You should have received a copy of the GNU General Public License     *
    1.18 + *   version 2 along with this program; if not, write to the               *
    1.19 + *   Free Software Foundation, Inc.,                                       *
    1.20 + *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    1.21 + ***************************************************************************/
    1.22 +#ifndef ARRAY_H
    1.23 +#define ARRAY_H
    1.24 +
    1.25 +#include <cstddef>
    1.26 +
    1.27 +template<typename T>
    1.28 +class Array {
    1.29 +	T *a;
    1.30 +	std::size_t sz;
    1.31 +	
    1.32 +	Array(const Array &ar);
    1.33 +	
    1.34 +public:
    1.35 +	Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {}
    1.36 +	~Array() { delete []a; }
    1.37 +	void reset(const std::size_t size) { delete []a; a = size ? new T[size] : 0; sz = size; }
    1.38 +	std::size_t size() const { return sz; }
    1.39 +	operator T*() { return a; }
    1.40 +	operator const T*() const { return a; }
    1.41 +};
    1.42 +
    1.43 +#endif