Class vec_index (o2scl)

O2scl : Class List

class vec_index

A class to assign string labels to array indices.

Idea for Future:

Create a method to remove strings from the list

Constructors

inline vec_index()

Create an empty assignment.

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

Create an assignment based on the strings in list.

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

Create an assignment based on the strings in list.

inline vec_index(const vec_index &t)

Copy constructor.

Translation between size_t and string

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

Return the string of index i.

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

Return the index of string s.

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

Return the string of index i.

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

Return the index of string s.

Other useful methods

inline size_t size() const

Return the size.

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

Return the list of strings.

inline vec_index &operator=(const vec_index &t)

Copy constructor by assignment.

Adding strings

inline void append(std::string s)

Add string s and assign it the next index.

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

Add a list of strings.

inline 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.