UHD  003.004.002-23-stable
Public Member Functions
uhd::dict Class Reference

#include <dict.hpp>

List of all members.

Public Member Functions

 dict (void)
template<typename InputIterator >
 dict (InputIterator first, InputIterator last)
std::size_t size (void) const
std::vector< Key > keys (void) const
std::vector< Val > vals (void) const
bool has_key (const Key &key) const
const Val & get (const Key &key, const Val &other) const
const Val & get (const Key &key) const
void set (const Key &key, const Val &val)
const Val & operator[] (const Key &key) const
Val & operator[] (const Key &key)
Val pop (const Key &key)

Detailed Description

A templated dictionary class with a python-like interface.


Constructor & Destructor Documentation

uhd::dict::dict ( void  )

Create a new empty dictionary.

template<typename InputIterator >
uhd::dict::dict ( InputIterator  first,
InputIterator  last 
)

Input iterator constructor: Makes boost::assign::map_list_of work.

Parameters:
firstthe begin iterator
lastthe end iterator

Member Function Documentation

const Val& uhd::dict::get ( const Key &  key,
const Val &  other 
) const

Get a value in the dict or default.

Parameters:
keythe key to look for
otheruse if key not found
Returns:
the value or default
const Val& uhd::dict::get ( const Key &  key) const

Get a value in the dict or throw.

Parameters:
keythe key to look for
Returns:
the value or default
bool uhd::dict::has_key ( const Key &  key) const

Does the dictionary contain this key?

Parameters:
keythe key to look for
Returns:
true if found
std::vector<Key> uhd::dict::keys ( void  ) const

Get a list of the keys in this dict. Key order depends on insertion precedence.

Returns:
vector of keys
const Val& uhd::dict::operator[] ( const Key &  key) const

Get a value for the given key if it exists. If the key is not found throw an error.

Parameters:
keythe key to look for
Returns:
the value at the key
Exceptions:
anexception when not found
Val& uhd::dict::operator[] ( const Key &  key)

Set a value for the given key, however, in reality it really returns a reference which can be assigned to.

Parameters:
keythe key to set to
Returns:
a reference to the value
Val uhd::dict::pop ( const Key &  key)

Pop an item out of the dictionary.

Parameters:
keythe item key
Returns:
the value of the item
Exceptions:
anexception when not found
void uhd::dict::set ( const Key &  key,
const Val &  val 
)

Set a value in the dict at the key.

Parameters:
keythe key to set at
valthe value to set
std::size_t uhd::dict::size ( void  ) const

Get the number of elements in this dict.

Returns:
the number of elements
std::vector<Val> uhd::dict::vals ( void  ) const

Get a list of the values in this dict. Value order depends on insertion precedence.

Returns:
vector of values

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines