msl 1.3.0
Loading...
Searching...
No Matches
msl::Dictionary Class Reference

Detailed Description

Generic key-value associative container.

#include <Dictionary.h>

Public Types

using container = std::unordered_map<std::string, boost::any>
 Underlying container.
using value_type = container::value_type
 Pair of (key, value).
using iterator = container::iterator
 Iterator on the elements.
using const_iterator = container::const_iterator
 Read-only iterator on the elements.
using Pointer = std::shared_ptr<Dictionary>
 Reference-counted pointer to Dictionary.
using ConstPointer = std::shared_ptr<Dictionary const>
 Reference-counted constant pointer to Dictionary.

Public Member Functions

 Dictionary (std::initializer_list< container::value_type > values)
 Create a dictionary from pairs of (key, value).
 Dictionary (Dictionary const &)=default
 Dictionary (Dictionary &&)=default
Dictionaryoperator= (Dictionary const &)=default
Dictionaryoperator= (Dictionary &&)=default
container::mapped_type get (std::string const &key) const
 Return a generic value.
template<typename T>
T const & get (std::string const &key) const
 Return a typed value (read-only).
template<typename T>
T & get (std::string const &key)
 Return a typed value.
bool has (std::string const &key) const
 Check whether the key is in the dictionary.
boost::typeindex::type_info const & type (std::string const &key) const
 Return the type of a key.
template<typename T>
Dictionaryset (std::string const &key, T &&value)
 Set the value at given key, create it if required.
bool empty () const
 Check whether the dictionary is empty.
size_t size () const
 Return the number of items in the dictionary.
iterator begin ()
 Return a read-write iterator to the first element.
const_iterator begin () const
 Return a read-only iterator to the first element.
const_iterator cbegin () const
 Return a read-only iterator to the first element.
iterator end ()
 Return a read-write iterator past the last element.
const_iterator end () const
 Return a read-only iterator past the last element.
const_iterator cend () const
 Return a read-only iterator past the last element.
Dictionaryclear ()
 Erases all elements.
Dictionaryinsert (std::initializer_list< value_type > &&data)
 Inserts elements.

Static Public Member Functions

static std::shared_ptr< DictionaryNew (std::initializer_list< value_type > &&data)
 Create a dictionary from pairs of (key, value).

Member Function Documentation

◆ get() [1/3]

container::mapped_type msl::Dictionary::get ( std::string const & key) const

Return a generic value.

Raise an exception if the key is not in the dictionary

◆ get() [2/3]

template<typename T>
T const & msl::Dictionary::get ( std::string const & key) const
inline

Return a typed value (read-only).

Raise an exception if the key is not in the dictionary or if the type is wrong

◆ get() [3/3]

template<typename T>
T & msl::Dictionary::get ( std::string const & key)
inline

Return a typed value.

Raise an exception if the key is not in the dictionary or if the type is wrong

◆ type()

boost::typeindex::type_info const & msl::Dictionary::type ( std::string const & key) const

Return the type of a key.

Raise an exception if the key is not in the dictionary


The documentation for this class was generated from the following file: