cpp-bencoding
PrettyPrinter.h
Go to the documentation of this file.
1 
8 #ifndef BENCODING_PRETTYPRINTER_H
9 #define BENCODING_PRETTYPRINTER_H
10 
11 #include <memory>
12 #include <string>
13 
14 #include "BItemVisitor.h"
15 
16 namespace bencoding {
17 
18 class BItem;
19 
27 class PrettyPrinter: private BItemVisitor {
28 public:
29  static std::unique_ptr<PrettyPrinter> create();
30 
31  std::string getPrettyRepr(std::shared_ptr<BItem> data,
32  const std::string &indent = " ");
33 
34 private:
35  PrettyPrinter();
36 
39  virtual void visit(BDictionary *bDictionary) override;
40  virtual void visit(BInteger *bInteger) override;
41  virtual void visit(BList *bList) override;
42  virtual void visit(BString *bString) override;
44 
47  void storeCurrentIndent();
48  void increaseIndentLevel();
49  void decreaseIndentLevel();
51 
52 private:
54  std::string prettyRepr = "";
55 
57  std::string indentLevel = " ";
58 
60  std::string currentIndent = "";
61 };
62 
65 std::string getPrettyRepr(std::shared_ptr<BItem> data,
66  const std::string &indent = " ");
68 
69 } // namespace bencoding
70 
71 #endif
Representation of an integer.
Definition: BInteger.h:23
static std::unique_ptr< PrettyPrinter > create()
Creates a new printer.
Definition: PrettyPrinter.cpp:26
virtual void visit(BDictionary *bDictionary) override
Definition: PrettyPrinter.cpp:67
Base class for all visitors of the BItem subclasses.
std::string getPrettyRepr(std::shared_ptr< BItem > data, const std::string &indent=" ")
Returns a pretty representation of data.
Definition: PrettyPrinter.cpp:154
Base class for all visitors of the BItem subclasses.
Definition: BItemVisitor.h:25
Representation of a dictionary.
Definition: BDictionary.h:39
void decreaseIndentLevel()
Decreases the current indentation by a single level.
Definition: PrettyPrinter.cpp:62
void increaseIndentLevel()
Increases the current indentation by a single level.
Definition: PrettyPrinter.cpp:55
std::string prettyRepr
Pretty representation of the data obtained so far.
Definition: PrettyPrinter.h:54
Pretty printer of data.
Definition: PrettyPrinter.h:27
std::string currentIndent
The current level of indentation.
Definition: PrettyPrinter.h:60
std::string getPrettyRepr(std::shared_ptr< BItem > data, const std::string &indent=" ")
Returns a pretty representation of data.
Definition: PrettyPrinter.cpp:36
Main namespace of the bencoding library.
std::string indentLevel
A single level of indentation.
Definition: PrettyPrinter.h:57
void storeCurrentIndent()
Stores the current indentation into prettyRepr.
Definition: PrettyPrinter.cpp:48
Representation of a string.
Definition: BString.h:23
Representation of a list.
Definition: BList.h:26
PrettyPrinter()
Constructs a printer.