Programming Reference:LabelIndex Class
Location
src/shared/types
Synopsis
An object of type LabelIndex represents a mapping of string labels to array indices. Such string label indices are used in parameters and signals.
Methods
LabelIndex()
Initializes the LabelIndex object to a "trivial" index, i.e. labels are initialized to one-based numerical indices "1", "2", "3", ...
bool Exists(string Label)
Returns true if the specified label exists in the index, false otherwise.
Clear()
Resets the index to a trivial index.
Resize(Size)
Adapts index size to the specified number of entries.
WriteToStream(ostream), ReadFromStream(istream)
Writes/reads the index object from/to the specified stream. Stream representation is human readable, and corresponds to the way indices are specified in a parameter line. Beginning with an opening bracket, indices are listed in sequence, separated with space characters. Brackets and whitespace that are part of labels are encoded as described here.
Properties
bool IsTrivial (r)
True if all labels match string representations of one-based indices "1", "2", "3", ...
int Size (r)
The number of entries in the index, i.e. the number of indices that can be addressed by string labels.
Operators
The subscript operator [] may be applied to a LabelIndex object with a string or a numerical argument.
In the first case, the zero-based index corresponding to the specified label will be returned, as in the following example:
int idx = Parameter( "MyParameter" ).RowLabels()["SecondRow"];
will return 1 if "SecondRow" exists as a string, and refers to the parameter's second row. For nonexistent labels, an index of zero will be returned, i.e. a nonexistent label will be mapped to the first entry.
In the second case, specifying a zero-based index will provide access to the string label associated with that index:
string label = Parameter( "MyParameter" ).RowLabels()[1];
will return "SecondRow" if this is the label specified for the second entry.
See also
Technical Reference:Parameter Definition, Programming Reference:Signals, Programming Reference:PhysicalUnit Class