mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-12-27 21:35:41 +00:00
Do the str to int conversion in the SettingsBag.
This commit is contained in:
parent
fe53ea7ea1
commit
79e82e2489
2 changed files with 36 additions and 4 deletions
|
@ -22,7 +22,6 @@
|
|||
#include "duckhandy/stringize.h"
|
||||
#include "pathname/pathname.hpp"
|
||||
#include "list_highlight_langs.hpp"
|
||||
#include "duckhandy/lexical_cast.hpp"
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
|
@ -60,7 +59,7 @@ namespace tawashi {
|
|||
if (parSettings["redis_mode"] == "inet") {
|
||||
return IncRedis(
|
||||
parSettings.as<std::string>("redis_server"),
|
||||
dhandy::lexical_cast<uint16_t>(parSettings["redis_port"])
|
||||
parSettings.as<uint16_t>("redis_port")
|
||||
);
|
||||
}
|
||||
else if (parSettings["redis_mode"] == "sock") {
|
||||
|
@ -136,7 +135,7 @@ namespace tawashi {
|
|||
if (m_redis) {
|
||||
m_redis->wait_for_connect();
|
||||
auto batch = m_redis->make_batch();
|
||||
batch.select(dhandy::lexical_cast<int>((*m_settings)["redis_db"]));
|
||||
batch.select(m_settings->as<int>("redis_db"));
|
||||
batch.client_setname("tawashi_v" STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH));
|
||||
batch.throw_if_failed();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
*/
|
||||
|
||||
#include "settings_bag.hpp"
|
||||
#include "duckhandy/lexical_cast.hpp"
|
||||
#include <ciso646>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
|
||||
namespace tawashi {
|
||||
SettingsBag::SettingsBag (const Kakoune::SafePtr<IniFile>& parIni) :
|
||||
|
@ -43,9 +47,38 @@ namespace tawashi {
|
|||
|
||||
template <>
|
||||
std::string SettingsBag::as (boost::string_ref parIndex) const {
|
||||
auto& setting = (*this)[parIndex];
|
||||
auto& setting = this->at(parIndex);
|
||||
return std::string(setting.data(), setting.size());
|
||||
}
|
||||
|
||||
template <>
|
||||
bool SettingsBag::as (boost::string_ref parIndex) const {
|
||||
auto& setting = this->at(parIndex);
|
||||
if (setting == "true" or setting == "yes" or setting == "1" or setting == "on") {
|
||||
return true;
|
||||
}
|
||||
else if (setting == "false" or setting == "no" or setting == "0" or setting == "off") {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
std::ostringstream oss;
|
||||
oss << "Bad conversion: can't convert \"" << setting << "\" to bool";
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
uint16_t SettingsBag::as (boost::string_ref parIndex) const {
|
||||
return dhandy::lexical_cast<uint16_t>(this->at(parIndex));
|
||||
}
|
||||
|
||||
template <>
|
||||
int SettingsBag::as (boost::string_ref parIndex) const {
|
||||
return dhandy::lexical_cast<int>(this->at(parIndex));
|
||||
}
|
||||
|
||||
template std::string SettingsBag::as<std::string> (boost::string_ref parIndex) const;
|
||||
template bool SettingsBag::as<bool> (boost::string_ref parIndex) const;
|
||||
template uint16_t SettingsBag::as<uint16_t> (boost::string_ref parIndex) const;
|
||||
template int SettingsBag::as<int> (boost::string_ref parIndex) const;
|
||||
} //namespace tawashi
|
||||
|
|
Loading…
Reference in a new issue