cpp-bencoding
|
Representation of a dictionary. More...
#include <BDictionary.h>
Classes | |
class | BStringByValueComparator |
Comparator of keys for the dictionary. More... | |
Public Types | |
using | key_type = BItemMap::key_type |
Key type. More... | |
using | mapped_type = BItemMap::mapped_type |
Mapped type. More... | |
using | value_type = BItemMap::value_type |
Value type. More... | |
using | size_type = BItemMap::size_type |
Size type. More... | |
using | reference = BItemMap::reference |
Reference. More... | |
using | const_reference = BItemMap::const_reference |
Constant reference. More... | |
using | iterator = BItemMap::iterator |
Iterator. More... | |
using | const_iterator = BItemMap::const_iterator |
Constant iterator. More... | |
Public Member Functions | |
Capacity | |
size_type | size () const |
Returns the number of items in the dictionary. More... | |
bool | empty () const |
Checks if the dictionary is empty. More... | |
Element Access and Modifiers | |
mapped_type & | operator[] (const key_type &key) |
Accesses the specified element. More... | |
Iterators | |
iterator | begin () |
Returns an iterator to the beginning of the dictionary. More... | |
iterator | end () |
Returns an iterator to the end of the dictionary. More... | |
const_iterator | begin () const |
Returns a constant iterator to the beginning of the dictionary. More... | |
const_iterator | end () const |
Returns a constant iterator to the end of the dictionary. More... | |
const_iterator | cbegin () const |
Returns a constant iterator to the beginning of the dictionary. More... | |
const_iterator | cend () const |
Returns a constant iterator to the end of the dictionary. More... | |
BItemVisitor Support | |
virtual void | accept (BItemVisitor *visitor) override |
Accepts the item by the given visitor. More... | |
Public Member Functions inherited from bencoding::BItem | |
virtual | ~BItem ()=0 |
Destructs the item. More... | |
template<typename T > | |
std::shared_ptr< T > | as () |
Casts the item to the given subclass of BItem. More... | |
Static Public Member Functions | |
static std::unique_ptr< BDictionary > | create () |
Creates and returns a new dictionary. More... | |
static std::unique_ptr< BDictionary > | create (std::initializer_list< value_type > items) |
Creates and returns a new dictionary containing the given items. More... | |
Private Types | |
using | BItemMap = std::map< std::shared_ptr< BString >, std::shared_ptr< BItem >, BStringByValueComparator > |
Mapping of strings into items. More... | |
Private Member Functions | |
BDictionary () | |
Constructs an empty dictionary. More... | |
BDictionary (std::initializer_list< value_type > items) | |
Constructs a dictionary from the given items. More... | |
Private Attributes | |
BItemMap | itemMap |
Underlying list of items. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from bencoding::BItem | |
BItem () | |
Constructs the item. More... | |
Representation of a dictionary.
The interface models the interface of std::map
.
According to the specification, the keys should appear in a lexicographical order by the string values. This has the following consequences for the users of the BDictionary class:
std::shared_ptr<BString>
, its value is taken into account, not its address. That is, two different smart pointers pointing to strings with equal values are considered to be equal when accessing or modifying elements.Use create() to create instances of the class.
|
private |
Mapping of strings into items.
using bencoding::BDictionary::const_iterator = BItemMap::const_iterator |
Constant iterator.
using bencoding::BDictionary::const_reference = BItemMap::const_reference |
Constant reference.
using bencoding::BDictionary::iterator = BItemMap::iterator |
Iterator.
using bencoding::BDictionary::key_type = BItemMap::key_type |
Key type.
using bencoding::BDictionary::mapped_type = BItemMap::mapped_type |
Mapped type.
using bencoding::BDictionary::reference = BItemMap::reference |
Reference.
using bencoding::BDictionary::size_type = BItemMap::size_type |
Size type.
using bencoding::BDictionary::value_type = BItemMap::value_type |
Value type.
|
privatedefault |
Constructs an empty dictionary.
|
explicitprivate |
Constructs a dictionary from the given items.
|
overridevirtual |
Accepts the item by the given visitor.
Subclasses should implement this function in this way:
Implements bencoding::BItem.
BDictionary::iterator bencoding::BDictionary::begin | ( | ) |
Returns an iterator to the beginning of the dictionary.
BDictionary::const_iterator bencoding::BDictionary::begin | ( | ) | const |
Returns a constant iterator to the beginning of the dictionary.
BDictionary::const_iterator bencoding::BDictionary::cbegin | ( | ) | const |
Returns a constant iterator to the beginning of the dictionary.
BDictionary::const_iterator bencoding::BDictionary::cend | ( | ) | const |
Returns a constant iterator to the end of the dictionary.
|
static |
Creates and returns a new dictionary.
|
static |
Creates and returns a new dictionary containing the given items.
bool bencoding::BDictionary::empty | ( | ) | const |
Checks if the dictionary is empty.
true
if the dictionary is empty, false
otherwise. BDictionary::iterator bencoding::BDictionary::end | ( | ) |
Returns an iterator to the end of the dictionary.
BDictionary::const_iterator bencoding::BDictionary::end | ( | ) | const |
Returns a constant iterator to the end of the dictionary.
BDictionary::mapped_type & bencoding::BDictionary::operator[] | ( | const key_type & | key | ) |
Accesses the specified element.
If there is no value mapped to key, an insertion of a null pointer is automatically performed, and a reference to this null pointer is returned.
BDictionary::size_type bencoding::BDictionary::size | ( | ) | const |
Returns the number of items in the dictionary.
|
private |
Underlying list of items.