38 lines
1.8 KiB
C++
38 lines
1.8 KiB
C++
#ifndef __APPLICATIONSETTINGS_H__
|
|
#define __APPLICATIONSETTINGS_H__
|
|
|
|
#include <boost/asio/io_context.hpp>
|
|
#include <boost/asio/steady_timer.hpp>
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
class ApplicationSettings {
|
|
#define BUILD_SETTING_FIELD(Category, Type, Name, DefaultValue) \
|
|
inline void set##Name(const Type &value) { \
|
|
std::lock_guard locker(m_mutex); \
|
|
m_ptree.put(#Category "." #Name, value); \
|
|
m_needSave = true; \
|
|
} \
|
|
inline Type get##Name() const { \
|
|
std::lock_guard locker(m_mutex); \
|
|
return m_ptree.get<Type>(#Category "." #Name, DefaultValue); \
|
|
}
|
|
|
|
#define BUILD_STATUS(Type, Name, DefaultValue) BUILD_SETTING_FIELD(Status, Type, Name, DefaultValue)
|
|
|
|
public:
|
|
ApplicationSettings(boost::asio::io_context &ioContext, const std::string &path);
|
|
|
|
protected:
|
|
void run();
|
|
|
|
boost::property_tree::ptree m_ptree;
|
|
bool m_needSave = false;
|
|
mutable std::mutex m_mutex;
|
|
|
|
private:
|
|
boost::asio::io_context &m_ioContext;
|
|
boost::asio::steady_timer m_timer;
|
|
std::string m_path;
|
|
};
|
|
|
|
#endif // __APPLICATIONSETTINGS_H__
|