CatapultServer  v0.5.0.1 (Elephant)
ConfigurationValueParsers.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "Logging.h"
23 #include "catapult/types.h"
24 #include <array>
25 #include <unordered_set>
26 
27 namespace catapult {
28  namespace utils {
29  class BlockSpan;
30  class FileSize;
31  class TimeSpan;
32  }
33 }
34 
35 namespace catapult { namespace utils {
36 
38  bool TryParseValue(const std::string& str, LogLevel& parsedValue);
39 
41  bool TryParseValue(const std::string& str, LogSinkType& parsedValue);
42 
44  bool TryParseValue(const std::string& str, LogColorMode& parsedValue);
45 
47  bool TryParseValue(const std::string& str, bool& parsedValue);
48 
50  bool TryParseValue(const std::string& str, uint8_t& parsedValue);
51 
53  bool TryParseValue(const std::string& str, uint16_t& parsedValue);
54 
56  bool TryParseValue(const std::string& str, uint32_t& parsedValue);
57 
59  bool TryParseValue(const std::string& str, uint64_t& parsedValue);
60 
62  bool TryParseValue(const std::string& str, Amount& parsedValue);
63 
65  bool TryParseValue(const std::string& str, BlockFeeMultiplier& parsedValue);
66 
68  bool TryParseValue(const std::string& str, Height& parsedValue);
69 
71  bool TryParseValue(const std::string& str, Importance& parsedValue);
72 
74  bool TryParseValue(const std::string& str, MosaicId& parsedValue);
75 
77  bool TryParseValue(const std::string& str, TimeSpan& parsedValue);
78 
80  bool TryParseValue(const std::string& str, BlockSpan& parsedValue);
81 
83  bool TryParseValue(const std::string& str, FileSize& parsedValue);
84 
86  bool TryParseValue(const std::string& str, Key& parsedValue);
87 
89  bool TryParseValue(const std::string& str, Hash256& parsedValue);
90 
92  bool TryParseValue(const std::string& str, GenerationHash& parsedValue);
93 
96  bool TryParseValue(const std::string& str, std::string& parsedValue);
97 
100  bool TryParseValue(const std::string& str, std::unordered_set<std::string>& parsedValue);
101 
103  template<typename T, size_t N>
104  bool TryParseEnumValue(const std::array<std::pair<const char*, T>, N>& stringToValueMapping, const std::string& str, T& parsedValue) {
105  auto iter = std::find_if(stringToValueMapping.cbegin(), stringToValueMapping.cend(), [&str](const auto& pair) {
106  return pair.first == str;
107  });
108 
109  if (stringToValueMapping.cend() == iter)
110  return false;
111 
112  parsedValue = iter->second;
113  return true;
114  }
115 
117  template<typename T, size_t N>
119  const std::array<std::pair<const char*, T>, N>& stringToValueMapping,
120  const std::string& str,
121  T& parsedValues) {
122  std::unordered_set<std::string> parts;
123  if (!TryParseValue(str, parts))
124  return false;
125 
126  T values = static_cast<T>(0);
127  for (const auto& part : parts) {
128  T value;
129  if (!TryParseEnumValue(stringToValueMapping, part, value))
130  return false;
131 
132  values |= value;
133  }
134 
135  parsedValues = values;
136  return true;
137  }
138 }}
catapult::utils::BlockSpan::FromDays
static constexpr BlockSpan FromDays(uint64_t days)
Creates a block span from the given number of days.
Definition: BlockSpan.h:45
catapult::Hash256
utils::ByteArray< Hash256_Size, Hash256_tag > Hash256
Definition: src/catapult/types.h:47
catapult::Amount
utils::BaseValue< uint64_t, Amount_tag > Amount
Definition: src/catapult/types.h:76
catapult::utils::LogColorMode::Ansi
Ansi codes.
catapult::Height
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
catapult::utils::LogColorMode
LogColorMode
Catapult (console) log color modes.
Definition: Logging.h:80
catapult::utils::TimeSpan::FromMilliseconds
static constexpr TimeSpan FromMilliseconds(uint64_t milliseconds)
Creates a time span from the given number of milliseconds.
Definition: TimeSpan.h:59
FileSize.h
catapult::utils::LogLevel::Fatal
Level for logging fatal events.
catapult::utils::LogSinkType::Sync
A synchronous sink.
catapult::utils::TimeSpan
Represents a time duration.
Definition: TimeSpan.h:30
catapult::utils::BaseValue< uint64_t, Amount_tag >
catapult::utils::LogLevel::Error
Level for logging error events.
catapult::utils::LogColorMode::AnsiBold
Bold ansi codes.
catapult::utils::TimeSpan::FromSeconds
static constexpr TimeSpan FromSeconds(uint64_t seconds)
Creates a time span from the given number of seconds.
Definition: TimeSpan.h:54
catapult::utils::FileSize::FromMegabytes
static constexpr FileSize FromMegabytes(uint64_t megabytes)
Creates a file size from the given number of megabytes.
Definition: FileSize.h:41
catapult::utils::LogLevel::Debug
Level for logging debug events.
catapult::utils::LogLevel::Info
Level for logging informational events.
catapult::utils::BlockSpan
Represents a block duration.
Definition: BlockSpan.h:28
catapult::utils::LogLevel::Trace
Level for logging trace events.
catapult::utils::TryParseEnumValue
bool TryParseEnumValue(const std::array< std::pair< const char *, T >, N > &stringToValueMapping, const std::string &str, T &parsedValue)
Tries to parse str into an enum value (parsedValue) given a mapping of strings to values (stringToVal...
Definition: ConfigurationValueParsers.h:104
catapult::utils::LogSinkType
LogSinkType
Catapult log sink types.
Definition: Logging.h:67
catapult::utils::TimeSpan::FromHours
static constexpr TimeSpan FromHours(uint64_t hours)
Creates a time span from the given number of hours.
Definition: TimeSpan.h:44
catapult::utils::LogLevel
LogLevel
Catapult log levels.
Definition: Logging.h:36
catapult::utils::TryParseBitwiseEnumValue
bool TryParseBitwiseEnumValue(const std::array< std::pair< const char *, T >, N > &stringToValueMapping, const std::string &str, T &parsedValues)
Tries to parse str into a bitwise enum value (parsedValue) given a mapping of strings to values (stri...
Definition: ConfigurationValueParsers.h:118
catapult::utils::TimeSpan::FromMinutes
static constexpr TimeSpan FromMinutes(uint64_t minutes)
Creates a time span from the given number of minutes.
Definition: TimeSpan.h:49
catapult::utils::FileSize
Represents a file size.
Definition: FileSize.h:29
catapult::utils::LogColorMode::None
No coloring.
catapult::BlockFeeMultiplier
utils::BaseValue< uint32_t, BlockFeeMultiplier_tag > BlockFeeMultiplier
Definition: src/catapult/types.h:91
BlockSpan.h
TimeSpan.h
catapult::utils::BlockSpan::FromHours
static constexpr BlockSpan FromHours(uint64_t hours)
Creates a block span from the given number of hours.
Definition: BlockSpan.h:40
catapult::utils::FileSize::FromKilobytes
static constexpr FileSize FromKilobytes(uint64_t kilobytes)
Creates a file size from the given number of kilobytes.
Definition: FileSize.h:46
catapult::utils::LogLevel::Max
Maximum log level.
types.h
ConfigurationValueParsers.h
catapult::utils::TryParseHexStringIntoContainer
bool TryParseHexStringIntoContainer(const char *const pHexData, size_t dataSize, TContainer &outputContainer)
Tries to parse a hex string (pHexData with size dataSize) into outputContainer.
Definition: HexParser.h:35
catapult::utils::LogSinkType::Async
An asynchronous sink.
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::FileSize::FromBytes
static constexpr FileSize FromBytes(uint64_t bytes)
Creates a file size from the given number of bytes.
Definition: FileSize.h:51
catapult::GenerationHash
utils::ByteArray< Hash256_Size, GenerationHash_tag > GenerationHash
Definition: src/catapult/types.h:53
Base
static constexpr uint8_t Base
Definition: ConfigurationValueParsers.cpp:82
catapult::utils::LogLevel::Min
Minimum log level.
Logging.h
catapult::utils::ByteArray< Key_Size, Key_tag >
HexParser.h
catapult::utils::TryParseValue
bool TryParseValue(const std::string &str, LogLevel &parsedValue)
Tries to parse str into a log level (parsedValue).
Definition: ConfigurationValueParsers.cpp:60
catapult::Key
utils::ByteArray< Key_Size, Key_tag > Key
Definition: src/catapult/types.h:41
catapult::utils::LogLevel::Warning
Level for logging warning events.