AnyMap

class AnyMap : public cppmicroservices::any_map

A map data structure with support for compound keys.

This class adds convenience functions on top of the any_map class. The any_map is a recursive data structure, and its values can be retrieved via standard map functions or by using a dotted key notation specifying a compound key.

See also

any_map

Public Functions

AnyMap(std::initializer_list<any_map::value_type> l = {})

initializer_list constructor

Construct an AnyMap of type UNORDERED_MAP_CASEINSENSITIVE_KEYS with the content of the the initializer list. Allows for inline initialization akin to:

AnyMap cache_bundle1 {
    {"a", std::string("A")},
    {"b", std::string("B")},
    {"c", std::string("C")}
};

Parameters:

l – a std::initializer_list<value_type> used to initialize the content of the AnyMap.

AnyMap(map_type type, std::initializer_list<any_map::value_type> l = {})

initializer_list constructor

Construct an AnyMap of type “type” with the content of the the initializer list. Allows for inline initialization akin to:

AnyMap cache_bundle1 {
    AnyMap::ORDERED_MAP, {
        {"a", std::string("A")},
        {"b", std::string("B")},
        {"c", std::string("C")}
    }
};

Parameters:
  • type – the map_type of the AnyMap

  • l – a std::initializer_list<value_type> used to initialize the content of the AnyMap.

AnyMap(ordered_any_map const &m)
AnyMap(ordered_any_map &&m)
AnyMap(unordered_any_map const &m)
AnyMap(unordered_any_map &&m)
AnyMap(unordered_any_cimap const &m)
AnyMap(unordered_any_cimap &&m)
map_type GetType() const

Get the underlying STL container type.

Returns:

The STL container type holding the map data.

mapped_type const &AtCompoundKey(key_type const &key) const

Get a key’s value, using a compound key notation.

A compound key consists of one or more key names, concatenated with the ‘.’ (dot) character. Each key except the last requires the referenced Any object to be of type AnyMap or std::vector<Any>. Containers of type std::vector<Any> are indexed using 0-based numerical key names.

For example, a AnyMap object holding data of the following layout

{
  one: 1,
  two: "two",
  three: {
    a: "anton",
    b: [ 3, 8 ]
  }
}
can be queried using the following notation:
map.AtCompoundKey("one");       // returns Any(1)
map.AtCompoundKey("three.a");   // returns Any(std::string("anton"))
map.AtCompoundKey("three.b.1"); // returns Any(8)

Parameters:

key – The key hierachy to query.

Throws:
  • std::invalid_argument – if the Any value for a given key is not of type AnyMap or std::vector<Any>.

  • std::out_of_range – if the key is not found or a numerical index would fall out of the range of an int type.

Returns:

A reference to the key’s value.

mapped_type AtCompoundKey(key_type const &key, mapped_type defaultValue) const noexcept

Return a key’s value, using a compound key notation if the key is found in the map or return the provided default value if the key is not found.

A compound key consists of one or more key names, concatenated with the ‘.’ (dot) character. Each key except the last requires the referenced Any object to be of type AnyMap or std::vector<Any>. Containers of type std::vector<Any> are indexed using 0-based numerical key names.

For example, a AnyMap object holding data of the following layout

{
  one: 1,
  two: "two",
  three: {
    a: "anton",
    b: [ 3, 8 ]
  }
}
can be queried using the following notation:
map.AtCompoundKey("one", Any());       // returns Any(1)
map.AtCompoundKey("four", Any());       // returns Any()
map.AtCompoundKey("three.a", Any());          // returns Any(std::string("anton"))
map.AtCompoundKey("three.c", Any());          // returns Any()
map.AtCompoundKey("three.b.1", Any());        // returns Any(8)
map.AtCompoundKey("three.b.4", Any());        // returns Any()

Parameters:
  • key – The key hierachy to query.

  • defaultValue – is the value to be returned if the key is not found

Returns:

A copy of the key’s value.

class any_map

A map data structure which wraps different STL map types.

This is a convenience class providing a STL associative container interface for different underlying container types. Supported underlying types are

This class provides most of the STL functions for associated containers, including forward iterators. It is typically not instantiated by clients directly, but obtained via framework API calls, returning an AnyMap sub-class instance.

See also

AnyMap

Subclassed by cppmicroservices::AnyMap

Public Types

enum map_type

Values:

enumerator ORDERED_MAP
enumerator UNORDERED_MAP
enumerator UNORDERED_MAP_CASEINSENSITIVE_KEYS
using key_type = std::string
using mapped_type = Any
using value_type = std::pair<const key_type, mapped_type>
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using reference = value_type&
using const_reference = value_type const&
using pointer = value_type*
using const_pointer = value_type const*
using ordered_any_map = std::map<std::string, Any>
using unordered_any_map = std::unordered_map<std::string, Any>
using unordered_any_cimap = std::unordered_map<std::string, Any, detail::any_map_cihash, detail::any_map_ciequal>
using iterator = iter
using const_iterator = const_iter

Public Functions

any_map(map_type type, std::initializer_list<value_type> l = {})

initializer_list constructor

Construct an AnyMap of type “type” with the content of the initialized with the content of the the initializer list. Allows for inline initialization akin to:

any_map cache_bundle1 {
    any_map::ORDERED_MAP, {
        {"a", std::string("A")},
        {"b", std::string("B")},
        {"c", std::string("C")}
    }
};
The primary purpose of this constructor in any_map is in support of the initializer_list constructors in the AnyMap subclass.

Parameters:
  • type – the map_type of the AnyMap

  • l – a std::initializer_list<value_type> used to initialize the content of the AnyMap.

any_map(ordered_any_map const &m)
any_map(ordered_any_map &&m)
any_map(unordered_any_map const &m)
any_map(unordered_any_map &&m)
any_map(unordered_any_cimap const &m)
any_map(unordered_any_cimap &&m)
any_map(any_map const &m)
any_map &operator=(any_map const &m)
any_map(any_map &&m) noexcept
any_map &operator=(any_map &&m) noexcept
~any_map()
iter begin()
const_iter begin() const
const_iter cbegin() const
iter end()
const_iter end() const
const_iter cend() const
bool empty() const
size_type size() const
size_type count(key_type const &key) const
void clear()
mapped_type &at(key_type const &key)
mapped_type const &at(key_type const &key) const
mapped_type &operator[](key_type const &key)
mapped_type &operator[](key_type &&key)
std::pair<iterator, bool> insert(value_type const &value)
template<class ...Args>
inline std::pair<iterator, bool> emplace(Args&&... args)
const_iterator find(key_type const &key) const

return the iterator to the value referenced by key

size_type erase(key_type const &key)

Erase entry for value for ‘key’.

Parameters:

key – the key for the entry to Erase

Returns:

the number of elements erased.

bool operator==(any_map const &rhs) const

Compare the content of this map with those of rhs.

Parameters:

rhs – an any_map to compare

Returns:

bool true rhs contains the same content as this

inline bool operator!=(any_map const &rhs) const

Protected Attributes

map_type type
class const_iter : public cppmicroservices::any_map::iterator_base

Public Types

using reference = any_map::const_reference
using pointer = any_map::const_pointer
using iterator = const_iter

Public Functions

const_iter()
const_iter(iterator const &it)
const_iter(iter const &it)
~const_iter()
const_iter(ociter &&it)
const_iter(uociter &&it, iter_type type)
reference operator*() const
pointer operator->() const
iterator &operator++()
iterator operator++(int)
bool operator==(iterator const &x) const
bool operator!=(iterator const &x) const

Public Members

ociter *o
uociter *uo
uocciiter *uoci
class iter : public cppmicroservices::any_map::iterator_base

Public Types

using reference = any_map::reference
using pointer = any_map::pointer
using iterator = iter

Public Functions

iter()
iter(iter const &it)
~iter()
iter(oiter &&it)
iter(uoiter &&it, iter_type type)
reference operator*() const
pointer operator->() const
iterator &operator++()
iterator operator++(int)
bool operator==(iterator const &x) const
bool operator!=(iterator const &x) const

Public Members

oiter *o
uoiter *uo
uociiter *uoci