Imagine++
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
Imagine::FArray< T, S > Class Template Reference

Array of fixed size. More...

#include "Imagine/Common.h"

Public Types

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

Public Member Functions

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

Protected Attributes

_data [S]
 internal storage.
 

Friends

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

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, and Graphics/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() [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() [5/7]

template<typename T, int S>
Imagine::FArray< T, S >::FArray ( v0,
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 ( v0,
v1,
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 ( v0,
v1,
v2,
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

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
*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
cout << *cit << endl; // ...

◆ copy() [1/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

◆ copy() [2/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

◆ data() [1/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)

◆ data() [2/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)

◆ 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

◆ 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)

◆ 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>
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 []

◆ operator[]() [2/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 []

◆ size()

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

Dimension of FArray

Returns
size
cout << a.size() << endl; // size

Friends And Related Function 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

◆ 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); // ...

◆ 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); // ...


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