General cursor methods |
Top Previous Next |
Scripts > Class elements and c++ instructions > Interpreted C++ instructions > Container > cursor > General cursor methods
Cursors have read only access to the connected container. The cursors of different kinds of containers (vector and map) have a set of common methods, which will now be listed and explained.. Thereby an element is either a single value contained in a vector or a pair of values contained in a map.
a) Information:
bool isValid() const
returns, whether the cursor is connected to a container. For an internal cursor this is always the case.
bool hasCurrent() const
returns true, if the cursor is positioned on an actual element. Otherwise false will be returned.
bool empty() const
returns true, if there is no element in the container. If the container is invalid, true will be returned.
unsigned int size() const
returns the number of elements in the container. If the container is invalid, 0 will be returned.
value_type value() const
returns the value of the current element. If there is no current element, the default value of the value type will be returned: an empty string for the string type, 0 for numerical types and false for the bool type.
If the vaue type is node, you can call value().label() or value().value() to get the label or value of the node.
bool gotoNext()
sets the cursor on the next element. So it becomes the current element. If the current element was the last element of the list, gotoNext returns false and the cursor position becomes invalid. If the cursor position was invalid, it will be set on the first element by gotoNext.
bool gotoPrev()
sets the cursor on the previous element. So it becomes the current element. If the current element was the first element of the list, gotoPrev returns false and the cursor position becomes invalid. If the cursor position was invalid, it will be set on the last element by gotoPrev.
bool containsValue(const value_type& xValue) const
returns true, if a value xValue is contained in the container.
bool findValue(const value_type& xValue)
searches for the first value xValue. If the value is contained in the map the according element becomes the actual element and the function returns true. Otherwise false will be returned.
Example:
vstr v; vstr::cursor cr = v.getCursor(); if ( ! cr.findNext("tt") ) out << "v is empty";
bool findNextValue(const value_type& xValue)
Beginning at the actual position this function looks for a following element, the value which of is xValue. If such an element exists, it becomes the actual one and true is returned. Otherwise the actual position remains unchanged and false is returned.
bool findPrevValue(const value_type& xValue)
Beginning at the actual position this function looks for a previous element, the value which of is xValue. If such an element exists, it becomes the actual one and true is returned. Otherwise the actual position remains unchanged and false is returned.
A map cursor has some additional methods:
str key() const bool containsKey(const str& xsKey) const bool findKey(const str& xsKey)
|
This page belongs to the TextTransformer Documentation |
Home Content German |