A single type variable set is a collection of unidimensional
variables of the same type and are divided in symbols and arrays. ProBT represents these sets by the object classes plSymbol and plArray respectively. A plSymbol contains
one and only one unidimensional variable. A plArray contains
all the variables of an dimensional array of symbols.
For example, consider the variables types
id
and
relative_velocity
. The
following lines are single type variable sets declarations:
//A single one dimensional variable plSymbol article("art_id", id); //A one dimensional array plArray oneDvelocity("Va", relative_velocity, 1, 3); //A two dimensional array plArray twoDvelocity("Vb", relative_velocity, 2, 3, 2); //A three dimensional array plArray threeDvelocity("Vc",relative_velocity, 3, 2, 2, 2);
The first argument of plSymbol and plArray is the print
variable name, a string used when printing the variables on the set
(e.g. when using ``cout
''). The second argument corresponds, in both
classes, to the variable type. For a plArray the argument that
follows the variable type corresponds to the array dimension. If the
value of the dimension parameter is , then
other parameters
follows. These last parameters indicate the size for each
dimension. Our type examples are then:
Each of the elements on a plArray can be access by using the C++ operator ``()''. For example, we can print the plSymbols on a plArray by doing:
cout<<"oneDvelocity(0) = "<<oneDvelocity(0)<<"\n"; cout<<"twoDvelocity(1, 0) = "<<twoDvelocity(1, 0)<<"\n"; cout<<"threeDvelocity(1, 0, 1) = "<<threeDvelocity(1, 0, 1)<<"\n";
generating:
oneDvelocity(0) = Va0 twoDvelocity(1, 0) = Vb(1,0) threeDvelocity(1, 0, 1) = Vc(1,0,1)
It should be noticed that the operator''()'' returns a plSymbol
and that the number of arguments on the ``()'' operator depends on the
dimension of plArray. The names of the variables on a plArray is generated automatically by combining the print name
argument and the indexes.
Always be aware of passing the correct number of arguments to the plArray constructor, and the ``()'' operator. Passing more arguments than the dimension is not good, however it will not cause any error, extra parameters will be ignored. On the other hand, the lack of arguments will generate invalid access, and consequently a run time error such as the well known ``segmentation fault''. The following statements depict this situation by using the previously defined plArrays:
cout<<oneDvelocity(0, 0, 1)<<"\n"; //ATTENTION it's one dimensional cout<<twoDvelocity(1)<<"\n"; //ERROR it's two dimensional cout<<threeDvelocity(1, 0)<<"\n"; //ERROR it's three dimensional
Similarly, the following examples are typical misuses of plArray constructor:
//ATTENTION dimension = 1, and then two sizes are given plArray speed("velocity", relative_velocity, 1, 10, 20); //ERROR dimension = 4, and then only three sizes are given plArray speed("velocity", relative_velocity, 4, 10, 15, 40); //ERROR dimension = 3, and then only one size is given plArray speed("velocity", relative_velocity, 3, 4);