// Array.cpp // // Array class. It uses an ArrayStructure for the actual storage. // This class acts like a kind of adapter since it defines a common interface // for different array structures like normal arrays and sparse arrays. // The array structure to use is given as template argument. // // 29 januari 1999 RD Started // 2002-1-21 DD indexing starts at 1 // 2002-3-30 DD operator [] incorrectly implemented; corrected // 2005-12-17 DD size_t --> I // // (C) Datasim Component Technology 1999-2006 #ifndef DSArray_cpp #define DSArray_cpp #include "Array.hpp" #include // Constructors & destructor template Array::Array() { // Default constructor m_structure=S(); m_start=1; } template Array::Array(I size) { // Constructor with size. Start index=1. m_structure=S(size_t(size)); m_start=1; } template Array::Array(I size, I start) { // Constructor with size & start index m_structure=S(size_t(size)); m_start=start; } template Array::Array(I size, I start, const V& value) { // Constructor with size & start index m_structure=S(size_t(size)); m_start=start; // Initialise array elements for (I i = MinIndex(); i <= MaxIndex(); i++) (*this)[i] = value; } template Array::Array(const Array& source) { // Copy constructor m_structure=source.m_structure; m_start=source.m_start; } template Array::~Array() { // Destructor } // Selectors template I Array::MinIndex() const { // Return the minimum index return m_start; } template I Array::MaxIndex() const { // Return the maximum index return m_start+Size()-1; } template I Array::Size() const { // The size of the array return I(m_structure.Size()); } // Operators template inline V& Array::operator [] (I index) { // Subscripting operator return m_structure[index - m_start + 1]; } template inline const V& Array::operator [] (I index) const { // Subscripting operator return m_structure[index - m_start + 1]; } template Array& Array::operator = (const Array& source) { // Assignment operator // Exit if same object if (this==&source) return *this; m_structure=source.m_structure; m_start=source.m_start; return *this; } #endif // DSArray_cpp