Spectral analysis
Fork of Array_Matrix by
Diff: Array.hpp
- Revision:
- 1:54b07f0d5ba1
- Parent:
- 0:efe9b1f01090
- Child:
- 2:a25dba17218c
diff -r efe9b1f01090 -r 54b07f0d5ba1 Array.hpp --- a/Array.hpp Sun May 22 06:14:18 2016 +0000 +++ b/Array.hpp Mon Jul 25 13:37:16 2016 +0000 @@ -3,7 +3,7 @@ // If you define "#define DEBUG_ARRAY_CHECK", // range check of index is available. // -// 2016/05/22, Copyright (c) 2016 MIKAMI, Naoki +// 2016/07/25, Copyright (c) 2016 MIKAMI, Naoki //----------------------------------------------------------------------- #include "mbed.h" @@ -20,8 +20,10 @@ explicit Array(int i = 1) { ArrayNew(i); } // default constructor Array(const Array<T>& a) { Copy(a); } // copy constructor inline Array(int i, T initialValue); // constructor with initialization + inline Array(int i, const T val[]); // constructor with assignment built-in array ~Array() { delete[] v_; } // destructor inline void Fill(T val); // fill with same value + inline void Assign(const T val[]); // assign built-in array void SetSize(int i); // setting size int Length() const { return size_; } // get size of array Array<T>& operator=(const Array<T>& a); // assignment @@ -45,11 +47,18 @@ //----------------------------------------------------------------------- // constructor with initialization - template <class T> inline Array<T>::Array(int i, T initialValue) + template <class T> Array<T>::Array(int i, T initialValue) { ArrayNew(i); Fill(initialValue); } + + // constructor with assignment built-in array + template <class T> Array<T>::Array(int i, const T val[]) + { + ArrayNew(i); + Assign(val); + } template <class T> void Array<T>::SetSize(int i) { @@ -62,10 +71,16 @@ { for (int n=0; n<size_; n++) v_[n] = val; } - + + // assign built-in array + template <class T> void Array<T>::Assign(const T val[]) + { + for (int n=0; n<size_; n++) v_[n] = val[n]; + } + template <class T> Array<T>& Array<T>::operator=(const Array<T>& a) { - if (this != &a) // prohibition of self-assignment + if (this != &a) // prohibition of self-assignment { delete [] v_; Copy(a); @@ -76,7 +91,7 @@ template <class T> inline T& Array<T>::operator[](int i) { #ifdef DEBUG_ARRAY_CHECK - Range(i); // out of bound ? + Range(i); // out of bound ? #endif return v_[i]; } @@ -84,7 +99,7 @@ template <class T> inline const T& Array<T>::operator[](int i) const { #ifdef DEBUG_ARRAY_CHECK - Range(i); // out of bounds ? + Range(i); // out of bounds ? #endif return v_[i]; } @@ -101,7 +116,7 @@ template <class T> void Array<T>::Copy(const Array<T>& v_src) { v_ = new T[size_ = v_src.size_]; - for (int i=0; i<size_; i++) v_[i] = v_src.v_[i]; + for (int n=0; n<size_; n++) v_[n] = v_src.v_[n]; } // routine for constructor