cpp-bencoding
BList.h
Go to the documentation of this file.
1 
8 #ifndef BENCODING_BLIST_H
9 #define BENCODING_BLIST_H
10 
11 #include <initializer_list>
12 #include <list>
13 #include <memory>
14 
15 #include "BItem.h"
16 
17 namespace bencoding {
18 
26 class BList: public BItem {
27 private:
29  using BItemList = std::list<std::shared_ptr<BItem>>;
30 
31 public:
33  using value_type = BItemList::value_type;
34 
36  using size_type = BItemList::size_type;
37 
39  using reference = BItemList::reference;
40 
42  using const_reference = BItemList::const_reference;
43 
45  using iterator = BItemList::iterator;
46 
48  using const_iterator = BItemList::const_iterator;
49 
50 public:
51  static std::unique_ptr<BList> create();
52  static std::unique_ptr<BList> create(std::initializer_list<value_type> items);
53 
56  size_type size() const;
57  bool empty() const;
59 
62  void push_back(const value_type &bItem);
63  void pop_back();
65 
68  reference front();
69  const_reference front() const;
70  reference back();
71  const_reference back() const;
73 
76  iterator begin();
77  iterator end();
78  const_iterator begin() const;
79  const_iterator end() const;
80  const_iterator cbegin() const;
81  const_iterator cend() const;
83 
86  virtual void accept(BItemVisitor *visitor) override;
88 
89 private:
90  BList();
91  explicit BList(std::initializer_list<value_type> items);
92 
93 private:
96 };
97 
98 } // namespace bencoding
99 
100 #endif
reference front()
Returns a reference to the first item in the list.
Definition: BList.cpp:89
static std::unique_ptr< BList > create()
Creates and returns a new list.
Definition: BList.cpp:30
std::list< std::shared_ptr< BItem > > BItemList
List of items.
Definition: BList.h:29
Base class for all items (integers, strings, etc.).
Definition: BItem.h:20
void push_back(const value_type &bItem)
Appends the given item to the end of the list.
Definition: BList.cpp:63
size_type size() const
Returns the number of items in the list.
Definition: BList.cpp:44
reference back()
Returns a reference to the last item in the list.
Definition: BList.cpp:113
Base class for all visitors of the BItem subclasses.
Definition: BItemVisitor.h:25
iterator begin()
Returns an iterator to the beginning of the list.
Definition: BList.cpp:134
bool empty() const
Checks if the list is empty.
Definition: BList.cpp:53
BList()
Constructs an empty list.
const_iterator cbegin() const
Returns a constant iterator to the beginning of the list.
Definition: BList.cpp:162
BItemList::iterator iterator
Iterator (BidirectionalIterator).
Definition: BList.h:45
BItemList itemList
Underlying list of items.
Definition: BList.h:95
BItemList::const_iterator const_iterator
Constant iterator (constant BidirectionalIterator).
Definition: BList.h:48
Main namespace of the bencoding library.
const_iterator cend() const
Returns a constant iterator to the end of the list.
Definition: BList.cpp:169
BItemList::value_type value_type
Value type.
Definition: BList.h:33
Base class for all items (integers, strings, etc.).
virtual void accept(BItemVisitor *visitor) override
Accepts the item by the given visitor.
Definition: BList.cpp:173
BItemList::size_type size_type
Size type.
Definition: BList.h:36
iterator end()
Returns an iterator to the end of the list.
Definition: BList.cpp:141
void pop_back()
Removes the last element of the list.
Definition: BList.cpp:77
BItemList::const_reference const_reference
Constant reference.
Definition: BList.h:42
BItemList::reference reference
Reference.
Definition: BList.h:39
Representation of a list.
Definition: BList.h:26