Class vec_index (o2scl)

O2scl : Class List

class o2scl::vec_index

A class to assign string labels to array indices.

Idea for Future:

Create a method to remove strings from the list

Constructors

vec_index()

Create an empty assignment.

vec_index(const std::vector<std::string> &list)

Create an assignment based on the strings in list.

vec_index(std::initializer_list<std::string> list)

Create an assignment based on the strings in list.

vec_index(const vec_index &t)

Copy constructor.

Translation between size_t and string

std::string operator()(size_t i) const

Return the string of index i.

size_t operator()(std::string s) const

Return the index of string s.

std::string operator[](size_t i) const

Return the string of index i.

size_t operator[](std::string s) const

Return the index of string s.

Other useful methods

size_t size() const

Return the size.

std::vector<std::string> list() const

Return the list of strings.

vec_index &operator=(const vec_index &t)

Copy constructor by assignment.

Adding strings

void append(std::string s)

Add string s and assign it the next index.

void append(const std::vector<std::string> &list)

Add a list of strings.

void append(std::initializer_list<std::string> list)

Add a list of strings.

Protected Attributes

std::map<std::string, size_t, std::greater<std::string>> tmap

The map version for string lookup.

std::vector<std::string> tvec

The vector version for size_t lookup.