#include <VecSimple_Type.h>
Inheritance diagram for VecSimple(Type)::

Public Methods | |
| VecSimple(Type) () | |
| VecSimple(Type) (int length) | |
| VecSimple(Type) (Type *a, int n, int base=0) | |
| VecSimple(Type) (const VecSimple(Type) &X) | |
| ~VecSimple(Type) () | |
| void | fill (const Type &value) |
| VecSimple(Type)& | operator= (const Type &value) |
| VecSimple(Type)& | operator= (const VecSimple(Type) &X) |
| VecSimple(Type)& | append (const VecSimple(Type) &X) |
| bool | grow (int length) |
| void | print (Os os, const char *header=NULL, int nentries_per_line=3) const |
| void | scan (Is is) |
| void | printAsIndex (Os os) const |
| void | printAscii (Os os, const char *header=NULL, int nentries_per_line=3) const |
| void | scanFromFile (const String &filename) |
Friends | |
| Os& | operator<< (Os &os, const VecSimple(Type) &x) |
| Is& | operator>> (Is &is, VecSimple(Type) &x) |
NAME: VecSimple(Type) - simple vector, base=1, no arithmetic operations
DESCRIPTION:
The class implements a standard vector type derived from "VecSimplest(Type)". The public interface consists of various operations such as subscripting (w/array-range-check if desired), assignment operators, fill functions, print and scan functions, etc. The subscript operator assumes that the base equals 1. If other bases are desired, the "ArrayGenSimplest(Type)" or "ArrayGen(Type)" classes can be used.
No arithmetic operations are used in any of the member functions. Hence this class is suited as a general vector class for various objects. The only requirement is that the object has a constructor with no arguments so that an array of the class'' objects can be allocated by "new". In addition, the class must define "operator=", "operator<<" and "operator>>". Macros for generating default versions of these operators are collected in the file "default_op.h".
|
|
Several constructors are available. The constructor without parameters allocates no memory. To allocate the proper amount of memory at a later stage, the "redim" function can be used. Another constructor takes the number of entries in the vector as parameter and allocates memory for the corresponding vector representation. Finally, a copy-constructor is available. To initialize the vector entries one can use the member functions "fill" or "operator()". |
|
|
See documentation of one of the overloaded constructor. |
|
|
See documentation of one of the overloaded constructor. |
|
|
See documentation of one of the overloaded constructor. |
|
|
|
|
|
appends the vector "X" to the current vector. |
|
|
Reimplemented in ArrayGen(Type), ArrayGenSel(Type), ArrayGenSimple(Type), and Vec(Type). |
|
|
as "VecSimplest redim", but the contents of the existing vector are preserved (like the "realloc" function in C). The supplied length can also be smaller than the original length, providing a ""shrink"" functionality. |
|
|
See documentation of one of the overloaded functions. |
|
|
the version that takes another "VecSimple(Type)" as argument makes the object a copy of the vector argument, that is, the object is redimensioned according to the dimensions of "X" and thereafter each entry is set equal to the corresponding entry in "X". The version that takes a "Type" value as argument sets all the entries in the vector to have this value. Reimplemented in ArrayGen(Type), ArrayGenSel(Type), Vec(Type), and VecSort(Type). |
|
|
prints the contents of the vector. See documentation of the function "scan". Reimplemented in ArrayGen(Type), ArrayGenSel(Type), ArrayGenSimple(Type), and Vec(Type). |
|
|
prints the vector as an index, that is on the form
(x1,x2,x3,x4,x5,...)
|
|
|
sets the format to ASCII and calls "print". Reimplemented in ArrayGen(Type), and ArrayGenSimple(Type). |
|
|
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 $
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
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]
Reimplemented in ArrayGen(Type), ArrayGenSel(Type), ArrayGenSimple(Type), and Vec(Type). |
|
|
enables an unknown numbers of "Type" objects to be read from file into a possibly empty vector. The objects must appear on the file without any text. Hence, this function cannot read a file written by "print" with a comment. First, the number of objects on the file is found, then the vector is correctly redimensioned and then an ordinary "scan" function is called. Only ascii files can be read by the present implementation (that is also the most useful application of a function like this). |
|
|
is defined in terms of the "print" function. |
|
|
is defined in terms of the "scan" function. |