cpp-bencoding
Classes | Public Types | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
bencoding::BDictionary Class Reference

Representation of a dictionary. More...

#include <BDictionary.h>

Inheritance diagram for bencoding::BDictionary:
bencoding::BItem

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_typeoperator[] (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< BDictionarycreate ()
 Creates and returns a new dictionary. More...
 
static std::unique_ptr< BDictionarycreate (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...
 

Detailed Description

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:

Use create() to create instances of the class.

Member Typedef Documentation

◆ BItemMap

using bencoding::BDictionary::BItemMap = std::map<std::shared_ptr<BString>, std::shared_ptr<BItem>, BStringByValueComparator>
private

Mapping of strings into items.

◆ const_iterator

using bencoding::BDictionary::const_iterator = BItemMap::const_iterator

Constant iterator.

◆ const_reference

using bencoding::BDictionary::const_reference = BItemMap::const_reference

Constant reference.

◆ iterator

using bencoding::BDictionary::iterator = BItemMap::iterator

Iterator.

◆ key_type

using bencoding::BDictionary::key_type = BItemMap::key_type

Key type.

◆ mapped_type

using bencoding::BDictionary::mapped_type = BItemMap::mapped_type

Mapped type.

◆ reference

using bencoding::BDictionary::reference = BItemMap::reference

Reference.

◆ size_type

using bencoding::BDictionary::size_type = BItemMap::size_type

Size type.

◆ value_type

using bencoding::BDictionary::value_type = BItemMap::value_type

Value type.

Constructor & Destructor Documentation

◆ BDictionary() [1/2]

bencoding::BDictionary::BDictionary ( )
privatedefault

Constructs an empty dictionary.

◆ BDictionary() [2/2]

bencoding::BDictionary::BDictionary ( std::initializer_list< value_type items)
explicitprivate

Constructs a dictionary from the given items.

Member Function Documentation

◆ accept()

void bencoding::BDictionary::accept ( BItemVisitor visitor)
overridevirtual

Accepts the item by the given visitor.

Subclasses should implement this function in this way:

void Subclass::accept(BItemVisitor *visitor) {
visitor->visit(this);
}

Implements bencoding::BItem.

◆ begin() [1/2]

BDictionary::iterator bencoding::BDictionary::begin ( )

Returns an iterator to the beginning of the dictionary.

◆ begin() [2/2]

BDictionary::const_iterator bencoding::BDictionary::begin ( ) const

Returns a constant iterator to the beginning of the dictionary.

◆ cbegin()

BDictionary::const_iterator bencoding::BDictionary::cbegin ( ) const

Returns a constant iterator to the beginning of the dictionary.

◆ cend()

BDictionary::const_iterator bencoding::BDictionary::cend ( ) const

Returns a constant iterator to the end of the dictionary.

◆ create() [1/2]

std::unique_ptr< BDictionary > bencoding::BDictionary::create ( )
static

Creates and returns a new dictionary.

◆ create() [2/2]

std::unique_ptr< BDictionary > bencoding::BDictionary::create ( std::initializer_list< value_type items)
static

Creates and returns a new dictionary containing the given items.

◆ empty()

bool bencoding::BDictionary::empty ( ) const

Checks if the dictionary is empty.

Returns
true if the dictionary is empty, false otherwise.

◆ end() [1/2]

BDictionary::iterator bencoding::BDictionary::end ( )

Returns an iterator to the end of the dictionary.

◆ end() [2/2]

BDictionary::const_iterator bencoding::BDictionary::end ( ) const

Returns a constant iterator to the end of the dictionary.

◆ operator[]()

BDictionary::mapped_type & bencoding::BDictionary::operator[] ( const key_type key)

Accesses the specified element.

Returns
A reference to the value that is mapped to a key equivalent to key.

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.

◆ size()

BDictionary::size_type bencoding::BDictionary::size ( ) const

Returns the number of items in the dictionary.

Member Data Documentation

◆ itemMap

BItemMap bencoding::BDictionary::itemMap
private

Underlying list of items.


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