OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
OnixS::ICE::BOE::System::ConfigurationParser Namespace Reference

Namespaces

namespace  Utils

Typedefs

using KeyValueMap = std::unordered_map<std::string, std::string>
template<typename C>
using Setter = std::function<void(C&, const std::string&)>
template<typename C>
using Registry = std::unordered_map<std::string, Setter<C>>

Functions

KeyValueMap parseConfigFile (const std::string &fileName, const std::string &rootNode)
void throwCannotApplyConfigurationValue (const std::string &key, const std::string &value)
template<typename C, typename Arg>
Setter< CmakeSetter (C &(C::*mf)(Arg))
template<typename C>
void loadFromFile (const std::string &fileName, C &obj, const Registry< C > &reg, const std::string &rootNode, bool ignoreUnknown=true)

Typedef Documentation

◆ KeyValueMap

using KeyValueMap = std::unordered_map<std::string, std::string>

Definition at line 101 of file ConfigurationParser.h.

◆ Registry

template<typename C>
using Registry = std::unordered_map<std::string, Setter<C>>

Definition at line 111 of file ConfigurationParser.h.

◆ Setter

template<typename C>
using Setter = std::function<void(C&, const std::string&)>

Definition at line 110 of file ConfigurationParser.h.

Function Documentation

◆ loadFromFile()

template<typename C>
void loadFromFile ( const std::string & fileName,
C & obj,
const Registry< C > & reg,
const std::string & rootNode,
bool ignoreUnknown = true )

Loads configuration from the given file.

Definition at line 125 of file ConfigurationParser.h.

126{
127 const auto map = parseConfigFile(fileName, rootNode);
128
129 for (const auto& pair : map)
130 {
131 const auto& key = pair.first;
132 const auto& value = pair.second;
133
134 const auto it = reg.find(key);
135
136 if(it != reg.end())
137 {
138 try
139 {
140 it->second(obj, value);
141 }
142 catch(...)
143 {
145 }
146 }
147 else if (!ignoreUnknown)
148 throw std::invalid_argument("Unknown configuration property '" + key + "'");
149 }
150}
KeyValueMap parseConfigFile(const std::string &fileName, const std::string &rootNode)
Parses the given file to the key-value pair map.
void throwCannotApplyConfigurationValue(const std::string &key, const std::string &value)

◆ makeSetter()

template<typename C, typename Arg>
Setter< C > makeSetter ( C &(C::* mf )(Arg))

Definition at line 114 of file ConfigurationParser.h.

115{
116 using Type = typename std::decay<Arg>::type ;
117 return [mf](C& obj, const std::string& text)
118 {
119 (obj.*mf)(Utils::fromString<Type>(text));
120 };
121}
@ C
Vendor-provided platform billed by executing broker.
Definition Fields.h:180

◆ parseConfigFile()

KeyValueMap parseConfigFile ( const std::string & fileName,
const std::string & rootNode )

Parses the given file to the key-value pair map.

◆ throwCannotApplyConfigurationValue()

void throwCannotApplyConfigurationValue ( const std::string & key,
const std::string & value )