8 #ifndef BENCODING_BDICTIONARY_H 9 #define BENCODING_BDICTIONARY_H 11 #include <initializer_list> 49 bool operator()(
const std::shared_ptr<BString> &lhs,
50 const std::shared_ptr<BString> &rhs)
const;
57 using BItemMap = std::map<std::shared_ptr<BString>,
86 static std::unique_ptr<BDictionary>
create();
87 static std::unique_ptr<BDictionary>
create(
88 std::initializer_list<value_type> items);
118 explicit BDictionary(std::initializer_list<value_type> items);
BDictionary()
Constructs an empty dictionary.
Base class for all items (integers, strings, etc.).
Definition: BItem.h:20
std::map< std::shared_ptr< BString >, std::shared_ptr< BItem >, BStringByValueComparator > BItemMap
Mapping of strings into items.
Definition: BDictionary.h:58
iterator begin()
Returns an iterator to the beginning of the dictionary.
Definition: BDictionary.cpp:85
BItemMap::const_reference const_reference
Constant reference.
Definition: BDictionary.h:77
BItemMap::reference reference
Reference.
Definition: BDictionary.h:74
Base class for all visitors of the BItem subclasses.
Definition: BItemVisitor.h:25
virtual void accept(BItemVisitor *visitor) override
Accepts the item by the given visitor.
Definition: BDictionary.cpp:124
Representation of a dictionary.
Definition: BDictionary.h:39
const_iterator cbegin() const
Returns a constant iterator to the beginning of the dictionary.
Definition: BDictionary.cpp:113
iterator end()
Returns an iterator to the end of the dictionary.
Definition: BDictionary.cpp:92
Comparator of keys for the dictionary.
Definition: BDictionary.h:47
bool operator()(const std::shared_ptr< BString > &lhs, const std::shared_ptr< BString > &rhs) const
Checks if lhs->value() < rhs->value().
Definition: BDictionary.cpp:22
BItemMap::mapped_type mapped_type
Mapped type.
Definition: BDictionary.h:65
Main namespace of the bencoding library.
const_iterator cend() const
Returns a constant iterator to the end of the dictionary.
Definition: BDictionary.cpp:120
Base class for all items (integers, strings, etc.).
BItemMap itemMap
Underlying list of items.
Definition: BDictionary.h:122
BItemMap::size_type size_type
Size type.
Definition: BDictionary.h:71
BItemMap::iterator iterator
Iterator.
Definition: BDictionary.h:80
mapped_type & operator[](const key_type &key)
Accesses the specified element.
Definition: BDictionary.cpp:78
BItemMap::const_iterator const_iterator
Constant iterator.
Definition: BDictionary.h:83
size_type size() const
Returns the number of items in the dictionary.
Definition: BDictionary.cpp:57
BItemMap::key_type key_type
Key type.
Definition: BDictionary.h:62
static std::unique_ptr< BDictionary > create()
Creates and returns a new dictionary.
Definition: BDictionary.cpp:42
BItemMap::value_type value_type
Value type.
Definition: BDictionary.h:68
bool empty() const
Checks if the dictionary is empty.
Definition: BDictionary.cpp:66