diff --git a/src/common/Array.h b/src/common/Array.h deleted file mode 100644 index f01806ea..00000000 --- a/src/common/Array.h +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Sindre Aam�s * - * aamas@stud.ntnu.no * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License version 2 as * - * published by the Free Software Foundation. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License version 2 for more details. * - * * - * You should have received a copy of the GNU General Public License * - * version 2 along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef ARRAY_H -#define ARRAY_H - -#include - -template -class Array { - T *a; - std::size_t sz; - - Array(const Array &ar); - -public: - Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {} - ~Array() { delete []a; } - void reset(const std::size_t size) { delete []a; a = size ? new T[size] : 0; sz = size; } - std::size_t size() const { return sz; } - operator T*() { return a; } - operator const T*() const { return a; } -}; - -#endif diff --git a/src/common/RingBuffer.h b/src/common/RingBuffer.h index 137df0a0..7228684d 100644 --- a/src/common/RingBuffer.h +++ b/src/common/RingBuffer.h @@ -19,7 +19,7 @@ #ifndef RINGBUFFER_H #define RINGBUFFER_H -#include "Array.h" +#include "array.h" #include #include #include diff --git a/src/common/array.h b/src/common/array.h new file mode 100644 index 00000000..a5f36e69 --- /dev/null +++ b/src/common/array.h @@ -0,0 +1,45 @@ +#ifndef ARRAY_H +#define ARRAY_H + +#include +#include + +template +class Array +{ + public: + typedef T value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T &reference; + typedef const T &const_reference; + typedef T *pointer; + typedef const T *const_pointer; + typedef T *iterator; + typedef const T *const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + private: + pointer m_p; + size_type m_size; + + public: + + Array(size_type size = 0) : m_p(size ? new value_type[size] : 0), m_size(size) {} + + void reset(size_t size) + { + delete[] this->m_p; + this->m_p = size ? new value_type[size] : 0; + this->m_size = size; + } + + size_type size() const { return(this->m_size); } + + operator pointer() { return(this->m_p); } + operator const_pointer() const { return(this->m_p); } + + ///TODO: Add more functions from here: http://en.cppreference.com/w/cpp/container/array +}; +#endif