vector |
Top Previous Next |
Scripts > Class elements and c++ instructions > Interpreted C++ instructions > Container > vector
A container class vector manages a list of elements. All elements of a list have the same data type. There are, however, different vector types depending on type of the contained elements. (See the table above)
Syntax
vbool <identifier> vint <identifier> vuint <identifier> vdbl <identifier> vchar <identifier> vstr <identifier> vnode <identifier>
Description
The vector types are typedefs of the clsss CTT_Vector< value_type > in the exported code. CTT_Vector is derived from std::vector< value_type >.
All vector classes have the same methods. These are
1.) the read only methods of the general cursor class:
bool isValid() const bool hasCurrent() const bool empty() const unsigned int size() const bool gotoNext() bool gotoPrev() value_type value() const bool containsValue(const value_type& ) const bool findValue(const value_type& xValue) bool findNextValue(const value_type& xValue) bool findPrevValue(const value_type& xValue)
2.) getCursor() const
By this method an external cursor is connected with the vector.
Example:
vint v; vint::cursor cr = v.getCursor();
cr now points to the same data element as the internal cursor, but further both can be placed independently from each other.
3.) Methods, which change the content of a vector:
void reset()
Positions the cursor before/behind the list of elements of the vector.
void clear()
removes all elements from the vector and resets all cursors.
void push_back(const value_type& xValue)
Appends xValue at the end of the vector. All cursors are reset.
void pop_back()
Removes the last element from the vector. All cursors are reset. If the vector is empty, an error occurs..You should check, whether the vector contains elements before calling pop_back:
bool remove()
removes the current element from the vector and returns true. If there is no current element or if an error occurs, false will be returned. All cursors are reset.
bool setValue(const value_type& xValue)
changes the value of the current element and returns true. If there is no current element or if an error occurs, false will be returned.
4.) Direct access of the elements
value_type back()
returns the last element. If the vector is empty, an error occurs..You should check, whether the vector contains elements before calling back:
if(v.size()) value = v.back();
value_type front()
returns the first element. If the vector is empty, an error occurs..You should check, whether the vector contains elements before calling front:
if(v.size()) value = v.front();
Index operator
The elements, which were inserted into a vector by the push_back method can be accessed directly by their index. The first element has index 0 and the last has index size() -1. If a vstr named v exists
str s = v[0];
copies the first String into s and
v[0] = s;
copies the string s into the first element, if the first element exists. If no first element was inserted by push_back, an error occurres.
|
This page belongs to the TextTransformer Documentation |
Home Content German |