Diffpack Documentation


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

ArrayGenSimple(Type) Class Reference

general array with operator= and printing. More...

#include <ArrayGenSimple_Type.h>

Inheritance diagram for ArrayGenSimple(Type)::

VecSimple_Type ArrayGenSimplest_Type VecSimplest_Type VecSimplest_Type ArrayGen_Type ArrayGenSel_Type List of all members.

Public Methods

 ArrayGenSimple(Type) ()
 ArrayGenSimple(Type) (int n1)
 ArrayGenSimple(Type) (int n1, int n2)
 ArrayGenSimple(Type) (int n1, int n2, int n3)
 ArrayGenSimple(Type) (const Ptv(int) &n)
 ArrayGenSimple(Type) (const ArrayGenSimple(Type) &X)
 ~ArrayGenSimple(Type) ()
bool redim (int n1)
bool redim (int n1, int n2)
bool redim (int n1, int n2, int n3)
bool redim (const Ptv(int) &n)
bool redim (Type *a, int n, int base=0)
Type& operator() (int i)
Type& operator() (int i, int j)
Type& operator() (int i, int j, int k)
Type& operator() (const Ptv(int) &index)
const Type& operator() (int i) const
const Type& operator() (int i, int j) const
const Type& operator() (int i, int j, int k) const
const Type& operator() (const Ptv(int) &index) const
ArrayGenSimple(Type)& operator= (Type a)
ArrayGenSimple(Type)& operator= (const ArrayGenSimple(Type) &a)
void fill (const Type &a)
void print (Os os, const char *header=NULL, int nentries_per_line=3) const
void printAscii (Os os, const char *header=NULL, int nentries_per_line=3) const
void scan (Is is)

Detailed Description

general array with operator= and printing.

NAME: ArrayGenSimple(Type) - general array with operator= and printing

DESCRIPTION:

The class implements a multi-dimensional array in terms of a standard, one-dimensional C array. The multi-dimensional feature is created by offering subscript operators for one, two, three and "Ptv(int)" indices. The bases of the indices can be arbitrary (see the example below). The only requirement of the array entries is that class "Type" must have a constructor without arguments and "operator=", "operator>>" and "operator<<". There are no assumptions that the entries in the array can be used in arithmetic operations like +, -, * and /.

The present class has class "VecSimplest(Type)" as a virtual base class.


Constructor & Destructor Documentation

ArrayGenSimple(Type)::ArrayGenSimple_Type ( )
 

See documentation for class "ArrayGenSimplest(Type)".

ArrayGenSimple(Type)::ArrayGenSimple_Type ( int n1 )
 

See documentation of one of the overloaded constructor.

ArrayGenSimple(Type)::ArrayGenSimple_Type ( int n1,
int n2 )
 

See documentation of one of the overloaded constructor.

ArrayGenSimple(Type)::ArrayGenSimple_Type ( int n1,
int n2,
int n3 )
 

See documentation of one of the overloaded constructor.

ArrayGenSimple(Type)::ArrayGenSimple_Type ( const Ptv(int) & n )
 

See documentation of one of the overloaded constructor.

ArrayGenSimple(Type)::ArrayGenSimple_Type ( const ArrayGenSimple(Type) & X )
 

See documentation of one of the overloaded constructor.

ArrayGenSimple(Type)::~ArrayGenSimple(Type) ( ) [inline]
 


Member Function Documentation

void ArrayGenSimple(Type)::fill ( const Type & a ) [inline]
 

Reimplemented from VecSimple(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

const Type & ArrayGenSimple(Type)::operator() ( const Ptv(int) & index ) const [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

const Type & ArrayGenSimple(Type)::operator() ( int i,
int j,
int k ) const [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

const Type & ArrayGenSimple(Type)::operator() ( int i,
int j ) const [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

const Type & ArrayGenSimple(Type)::operator() ( int i ) const [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

Type & ArrayGenSimple(Type)::operator() ( const Ptv(int) & index ) [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

Type & ArrayGenSimple(Type)::operator() ( int i,
int j,
int k ) [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

Type & ArrayGenSimple(Type)::operator() ( int i,
int j ) [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

Type & ArrayGenSimple(Type)::operator() ( int i ) [inline]
 

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type).

ArrayGenSimple(Type) & ArrayGenSimple(Type)::operator= ( const ArrayGenSimple(Type) & a )
 

ArrayGenSimple(Type) & ArrayGenSimple(Type)::operator= ( Type a ) [inline]
 

void ArrayGenSimple(Type)::print ( Os os,
const char * header = NULL,
int nentries_per_line = 3 ) const
 

prints the contents of the vector. See documentation of the function "scan".

Reimplemented from VecSimple(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

void ArrayGenSimple(Type)::printAscii ( Os os,
const char * header = NULL,
int nentries_per_line = 3 ) const
 

sets the format to ASCII and calls "print".

Reimplemented from VecSimple(Type).

Reimplemented in ArrayGen(Type).

bool ArrayGenSimple(Type)::redim ( Type * a,
int n,
int base = 0 ) [inline]
 

redimensions the array. With this function one can change the dimension of the array, and the number of entries of each dimension. The base is set to 1.

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

bool ArrayGenSimple(Type)::redim ( const Ptv(int) & n ) [inline]
 

See documentation of one of the overloaded functions.

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

bool ArrayGenSimple(Type)::redim ( int n1,
int n2,
int n3 ) [inline]
 

See documentation of one of the overloaded functions.

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

bool ArrayGenSimple(Type)::redim ( int n1,
int n2 ) [inline]
 

See documentation of one of the overloaded functions.

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

bool ArrayGenSimple(Type)::redim ( int n1 ) [inline]
 

See documentation of one of the overloaded functions.

Reimplemented from ArrayGenSimplest(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).

void ArrayGenSimple(Type)::scan ( Is is )
 

reads the vector from an "Is" object. The entries of an array can be written and read in two main formats, the binary format or the ascii format. When "print" is invoked, the format is determined by the state of the "Os" object (the result of the "getFormat" function). Each of the ascii/binary formats can have a header or not. The header is present if "print" is called with a non-"NULL" "header" string. In "scan" one detects the header if the first non-space character is "[". If the header is present, its syntax is like this:

      [size]X text $
where "size" is the size of the array (for a vector it is the length, for a matrix it is a string on the form "rxc", where "r" is the number of rows and "c" is the number of columns), "X" is a character that equals "b" in case of a binary format or space in case of an ascii format. "text" is the "header" string given to "print". In "scan" this string is ignored, but it is available in the internal "Is" buffer so the programmer can in principle extract the header after "scan" is called.

After the header a character "@" follows if the format is binary, if not, a space appears. Hence one can detect whether the format is binary or ascii even when the header does not appear. After the "@", the binary format has two binary numbers: The number of array entries and the size of each entry.

If the header is present and the format is ascii, there will be "nentires_per_line" array entries on each output line. There array index will also be written. In all other cases, the array entries are written with no index, but in the ascii format there will be an extra space.

With a header the "scan" functions can read the dimensions of the array and call "redim" before reading the entries. Without a header the dimensions of the array must be correct BEFORE "scan" is called. In other words, a file containing the array entries only can only be read when the number of entries is known. The function "scanFromFile" can, however, read an unknown number of entries from file into a vector with wrong dimensions (see documentation below). If the format is binary, the "scan" function detects the array length and redimensions the array, but a warning is issued. The reason is that, without a header, the main rule is that the programmer must have redimensioned the array on beforehand.

After the header the data appears. If they are written in binary mode, the first non-white character (after the header) is "@". Then, in binary format, the number of items must appear and after that the size of each item. Then the data appear in binary format. If the "@" character is not present, the data appear in ascii format.

Let us present some examples on valid data files. First the most comprehensive form:

      [3]  Example of a data file with much additional information such as
      indices for each vector entry. This file is in ascii format.
  
      (1)=1.2
      (2)=3.4
      (3)=1.8

Here is an ascii format file with as little information as possible (a NULL header was given when calling "print":

      1.2 3.4 1.8
An equivalent form may be

      1.2 3.4
      1.8

Finally we show a binary file without header. To indicate a binary number (f.ex. 8.1) we use the notation [B8.1].

      @[B3][B4][B1.2][B3.4][B1.8]
Observe that the item is a float and that the size of the item is "sizeof(float)" which equals 4. There is a comprehensive demonstration and test program for the various ascii and binary file formats of arrays in the directory "$DPR/src/app/class-verify/category2/arrayprint".

Reimplemented from VecSimple(Type).

Reimplemented in ArrayGen(Type), and ArrayGenSel(Type).


The documentation for this class was generated from the following file:
Copyright © 2003 inuTech GmbH. All rights reserved.