hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
string_builder.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_STRING_BUILDER_HPP
7 #define IROHA_SHARED_MODEL_STRING_BUILDER_HPP
8 
9 #include <string>
10 
11 namespace shared_model {
12  namespace detail {
17  public:
22  PrettyStringBuilder &init(const std::string &name);
23 
28 
33 
39  PrettyStringBuilder &append(const std::string &name,
40  const std::string &value);
41 
46  PrettyStringBuilder &append(const std::string &value);
47 
55  template <typename Collection, typename Transform>
56  PrettyStringBuilder &appendAll(Collection &&c, Transform &&t) {
57  insertLevel();
58  for (auto &val : c) {
59  append(t(val));
60  }
61  removeLevel();
62  return *this;
63  }
64 
73  template <typename Collection, typename Transform>
75  const std::string &name, Collection &&c, Transform &&t) {
76  result_.append(name);
77  result_.append(keyValueSeparator);
78  appendAll(c, t);
79  result_.append(singleFieldsSeparator);
80  result_.append(spaceSeparator);
81  return *this;
82  }
83 
88  std::string finalize();
89 
90  private:
91  std::string result_;
92  static const std::string beginBlockMarker;
93  static const std::string endBlockMarker;
94  static const std::string keyValueSeparator;
95  static const std::string singleFieldsSeparator;
96  static const std::string initSeparator;
97  static const std::string spaceSeparator;
98  };
99  } // namespace detail
100 } // namespace shared_model
101 
102 #endif // IROHA_SHARED_MODEL_STRING_BUILDER_HPP
PrettyStringBuilder & appendAll(const std::string &name, Collection &&c, Transform &&t)
Definition: string_builder.hpp:74
PrettyStringBuilder & init(const std::string &name)
Definition: string_builder.cpp:18
std::string finalize()
Definition: string_builder.cpp:52
PrettyStringBuilder & removeLevel()
Definition: string_builder.cpp:31
PrettyStringBuilder & insertLevel()
Definition: string_builder.cpp:26
PrettyStringBuilder & appendAll(Collection &&c, Transform &&t)
Definition: string_builder.hpp:56
Definition: string_builder.hpp:16
PrettyStringBuilder & append(const std::string &name, const std::string &value)
Definition: string_builder.cpp:36
Definition: command_executor.hpp:12