Imagine++
Imagine::FArray< T, S > Class Template Reference

Array of fixed size. More...

#include "Imagine/Common.h"

Inheritance diagram for Imagine::FArray< T, S >:
Imagine::FVector< int, dim > Imagine::FVector< double, 3 > Imagine::FVector< float, 3 > Imagine::Coords< dim > * Imagine::Coords< dim > & Imagine::Coords< 2 > Imagine::Coords< dim >

Public Types

typedef const T * const_iterator
 Const iterator type.
 
typedef T * iterator
 Iterator type.
 

Public Member Functions

 FArray ()
 Empty constructor.
 
template<typename T2>
 FArray (const FArray< T2, S > &a)
 Copy constructor.
 
 FArray (const T &v)
 Constructor with constant value.
 
template<typename T2>
 FArray (const T2 t[S])
 Constructor from C array.
 
 FArray (T v0, T v1)
 2D alias.
 
 FArray (T v0, T v1, T v2)
 3D alias.
 
 FArray (T v0, T v1, T v2, T v3)
 4D alias.
 
iterator begin ()
 Begin iterator.
 
const_iterator begin () const
 Begin const iterator.
 
template<typename T2>
FArraycopy (const FArray< T2, S > &b)
 Copy.
 
template<typename T2>
FArraycopy (const T2 t[S])
 C array of different type copy.
 
T * data ()
 Data pointer (write).
 
const T * data () const
 Data pointer (read).
 
bool empty () const
 Is empty.
 
iterator end ()
 End iterator.
 
const_iterator end () const
 End const iterator.
 
FArrayfill (const T &v)
 Filling.
 
bool operator!= (const FArray &b) const
 Inequality test.
 
template<typename T2>
FArrayoperator= (const FArray< T2, S > &b)
 Assignment.
 
bool operator== (const FArray &b) const
 Equality test.
 
T & operator[] (int i)
 Write access.
 
const T & operator[] (int i) const
 Read access.
 
int size () const
 Size.
 

Protected Attributes

_data [S]
 internal storage.
 

Friends

std::ostream & operator<< (std::ostream &out, const FArray &a)
 ASCII write.
 
std::istream & operator>> (std::istream &in, FArray &a)
 ASCII read.
 
std::pair< T, T > range (const FArray &a)
 Range.
 
void read (std::istream &in, FArray &a)
 Binary read.
 
void write (std::ostream &out, const FArray &a)
 Binary write.
 

Detailed Description

template<typename T, int S>
class Imagine::FArray< T, S >

Fixed size arrays.

Parameters
Tvalue type
Sarray size
Examples
Common/test/test.cpp.

Constructor & Destructor Documentation

◆ FArray() [1/7]

template<typename T, int S>
Imagine::FArray< T, S >::FArray ( )
inline

Constructs an uninitialized array of S variables of type T

FArray<char,3> a; // uninitialized
FArray()
Empty constructor.
Definition FArray.h:34

◆ FArray() [2/7]

template<typename T, int S>
Imagine::FArray< T, S >::FArray ( const T & v)
inlineexplicit

Constructs an array of S variables of type T, each initialized to v

Parameters
vvalue used for initialization
FArray<char,3> b('.'); // filled with constant value

◆ FArray() [3/7]

template<typename T, int S>
template<typename T2>
Imagine::FArray< T, S >::FArray ( const T2 t[S])
inline

Constructs from a C array (with a possibly different type)

Parameters
tC array used for initialization
Template Parameters
T2value type of t
char tt[]={'a','b','c'}; // filled from C array
FArray<char,3> c(tt); // (copying array into fresh memory)

◆ FArray() [4/7]

template<typename T, int S>
template<typename T2>
Imagine::FArray< T, S >::FArray ( const FArray< T2, S > & a)
inline

Constructs from another FArray (with a possibly different type)

Parameters
aFArray to be copied (has to be of the same size)
Template Parameters
T2value type of a
FArray<char,3> dd(c); // copy constructor
FArray<char,3> di(c); // copy from different type

◆ FArray() [5/7]

template<typename T, int S>
Imagine::FArray< T, S >::FArray ( T v0,
T v1 )
inline

Short constructor for 2D FArray

Parameters
v0value for index 0 component
v1value for index 1 component
FArray<char,2> e('a','b'); // alias for 2D case

◆ FArray() [6/7]

template<typename T, int S>
Imagine::FArray< T, S >::FArray ( T v0,
T v1,
T v2 )
inline

Short constructor for 3D FArray

Parameters
v0value for index 0 component
v1value for index 1 component
v2value for index 2 component
FArray<char,3> f('a','b','c'); // alias for 3D case

◆ FArray() [7/7]

template<typename T, int S>
Imagine::FArray< T, S >::FArray ( T v0,
T v1,
T v2,
T v3 )
inline

Short constructor for 4D FArray

Parameters
v0value for index 0 component
v1value for index 1 component
v2value for index 2 component
v3value for index 3 component
FArray<char,4> g('a','b','c','d'); // alias for 4D case

Member Function Documentation

◆ begin() [1/2]

template<typename T, int S>
iterator Imagine::FArray< T, S >::begin ( )
inline

Begin iterator

for (FArray<char,3>::iterator it=f.begin() ; it!=f.end(); ++it) // Iterator
T * iterator
Iterator type.
Definition FArray.h:25
*it='x'; // ...

◆ begin() [2/2]

template<typename T, int S>
const_iterator Imagine::FArray< T, S >::begin ( ) const
inline

Begin const iterator

for (FArray<char,3>::const_iterator cit=f.begin() ; cit!=f.end(); ++cit) // const iterator
const T * const_iterator
Const iterator type.
Definition FArray.h:27
cout << *cit << endl; // ...

◆ copy() [1/2]

template<typename T, int S>
template<typename T2>
FArray & Imagine::FArray< T, S >::copy ( const FArray< T2, S > & b)
inline

Copies another FArray of possibly different type but same size.

Parameters
bC array to be copied into FArray
Template Parameters
T2value type of b
Returns
self reference
di.copy(tt); // Copies C array of different type into FArray

◆ copy() [2/2]

template<typename T, int S>
template<typename T2>
FArray & Imagine::FArray< T, S >::copy ( const T2 t[S])
inline

Copies C array of different type

Parameters
tC array to be copied into FArray
Template Parameters
T2value type of t
Returns
self reference
di.copy(tt); // Copies C array of different type into FArray
Examples
Common/test/test.cpp.

◆ data() [1/2]

template<typename T, int S>
T * Imagine::FArray< T, S >::data ( )
inline

Pointer to data for writing

Returns
pointer to FArray elements
a.data()[0]=x; // data pointer (write)

◆ data() [2/2]

template<typename T, int S>
const T * Imagine::FArray< T, S >::data ( ) const
inline

Pointer to data for reading

Returns
const pointer to FArray elements
y=a.data()[1]; // data pointer (read)
Examples
Common/test/test.cpp.

◆ empty()

template<typename T, int S>
bool Imagine::FArray< T, S >::empty ( ) const
inline

True if FArray is empty

Returns
false

◆ end() [1/2]

template<typename T, int S>
iterator Imagine::FArray< T, S >::end ( )
inline

End iterator

for (FArray<char,3>::iterator it=f.begin() ; it!=f.end(); ++it) // Iterator
*it='x'; // ...

◆ end() [2/2]

template<typename T, int S>
const_iterator Imagine::FArray< T, S >::end ( ) const
inline

End const iterator

for (FArray<char,3>::const_iterator cit=f.begin() ; cit!=f.end(); ++cit) // const iterator
cout << *cit << endl; // ...

◆ fill()

template<typename T, int S>
FArray & Imagine::FArray< T, S >::fill ( const T & v)
inline

Fills with constant value

Parameters
vvalue to be copied to each element
Returns
self reference
a.fill('x'); // Fills with constant value
Examples
Common/test/test.cpp.

◆ operator!=()

template<typename T, int S>
bool Imagine::FArray< T, S >::operator!= ( const FArray< T, S > & b) const
inline

Inequality test (component wise)

Parameters
bFArray for comparison
Returns
true if *this is different from b
for (FArray<char,3>::const_iterator cit=f.begin() ; cit!=f.end(); ++cit) // const iterator

◆ operator=()

template<typename T, int S>
template<typename T2>
FArray & Imagine::FArray< T, S >::operator= ( const FArray< T2, S > & b)
inline

Assigns from another FArray of possibly different type but same size

Parameters
bSource FArray
Template Parameters
T2value type of b
Returns
self reference
dd=b; // assignment (copies values)
di=a; // assignment from different type

◆ operator==()

template<typename T, int S>
bool Imagine::FArray< T, S >::operator== ( const FArray< T, S > & b) const
inline

Equality test (component wise)

Parameters
bFArray for comparison
Returns
true if *this equals b
if (a==b) cout << "a equals b" << endl; // ==

◆ operator[]() [1/2]

template<typename T, int S>
T & Imagine::FArray< T, S >::operator[] ( int i)
inline

Writes ith element

Parameters
ielement index (from 0 to S-1)
Returns
Reference to ith element.
c[0]=x; // write access []

◆ operator[]() [2/2]

template<typename T, int S>
const T & Imagine::FArray< T, S >::operator[] ( int i) const
inline

Reads ith element

Parameters
ielement index (from 0 to S-1)
Returns
const reference to ith element.
x=a[0]; // read access []

◆ size()

template<typename T, int S>
int Imagine::FArray< T, S >::size ( ) const
inline

Dimension of FArray

Returns
size
cout << a.size() << endl; // size
Examples
Common/test/test.cpp.

Friends And Related Symbol Documentation

◆ operator<<

template<typename T, int S>
std::ostream & operator<< ( std::ostream & out,
const FArray< T, S > & a )
friend

Writes FArray to stream

Parameters
outoutput stream
aFArray to write
Returns
updated stream
out.open("tmp.txt"); // ASCII write
out << a << endl; // ...

◆ operator>>

template<typename T, int S>
std::istream & operator>> ( std::istream & in,
FArray< T, S > & a )
friend

Reads FArray from stream

Parameters
ininput stream
aFArray to read
Returns
updated stream
in.open("tmp.txt"); // ASCII read
in >> a; // ...

◆ range

template<typename T, int S>
std::pair< T, T > range ( const FArray< T, S > & a)
friend

Compute min and max of component values (provided comparisons are defined for type T)

Parameters
ainpu array
Returns
pair of min,max values
/*pair<char,char> r =*/ range(a); // range
friend std::pair< T, T > range(const FArray &a)
Range.
Definition FArray.h:251

◆ read

template<typename T, int S>
void read ( std::istream & in,
FArray< T, S > & a )
friend

Reads FArray from binary stream

Parameters
ininput stream
aFArray to read
ifstream in("tmp.bin",ios::binary); // binary read
read(in,a); // ...
friend void read(std::istream &in, FArray &a)
Binary read.
Definition FArray.h:280

◆ write

template<typename T, int S>
void write ( std::ostream & out,
const FArray< T, S > & a )
friend

Writes FArray to binary stream

Parameters
outoutput stream
aFArray to write
ofstream out("tmp.bin",ios::binary); // binary write
write(out,a); // ...
friend void write(std::ostream &out, const FArray &a)
Binary write.
Definition FArray.h:269

The documentation for this class was generated from the following file: