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

Generic key-value associative container. More...

#include <Dictionary.h>

Public Types

using container = std::unordered_map<std::string, boost::any>
 Underlying container.
 
using value_type = container::value_type
 
using iterator = container::iterator
 Iterator on the elements.
 
using const_iterator = container::const_iterator
 Read-only iterator on the elements.
 

Public Member Functions

 DECLARE_POINTERS (Dictionary)
 
 Dictionary ()=default
 
 Dictionary (std::initializer_list< container::value_type > values)
 
 Dictionary (Dictionary const &)=default
 
 Dictionary (Dictionary &&)=default
 
Dictionaryoperator= (Dictionary const &)=default
 
Dictionaryoperator= (Dictionary &&)=default
 
 ~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)
 

Detailed Description

Generic key-value associative container.

Member Typedef Documentation

◆ container

using msl::Dictionary::container = std::unordered_map<std::string, boost::any>

Underlying container.

◆ value_type

using msl::Dictionary::value_type = container::value_type

◆ iterator

using msl::Dictionary::iterator = container::iterator

Iterator on the elements.

◆ const_iterator

using msl::Dictionary::const_iterator = container::const_iterator

Read-only iterator on the elements.

Constructor & Destructor Documentation

◆ Dictionary() [1/4]

msl::Dictionary::Dictionary ( )
default

◆ Dictionary() [2/4]

msl::Dictionary::Dictionary ( std::initializer_list< container::value_type > values)

◆ Dictionary() [3/4]

msl::Dictionary::Dictionary ( Dictionary const & )
default

◆ Dictionary() [4/4]

msl::Dictionary::Dictionary ( Dictionary && )
default

◆ ~Dictionary()

msl::Dictionary::~Dictionary ( )
default

Member Function Documentation

◆ DECLARE_POINTERS()

msl::Dictionary::DECLARE_POINTERS ( Dictionary )

◆ New()

static std::shared_ptr< Dictionary > msl::Dictionary::New ( std::initializer_list< value_type > && data)
inlinestatic

◆ operator=() [1/2]

Dictionary & msl::Dictionary::operator= ( Dictionary const & )
default

◆ operator=() [2/2]

Dictionary & msl::Dictionary::operator= ( Dictionary && )
default

◆ 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

◆ has()

bool msl::Dictionary::has ( std::string const & key) const

Check whether the key is in the dictionary.

◆ 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

◆ set()

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

Set the value at given key, create it if required.

◆ empty()

bool msl::Dictionary::empty ( ) const

Check whether the dictionary is empty.

◆ size()

size_t msl::Dictionary::size ( ) const

Return the number of items in the dictionary.

◆ begin() [1/2]

iterator msl::Dictionary::begin ( )

Return a read-write iterator to the first element.

◆ begin() [2/2]

const_iterator msl::Dictionary::begin ( ) const

Return a read-only iterator to the first element.

◆ cbegin()

const_iterator msl::Dictionary::cbegin ( ) const

Return a read-only iterator to the first element.

◆ end() [1/2]

iterator msl::Dictionary::end ( )

Return a read-write iterator past the last element.

◆ end() [2/2]

const_iterator msl::Dictionary::end ( ) const

Return a read-only iterator past the last element.

◆ cend()

const_iterator msl::Dictionary::cend ( ) const

Return a read-only iterator past the last element.

◆ clear()

Dictionary & msl::Dictionary::clear ( )

Erases all elements.

◆ insert()

Dictionary & msl::Dictionary::insert ( std::initializer_list< value_type > && data)

Inserts elements.


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