1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-10-18 15:29:24 +00:00
kamokan/src/kamokan_impl/settings_bag.hpp
King_DuckZ 8d19c794ed Extract string conversion functions from SettingsBag.
It's useful to have this functionality elsewhere, especially
the string to bool one which I'm going to use in the next
commit.
2017-06-14 19:30:52 +01:00

60 lines
2 KiB
C++

/* Copyright 2017, Michele Santullo
* This file is part of "kamokan".
*
* "kamokan" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "kamokan" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "kamokan". If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "ini_file.hpp"
#include "kakoune/safe_ptr.hh"
#if defined(SPDLOG_DEBUG_ON)
# include "spdlog.hpp"
#endif
#include "string_conv.hpp"
#include <map>
#include <boost/utility/string_view.hpp>
#include <functional>
#include <string>
namespace kamokan {
class SettingsBag : public Kakoune::SafeCountable {
typedef std::map<boost::string_view, boost::string_view> MapType;
public:
SettingsBag (const Kakoune::SafePtr<IniFile>& parIni, boost::string_view parSectionName);
~SettingsBag() noexcept;
const boost::string_view& operator[] (boost::string_view parIndex) const;
const boost::string_view& at (boost::string_view parIndex) const;
template <typename T> T as (boost::string_view parIndex) const;
void add_default (boost::string_view parKey, boost::string_view parValue);
private:
MapType m_defaults;
Kakoune::SafePtr<IniFile> m_ini;
const IniFile::KeyValueMapType* m_values;
};
template <typename T>
inline T SettingsBag::as (boost::string_view parIndex) const {
return string_conv<T>(this->at(parIndex));
}
inline const boost::string_view& SettingsBag::at (boost::string_view parIndex) const {
#if defined(SPDLOG_DEBUG_ON)
SPDLOG_DEBUG(spdlog::get("statuslog"), "Retrieving setting \"{}\"", parIndex);
#endif
return (*this)[parIndex];
}
} //namespace kamokan