3 #include <fc/exception/exception.hpp>
5 #include <boost/algorithm/string.hpp>
9 const std::string config_api::default_api_name =
"api";
11 config_api::configs_by_api_type config_api::_instances_by_api = config_api::configs_by_api_type();
15 , max_blockchain_history_depth(_max_blockchain_history_depth)
16 , max_blocks_history_depth(_max_blocks_history_depth)
17 , max_budgets_list_size(_max_budgets_list_size)
18 , max_discussions_list_size(_max_discussions_list_size)
19 , lookup_limit(_lookup_limit)
20 , tags_to_analize_count(_tags_to_analize_count)
21 , max_timestamp_range_in_s(_max_timestamp_range_in_s)
26 : _api_name(config.api_name())
27 , _max_blockchain_history_depth(config._max_blockchain_history_depth)
28 , _max_blocks_history_depth(config._max_blocks_history_depth)
29 , _max_budgets_list_size(config._max_budgets_list_size)
30 , _max_discussions_list_size(config._max_discussions_list_size)
31 , _lookup_limit(config._lookup_limit)
32 , _tags_to_analize_count(config._tags_to_analize_count)
33 , _max_timestamp_range_in_s(config._max_timestamp_range_in_s)
34 , max_blockchain_history_depth(_max_blockchain_history_depth)
35 , max_blocks_history_depth(_max_blocks_history_depth)
36 , max_budgets_list_size(_max_budgets_list_size)
37 , max_discussions_list_size(_max_discussions_list_size)
38 , lookup_limit(_lookup_limit)
39 , tags_to_analize_count(_tags_to_analize_count)
40 , max_timestamp_range_in_s(_max_timestamp_range_in_s)
44 namespace bpo = boost::program_options;
46 #define STR(field) BOOST_PP_STRINGIZE(field)
50 bpo::options_description result;
51 bpo::options_description_easy_init options(&result);
70 set_option<uint32_t>(options, clean_config._lookup_limit,
STR(
lookup_limit));
78 template <
typename MemberType>
79 void config_api::get_option_description(bpo::options_description_easy_init& options,
const char* member_name)
const
81 options(get_option_name(member_name,
api_name()).c_str(), bpo::value<MemberType>(),
82 get_option_description(member_name).c_str());
85 template <
typename MemberType>
86 void config_api::set_option(
const bpo::variables_map& options, MemberType& member,
const char* member_name)
88 if (options.count(get_option_name(member_name,
api_name())))
90 member = options.at(get_option_name(member_name,
api_name())).as<MemberType>();
92 else if (options.count(get_option_name(member_name, default_api_name)))
94 member = options.at(get_option_name(member_name, default_api_name)).as<MemberType>();
98 std::string config_api::get_option_name(
const char* field,
const std::string& api_name)
const
103 return boost::algorithm::replace_all_copy(result,
"_",
"-");
106 std::string config_api::get_option_description(
const char* field)
const
108 std::string result = boost::algorithm::replace_all_copy(std::string(field),
"_",
" ");
109 result +=
" option for ";
116 if (api_name.empty())
117 api_name = config_api::default_api_name;
119 auto config_it = config_api::_instances_by_api.find(api_name);
120 if (config_api::_instances_by_api.end() == config_it)
123 = config_api::_instances_by_api.emplace(api_name, std::unique_ptr<config_api>(
new config_api(api_name)))
126 return (*config_it->second);
void set_options(const boost::program_options::variables_map &options)
const uint32_t & max_timestamp_range_in_s
boost::program_options::options_description get_options_descriptions() const
const uint32_t & max_blocks_history_depth
const std::string & api_name() const
const uint32_t & tags_to_analize_count
const uint32_t & max_budgets_list_size
const uint32_t & lookup_limit
const uint32_t & max_discussions_list_size
const uint32_t & max_blockchain_history_depth
config_api & get_api_config(std::string api_name)