12 #include <iniparser.h> 30 kv_type(
const char* k,
const char* v): key(k), val(v) {}
33 ini_dict_impl(
const std::string& inifile)
34 : inidict_(iniparser_load(inifile.c_str()))
36 if (!inidict_)
throw std::runtime_error(
"Cannot read INI file " + inifile);
40 if (inidict_) iniparser_freedict(inidict_);
44 std::size_t
size()
const;
47 kv_type get_kv(
const std::size_t i)
const;
53 if (n<0)
throw std::runtime_error(
"Dictionary is invalid: negative number of entries");
54 return static_cast<std::size_t
>(n);
57 ini_dict_impl::kv_type ini_dict_impl::get_kv(
const std::size_t i)
const 59 if (i>=this->
size())
throw std::out_of_range(
"Access beyond the end of the dictionary");
60 return kv_type(inidict_->key[i], inidict_->val[i]);
66 iniparser::iniparser(
const std::string& inifile) : ini_dict_ptr_(new ini_dict_impl(inifile))
69 iniparser::~iniparser()
72 iniparser::kv_container_type iniparser::operator()()
const 74 kv_container_type kv_vec;
77 std::size_t inidict_sz=ini_dict_ptr_->size();
79 kv_vec.reserve(inidict_sz);
80 for (std::size_t i=0; i<inidict_sz; ++i) {
81 ini_dict_impl::kv_type kv=ini_dict_ptr_->get_kv(i);
82 if (kv.val && kv.key) {
83 kv_vec.push_back(std::make_pair(std::string(kv.key),std::string(kv.val)));
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)