42template<
class T>
class Array;
196template<
class T>
inline
209template<
class T>
inline
216template<
class T>
inline
219template<
class T>
inline
225template<
class T>
inline
230 for (
int i = 0; i < a.
ndata; i++)
234template<
class T>
inline
238 std::istringstream buffer(values);
242template<
class T>
inline
246 std::istringstream buffer(values);
266 int old_ndata =
ndata;
272 for (
int i = 0; i <
min; ++i) {
276 for (
int i =
min; i <
size; ++i) {
289template<
class T>
inline
296template<
class T>
inline
303template<
class T>
inline
307 "Array::operator()(i1, i2): Improper indexes.");
309 for (
int i = 0; i < s.
ndata; i++)
314template<
class T>
inline
318 for (
int i = 0; i < a.
size(); i++) {
320 "Array::operator()(indices): Improper indices.");
321 a(i) =
data[indices(i)];
326template<
class T>
inline
331 for (
int i = 0; i <
ndata; i++)
337template<
class T>
inline
342 for (
int i = 0; i <
ndata; i++)
350 std::istringstream buffer(values);
361 for (
int i = 0; i < n; ++i)
371 for (
int i = 0; i < n; ++i)
379 it_assert_debug((pos >= 0) && (n > 0) && (pos + n <=
ndata),
"Array::mid(): Indexing out of range");
381 for (
int i = 0; i < n; ++i)
394 for (
int i =
ndata - 1; i > 0; i--)
408 for (
int i = 0; i < a.
ndata; i++)
412 for (
int i = 0; i < a.
ndata; i++)
423 for (
int i = 0; i <
ndata - 1; i++)
436 for (
int i = 0; i < a.
ndata; i++)
450 "Array::swap(): Indices out of range.");
460 if (i1 == -1) i1 =
ndata - 1;
461 if (i2 == -1) i2 =
ndata - 1;
464 "Array<T>::set_subarray(): Indices out of range.");
465 it_assert_debug(i2 >= i1,
"Array<T>::set_subarray(): i2 >= i1 necessary.");
474 if (i1 == -1) i1 =
ndata - 1;
475 if (i2 == -1) i2 =
ndata - 1;
478 "Array<T>::set_subarray(): Indices out of range");
479 it_assert_debug(i2 >= i1,
"Array<T>::set_subarray(): i2 >= i1 necessary");
481 for (
int i = i1; i <= i2; i++)
490 for (
int i = 0; i < a.
size(); i++)
504 for (
int i = 0; i < a.
size(); i++)
515 for (
int i = 0; i < a1.
size(); i++)
517 for (
int i = 0; i < a2.
size(); i++)
518 temp(a1.
size() + i) = a2(i);
530 for (
int i = 0; i < a1.
size(); i++)
532 for (
int i = 0; i < a2.
size(); i++)
533 temp(a1.
size() + i) = a2(i);
534 for (
int i = 0; i < a3.
size(); i++)
535 temp(a1.
size() + a2.
size() + i) = a3(i);
548 for (
int i = 0; i < a.
size() - 1; i++)
551 os << a(a.
size() - 1);
564 int nrof_elements = 0;
571 is.setstate(std::ios_base::failbit);
577 if (++nrof_elements > a.
size()) {
580 is >> a(nrof_elements - 1);
583 if (a.
size() > nrof_elements) {
588 is.setstate(std::ios_base::failbit);
602 std::istringstream buffer(values);
void alloc(int n)
Allocate storage for an array of length n.
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
Array(int n, const Factory &f=DEFAULT_FACTORY)
Create an Array of size n. An element factory f can be specified.
void set_array(Array< T > &a, const char *values)
Assign a C-style string to an Array<T>. T must have istream operator>> defined.
bool in_range(int i) const
Check whether index i is in the allowed range.
void free()
Free the storage space allocated by the array.
void set_length(int n, bool copy=false)
Resizing an Array<T>.
int size() const
Returns the number of data elements in the array object.
Array< T > & operator=(const Array< T > &a)
Assignment operator.
Array(const Array< T > &a, const Factory &f=DEFAULT_FACTORY)
Copy constructor. An element factory f can be specified.
void set_array(Array< T > &a, const std::string &str)
Assign a string to an Array<T>. T must have istream operator>> defined.
int ndata
The current number of elements in the Array.
const T & operator()(int i) const
Get the i element.
Array< T > & operator=(const T &e)
Assignment operator.
void swap(int i, int j)
Swap elements i and j.
void set_subarray(int i1, int i2, const Array< T > &a)
Set the subarray defined by indicies i1 to i2 to Array<T> a.
const Factory & factory
Element factory (by default set to DEFAULT_FACTORY)
Array< T > left(int n) const
Get n left elements of the array.
Array(const Factory &f=DEFAULT_FACTORY)
Default constructor. An element factory f can be specified.
T shift_left(const T &e)
Shift in data at the last position. Return data from position 0.
virtual ~Array()
Destructor.
Array(const char *values, const Factory &f=DEFAULT_FACTORY)
Create an Array from char*. An element factory f can be specified.
T shift_right(const T &e)
Shift in data at position 0. Return data from the last position.
const Array< T > shift_right(const Array< T > &a)
Shift in array at position 0. Return data from the last position.
std::istream & operator>>(std::istream &is, Array< T > &a)
Input stream for Array<T>. T must have istream operator>> defined.
const Array< T > operator()(const Array< int > &indices) const
Sub-array with the elements given by the integer Array.
const Array< T > shift_left(const Array< T > &a)
Shift in array at the last position. Return data from position 0.
void set_subarray(int i1, int i2, const T &t)
Set the subarray defined by indicies i1 to i2 the element value t.
const Array< T > operator()(int i1, int i2) const
Sub-array from element i1 to element i2.
T & operator()(int i)
Get the i element.
Array< T > & operator=(const char *values)
Assignment operator.
std::ostream & operator<<(std::ostream &os, const Array< T > &a)
Output stream for Array<T>. T must have ostream operator<< defined.
Array(const std::string &values, const Factory &f=DEFAULT_FACTORY)
Create an Array from string. An element factory f can be specified.
T * data
A pointer to the data area.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
friend const Array< T > concat(const Array< T > &a1, const T &e)
Append element e to the end of the Array a.
int length() const
Returns the number of data elements in the array object.
Array< T > right(int n) const
Get n right elements of the array.
Base class for class factories.
Vector copy functions for internal use.
Base class for class factories and memory allocation functions.
#define it_assert_debug(t, s)
Abort if t is not true and NDEBUG is not defined.
T min(const Vec< T > &in)
Minimum value of vector.
Error handling functions - header file.
Miscellaneous functions - header file.
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
void destroy_elements(T *&ptr, int n)
Destroy an array of Array, Vec or Mat elements.
const Factory DEFAULT_FACTORY
Default (dummy) factory.
void create_elements(T *&ptr, int n, const Factory &)
Create an n-length array of T to be used as Array, Vec or Mat elements.