#pragma once #include "Properties.h" #include "ServerProperties.h" #include #include #include #include using std::string; using std::string_view; using std::unordered_map; namespace Feather { template class Property { public: Property(string_view key) : key(key) {} Property(string_view key, T defaultValue) : key(key), value(defaultValue) {} Property(string_view key, std::function op, T defaultValue) : key(key), op(op), value(defaultValue) {} void Init(Properties *properties) { try { SetValue(properties->Get(key)); } catch (std::out_of_range err) { // process default value from constructor SetValue(value); } } virtual void SetValue(T value) { if (op) { this->value = op(value); } else { this->value = value; } } virtual T GetValue() { return value; } inline string ToString() { return std::to_string(value); } string_view key; private: T value = T(); std::function op; }; template <> inline string Property::ToString() { return value; } template <> inline string Property::ToString() { return value ? "true" : "false"; } }