cpp-bencoding
Encoder.h
Go to the documentation of this file.
1 
8 #ifndef BENCODING_ENCODER_H
9 #define BENCODING_ENCODER_H
10 
11 #include <memory>
12 #include <string>
13 
14 #include "BItemVisitor.h"
15 
16 namespace bencoding {
17 
18 class BItem;
19 
29 class Encoder: private BItemVisitor {
30 public:
31  static std::unique_ptr<Encoder> create();
32 
33  std::string encode(std::shared_ptr<BItem> data);
34 
35 private:
36  Encoder();
37 
40  virtual void visit(BDictionary *bDictionary) override;
41  virtual void visit(BInteger *bInteger) override;
42  virtual void visit(BList *bList) override;
43  virtual void visit(BString *bString) override;
45 
46 private:
48  std::string encodedData;
49 };
50 
53 std::string encode(std::shared_ptr<BItem> data);
55 
56 } // namespace bencoding
57 
58 #endif
Representation of an integer.
Definition: BInteger.h:23
std::string encode(std::shared_ptr< BItem > data)
Encodes the given data and returns them.
Definition: Encoder.cpp:33
Base class for all visitors of the BItem subclasses.
Base class for all visitors of the BItem subclasses.
Definition: BItemVisitor.h:25
std::string encode(std::shared_ptr< BItem > data)
Encodes the given data and returns them.
Definition: Encoder.cpp:82
Representation of a dictionary.
Definition: BDictionary.h:39
static std::unique_ptr< Encoder > create()
Creates a new encoder.
Definition: Encoder.cpp:26
std::string encodedData
Encoded items.
Definition: Encoder.h:48
virtual void visit(BDictionary *bDictionary) override
Definition: Encoder.cpp:38
Encoder()
Constructs an encoder.
Definition: Encoder.cpp:21
Main namespace of the bencoding library.
Data encoder.
Definition: Encoder.h:29
Representation of a string.
Definition: BString.h:23
Representation of a list.
Definition: BList.h:26