Go to the documentation of this file.
42 template<
class T>
class Array;
44 template<
class T>
const Array<T>
concat(
const Array<T> &a,
const T &e);
46 template<
class T>
const Array<T>
concat(
const T &e,
const Array<T> &a);
48 template<
class T>
const Array<T>
concat(
const Array<T> &a1,
51 template<
class T>
const Array<T>
concat(
const Array<T> &a1,
196 template<
class T>
inline
209 template<
class T>
inline
216 template<
class T>
inline
219 template<
class T>
inline
225 template<
class T>
inline
227 : ndata(0), data(0), factory(f)
230 for (
int i = 0; i < a.
ndata; i++)
234 template<
class T>
inline
236 : ndata(0), data(0), factory(f)
238 std::istringstream buffer(values);
242 template<
class T>
inline
244 : ndata(0), data(0), factory(f)
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) {
289 template<
class T>
inline
296 template<
class T>
inline
303 template<
class T>
inline
307 "Array::operator()(i1, i2): Improper indexes.");
309 for (
int i = 0; i < s.
ndata; i++)
310 s.
data[i] = data[i1+i];
314 template<
class T>
inline
318 for (
int i = 0; i < a.
size(); i++) {
320 "Array::operator()(indices): Improper indices.");
321 a(i) = data[indices(i)];
326 template<
class T>
inline
331 for (
int i = 0; i < ndata; i++)
337 template<
class T>
inline
342 for (
int i = 0; i < ndata; i++)
350 std::istringstream buffer(values);
361 for (
int i = 0; i < n; ++i)
362 tmp.
data[i] = data[i];
371 for (
int i = 0; i < n; ++i)
372 tmp.
data[i] = data[ndata-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)
382 tmp.
data[i] = data[pos+i];
394 for (
int i = ndata - 1; i > 0; i--)
408 for (
int i = 0; i < a.
ndata; i++)
410 for (
int i = ndata - 1; i >= a.
ndata; i--)
411 data[i] = data[i-a.
ndata];
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++)
437 out.
data[i] = data[i];
438 for (
int i = 0; i < ndata - a.
ndata; i++)
439 data[i] = data[i+a.
ndata];
440 for (
int i = ndata - a.
ndata; i < 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);
614 set_array(a, str.c_str());
619 #endif // #ifndef ARRAY_H
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Base class for class factories.
Array(int n, const Factory &f=DEFAULT_FACTORY)
Create an Array of size n. 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.
void destroy_elements(T *&ptr, int n)
Destroy an array of Array, Vec or Mat elements.
void free()
Free the storage space allocated by the array.
Base class for class factories and memory allocation functions.
void set_array(Array< T > &a, const std::string &str)
Assign a string to an Array<T>. T must have istream operator>> defined.
Array(const std::string &values, const Factory &f=DEFAULT_FACTORY)
Create an Array from string. An element factory f can be specified.
Array< T > left(int n) const
Get n left elements of the array.
const Array< T > operator()(const Array< int > &indices) const
Sub-array with the elements given by the integer Array.
void set_size(int n, bool copy=false)
Resizing an Array<T>.
Array(const char *values, const Factory &f=DEFAULT_FACTORY)
Create an Array from char*. An element factory f can be specified.
void alloc(int n)
Allocate storage for an array of length n.
int size(const Vec< T > &v)
Length of vector.
Array< T > & operator=(const Array< T > &a)
Assignment operator.
T shift_left(const T &e)
Shift in data at the last position. Return data from position 0.
#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.
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.
T * data
A pointer to the data area.
Miscellaneous functions - header file.
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
const Array< T > operator()(int i1, int i2) const
Sub-array from element i1 to element i2.
std::ostream & operator<<(std::ostream &os, const Array< T > &a)
Output stream for Array<T>. T must have ostream operator<< defined.
const Factory DEFAULT_FACTORY
Default (dummy) factory.
const Array< T > shift_right(const Array< T > &a)
Shift in array at position 0. Return data from the last position.
Vector copy functions for internal use.
virtual ~Array()
Destructor.
bool in_range(int i) const
Check whether index i is in the allowed range.
Array(const Array< T > &a, const Factory &f=DEFAULT_FACTORY)
Copy constructor. An element factory f can be specified.
Array< T > & operator=(const T &e)
Assignment operator.
void set_subarray(int i1, int i2, const T &t)
Set the subarray defined by indicies i1 to i2 the element value t.
void set_length(int n, bool copy=false)
Resizing an Array<T>.
const T & operator()(int i) const
Get the i element.
Array< T > & operator=(const char *values)
Assignment operator.
void swap(int i, int j)
Swap elements i and j.
void set_array(Array< T > &a, const char *values)
Assign a C-style string to an Array<T>. T must have istream operator>> defined.
const Factory & factory
Element factory (by default set to DEFAULT_FACTORY)
T & operator()(int i)
Get the i element.
int length() const
Returns the number of data elements in the array object.
Array(const Factory &f=DEFAULT_FACTORY)
Default constructor. An element factory f can be specified.
Array< T > right(int n) const
Get n right elements of the array.
void set_subarray(int i1, int i2, const Array< T > &a)
Set the subarray defined by indicies i1 to i2 to Array<T> a.
int ndata
The current number of elements in the Array.
int size() const
Returns the number of data elements in the array object.
std::istream & operator>>(std::istream &is, Array< T > &a)
Input stream for Array<T>. T must have istream operator>> defined.
const Array< T > shift_left(const Array< T > &a)
Shift in array at the last position. Return data from position 0.
Error handling functions - header file.
Generated on Sun Jan 3 2021 11:31:33 for IT++ by Doxygen 1.8.20