Array of variable size.
More...
#include "Imagine/Common.h"
template<typename T>
class Imagine::Array< T >
Array of variable size. Memory is reference counted, i.e.:
- a=b results in a and b sharing the same memory
- the last object using memory frees it when it dies
- use clone() when this sharing is not desired
- Parameters
-
- Examples:
- Common/test/test.cpp.
◆ Array() [1/6]
Constructs an unallocated array of variables of type T
◆ Array() [2/6]
Constructs an allocated array of size variables of type T
- Parameters
-
◆ Array() [3/6]
Constructs an array pointing to variables of type T stored at an already allocated memory. Does not allocate fresh memory. This memory must indeed stay available during object life. Does not free given memory at object destruction unless handleDelete=true.
- Parameters
-
ptr | address of memory |
size | array size |
handleDelete | delete memory at destruction? (default=false) |
char t[4]={'a','b','c','d'};
Array<char> c(t,4);
char* t2=new char[3];
Array<char> c2(t2,3,true);
◆ Array() [4/6]
Constructs an array from another one (sharing memory!)
- Parameters
-
◆ Array() [5/6]
template<typename T>
template<typename T2 >
Constructs an array of type T from one of another type (thus without sharing memory!)
- Parameters
-
- Template Parameters
-
◆ Array() [6/6]
Constructs an array of variables of type T from a list.
- Parameters
-
list<char>l;
l.push_front('a');
Array<char>e(l);
◆ ~Array()
Reference counted desctructor: frees memory if the object is the last one to use it.
◆ begin() [1/2]
◆ begin() [2/2]
◆ clone()
Clones: creates a new array, with fresh memory, copying values to it
- Returns
- cloned array
◆ data() [1/2]
Pointer to data for reading and writing
- Returns
- pointer to array elements
◆ data() [2/2]
Pointer to data for reading only
- Returns
- const pointer to elements
◆ empty()
True if array is not allocated
- Returns
- emptyness
if (a.empty())
cout<< "a is empty" << endl;
◆ end() [1/2]
◆ end() [2/2]
◆ fill()
Fills with constant value
- Parameters
-
x | value to be copied to each element |
- Returns
- self reference
◆ getSubArray()
Construct a sub array, i.e. a new array with fresh memory, initialized from a part of values of *this
- Parameters
-
offset | position of first element of sub array |
size | size of sub array |
- Returns
- sub array
◆ operator!=()
Inequality test (component wise)
- Parameters
-
- Returns
- true if *this is different from b
◆ operator=() [1/2]
Assigns from another Array (sharing its memory)
- Parameters
-
- Returns
- self reference
◆ operator=() [2/2]
template<typename T>
template<typename T2 >
Assign from an array of another type (thus without sharing memory!)
- Parameters
-
- Template Parameters
-
- Returns
- self reference
◆ operator==()
Equality test, component wise, i.e. if arrays are of the same size and with the same values
- Parameters
-
- Returns
- true if *this equals A
if (a==b) cout << "a equals b" << endl;
◆ operator[]() [1/2]
Reads ith element
- Parameters
-
i | element index (from 0 to size-1) |
- Returns
- Const reference to ith element.
◆ operator[]() [2/2]
Writes ith element
- Parameters
-
i | element index (from 0 to size-1) |
- Returns
- Reference to ith element.
◆ setSize()
Change array size:
- (re)allocates fresh memory
- data is not copied from old to new memory
- concerns only this object, not the ones that shared the old memory with it (and continue to use the old memory)
- if the new size is the same as the old one, does nothing
◆ size()
Number of elements
- Returns
- size
◆ operator<<
template<typename T>
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const Array< T > & |
A |
|
) |
| |
|
friend |
Writes Array to stream (size and values)
- Parameters
-
out | output stream |
A | Array to write |
- Returns
- updated stream
out.open("tmp.txt");
out << a << endl;
◆ operator>>
template<typename T>
std::istream& operator>> |
( |
std::istream & |
in, |
|
|
Array< T > & |
A |
|
) |
| |
|
friend |
Reads and allocates Array from stream (providing size and values)
- Parameters
-
in | input stream |
A | Array to read |
- Returns
- updated stream
in.open("tmp.txt");
in >> a;
◆ prange
template<typename T>
std::pair<T,T> prange |
( |
const Array< T > & |
A | ) |
|
|
friend |
Compute pointwise min and pointwise max of component values (provided pointwise comparisons are defined for type T, e.g. FVector)
- Parameters
-
- Returns
- pair of pmin, pmax values
Array< Coords<2> > f(2);
f[0]=Coords<2>(1,5);
f[1]=Coords<2>(4,2);
◆ range
template<typename T>
std::pair<T,T> range |
( |
const Array< T > & |
A | ) |
|
|
friend |
Compute min and max of component values (provided comparisons are defined for type T)
- Parameters
-
- Returns
- pair of min,max values
Array< Coords<2> > f(2);
f[0]=Coords<2>(1,5);
f[1]=Coords<2>(4,2);
◆ read
template<typename T>
void read |
( |
std::istream & |
in, |
|
|
Array< T > & |
A |
|
) |
| |
|
friend |
Reads and allocates Array from binary stream (providing size and values)
- Parameters
-
in | input stream |
A | Array to read |
ifstream in("tmp.bin",ios::binary);
◆ write
template<typename T>
void write |
( |
std::ostream & |
out, |
|
|
const Array< T > & |
A |
|
) |
| |
|
friend |
Writes Array to binary stream (size and values)
- Parameters
-
out | output stream |
A | Array to write |
ofstream out("tmp.bin",ios::binary);
The documentation for this class was generated from the following file:
- /home/pascal/Ponts/svn/ImagineQt/Imagine/Common/src/Imagine/Common/Array.h