Top: Basic types: Lists: textmap

>     class textmap {
>         textmap(bool casesens = false);
>         int    get_count() const;
>         void   pack();
>         void   clear();
>         int    put(string key, string value);
>         string operator [](int index) const;
>         string operator [](string key) const;
>         string getkey(int index) const;
>     }

The textmap class implements an associative array of strings, i.e. textual key/value pairs. Items in a textmap object can be accessed both via integral indexes and textual keys. Internally, textmap keeps the list sorted in alphabetical order and uses binary search to find keys in a list.

The methods get_count(), clear() and pack() work as for tobjlist and are not described in this section.

textmap::textmap(bool casesens = false) constructs a textmap object, optionally with case-sensitive key search.

int textmap::put(string key, string value) associates value with key. This method can either insert or replace an existing value, as well as remove it from a textmap if value is an empty string.

string textmap::operator [](string key) returns a value associated with the key, or an empty string if key does not exist in a textmap.

string textmap::operator [](int index) returns a value at the position index. This method along with get_count() can be used to iterate through a textmap.

string textmap::getkey(int index) returns the key value at the position index.

See also: tstrlist

PTypes home