OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
Settings.h
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19#pragma once
20
22#include <string>
23
24namespace Samples {
25
26using namespace ONIXS_ICEBOE_NAMESPACE;
27
29{
30public:
31 Settings() = default;
32
33 Settings(const std::string& filename)
34 : map_(System::ConfigurationParser::parseConfigFile(filename, "TradingClient"))
35 {
36 }
37
38 template<typename T = std::string>
39 T get(const std::string& key, typename std::enable_if<std::is_integral<T>::value, void*>::type = nullptr) const
40 {
42 }
43
44 template<typename T = std::string>
45 T get(const std::string& key, T defaultValue, typename std::enable_if<std::is_integral<T>::value, void*>::type = nullptr) const
46 {
47 const auto v = getIfAny(key);
48 return v.empty() ? defaultValue : System::ConfigurationParser::Utils::fromString<T>(v);
49 }
50
51 template<typename T = std::string>
52 T get(const std::string& key, typename std::enable_if<std::is_same<T, std::string>::value, void*>::type = nullptr) const
53 {
54 return getAsStr(key);
55 }
56
57 template<typename T = std::string>
58 T get(const std::string& key, T defaultValue, typename std::enable_if<std::is_same<T, std::string>::value, void*>::type = nullptr) const
59 {
60 return getAsStr(key, defaultValue);
61 }
62
63 template<typename T = std::string>
64 T get(const std::string& key, typename std::enable_if<std::is_same<T, bool>::value, void*>::type = nullptr) const
65 {
67 }
68
69 template<typename T = std::string>
70 T get(const std::string& key, T defaultValue, typename std::enable_if<std::is_same<T, bool>::value, void*>::type = nullptr) const
71 {
72 const auto v = getIfAny(key);
73 return v.empty() ? defaultValue : System::ConfigurationParser::Utils::fromString<bool>(getAsStr(v));
74 }
75
76 bool isSet(const std::string& key) const
77 {
78 return map_.find(key) != map_.end();
79 }
80
81private:
82 std::string getAsStr(const std::string& key) const
83 {
84 const auto it = map_.find(key);
85
86 if (it == map_.end())
87 throw std::domain_error("There is no setting '" + key +"' available.");
88
89 return it->second;
90 }
91
92 std::string getAsStr(const std::string& key, const std::string& defaultValue) const
93 {
94 const auto it = map_.find(key);
95 return (it == map_.end()) ? defaultValue : it->second;
96 }
97
98 std::string getIfAny(const std::string& key) const
99 {
100 return getAsStr(key, {});
101 }
102
103private:
105};
106
107}
#define ONIXS_ICEBOE_NAMESPACE
Definition ABI.h:113
T get(const std::string &key, T defaultValue, typename std::enable_if< std::is_same< T, std::string >::value, void * >::type=nullptr) const
Definition Settings.h:58
Settings(const std::string &filename)
Definition Settings.h:33
Settings()=default
T get(const std::string &key, typename std::enable_if< std::is_integral< T >::value, void * >::type=nullptr) const
Definition Settings.h:39
T get(const std::string &key, typename std::enable_if< std::is_same< T, std::string >::value, void * >::type=nullptr) const
Definition Settings.h:52
T get(const std::string &key, T defaultValue, typename std::enable_if< std::is_integral< T >::value, void * >::type=nullptr) const
Definition Settings.h:45
T get(const std::string &key, T defaultValue, typename std::enable_if< std::is_same< T, bool >::value, void * >::type=nullptr) const
Definition Settings.h:70
T get(const std::string &key, typename std::enable_if< std::is_same< T, bool >::value, void * >::type=nullptr) const
Definition Settings.h:64
bool isSet(const std::string &key) const
Definition Settings.h:76
std::unordered_map< std::string, std::string > KeyValueMap