CatapultServer  v0.5.0.1 (Elephant)
KeyValueOutputBuilder.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include <sstream>
24 #include <vector>
25 
26 namespace catapult { namespace tools {
27 
31  public:
33  void add(const std::string& key, const std::string& value);
34 
36  void add(const std::string& key, const std::vector<std::string>& values, const std::string& separator);
37 
39  template<size_t N>
40  void add(const std::string& key, const std::array<uint8_t, N>& value) {
41  std::ostringstream out;
42  out << utils::HexFormat(value);
43  add(key, out.str());
44  }
45 
47  template<typename T>
48  void add(const std::string& key, const T& value) {
49  std::ostringstream out;
50  out << value;
51  add(key, out.str());
52  }
53 
54  public:
57  std::string str(const std::string& prefix) const;
58 
59  private:
60  int maxKeySize() const;
61 
62  private:
63  std::vector<std::pair<std::string, std::string>> m_keyValuePairs;
64  };
65 
67  template<typename TValue>
68  std::string Join(const std::vector<TValue>& values, const std::string& separator) {
69  std::ostringstream out;
70  for (auto i = 0u; i < values.size(); ++i) {
71  out << values[i];
72 
73  if (values.size() != i + 1)
74  out << separator;
75  }
76 
77  return out.str();
78  }
79 }}
catapult::utils::HexFormat
constexpr void HexFormat(const ByteArray< N, TTag > &)
catapult::tools::KeyValueOutputBuilder::add
void add(const std::string &key, const T &value)
Adds a key with a default formatted value.
Definition: KeyValueOutputBuilder.h:48
catapult::tools::KeyValueOutputBuilder::str
std::string str(const std::string &prefix) const
Definition: KeyValueOutputBuilder.cpp:37
catapult::tools::Join
std::string Join(const std::vector< TValue > &values, const std::string &separator)
Joins all values with separator.
Definition: KeyValueOutputBuilder.h:68
catapult::tools::KeyValueOutputBuilder
Definition: KeyValueOutputBuilder.h:30
HexFormatter.h
catapult::tools::KeyValueOutputBuilder::add
void add(const std::string &key, const std::string &value)
Adds a key with a string value.
Definition: KeyValueOutputBuilder.cpp:26
KeyValueOutputBuilder.h
catapult::tools::KeyValueOutputBuilder::maxKeySize
int maxKeySize() const
Definition: KeyValueOutputBuilder.cpp:47
catapult::tools::KeyValueOutputBuilder::m_keyValuePairs
std::vector< std::pair< std::string, std::string > > m_keyValuePairs
Definition: KeyValueOutputBuilder.h:63
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::tools::KeyValueOutputBuilder::add
void add(const std::string &key, const std::array< uint8_t, N > &value)
Adds a key with a hex-formatted array value.
Definition: KeyValueOutputBuilder.h:40