TCL_obj_stl
The header file TCL_obj_stl
provides TCL_obj
support for
STL containers. If the value_type
of an STL container (vector, deque
or list) or set is streamable to an iostream, then it is possible to
directly access the elements of the container as a simple list:
std::vector<int> vec;
make_model(vec);
...
vec {1 2 3}
set vec_elems [vec]
If the value_type
is not streamable, an exception will be thrown. This
feature makes the #members
functionality of sets redundant.
The following TCL procedures are defined for the
following STL containers, which can be used from a TCL script or the
object browser to manipulate STL container objects. Procedures that do
not call member names are prefixed by the “@” symbol, which is a
valid identifier character in TCL, but is not a valid C++ identifier
character. This avoids any possible clash of member names.
- vector, dequeue, list
-
- @is_vector
- A “do nothing” command, the presence of which
indicates the object is a vector. @elem is more efficient in this case
- @is_sequence
- A “do nothing” command, the presence of which
indicates the object complies with the sequence concept.
- size
- returns the size of the vector
- @elem
- takes one argument, the index of an element. It creates a
TCL command name(index) that can be used in the usual
way to access or modify the element's value.
- set, map
-
- @is_set
- A “do nothing” command, the presence of which
indicates the object complies with the set concept.
- @is_map
- A “do nothing” command, the presence of which
indicates the object complies with the map concept. @elem can be
used to lookup elements by key.
- size
- Return number of entries in the set or map
- count
- Takes a single argument, and returns 1 or 0, according to
whether that argument present within the set or map (as a member or
key respectively).
- #members
- Returns list of members of a set
- #keys
- Returns list of keys of a map
- @elem
- Returns a TCL command name for accessing individual
elements of a set or map. In the case of a set, the command accesses
the th element of the set. In the case of a map, the argument can
be an arbitrary string (so long as it converts to the key type of
the map), that can be used to address the map element. For example,
if the map is
map
<string,string>+, one can create an element
m["hello"]="foo"
by means of the following TCL commands:
m.@elem hello
m(hello) foo
Subsections