📄 settingsini.hpp
字号:
// Copyright E骾n O'Callaghan 2008 - 2008.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#include "auxiliary/txml_oarchive.hpp"
#include "auxiliary/txml_iarchive.hpp"
#include "auxiliary/txml_ini_adapter.hpp"
template <class T>
class SettingsIni
{
public:
SettingsIni(boost::filesystem::path location, std::string name, aux::txml_ini& ini) :
adapter_(location, ini),
name_(name)
{}
SettingsIni(std::string name, aux::txml_ini& ini) :
adapter_(boost::filesystem::path(""), ini),
name_(name)
{}
void SaveSettings()
{
std::stringstream xml_data;
{
aux::xml::txml_oarchive oxml(xml_data);
T* pT = static_cast<T*>(this);
oxml << boost::serialization::make_nvp(name_.c_str(), *pT);
}
adapter_.save_stream_data(xml_data);
}
void LoadSettings()
{
std::stringstream xml_data;
if (adapter_.load_stream_data(xml_data))
{
try
{
aux::xml::txml_iarchive ixml(xml_data);
T* pT = static_cast<T*>(this);
ixml >> boost::serialization::make_nvp(name_.c_str(), *pT);
}
catch (const std::exception&)
{
// hal::event_log.post(boost::shared_ptr<hal::EventDetail>(
// new hal::EventXmlException(hal::from_utf8(e.what()), hal::from_utf8(name_))));
}
}
}
private:
aux::txml_ini_adapter adapter_;
std::string name_;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -