#pragma once #include #include #include #include #define PERSISTENT_PROPERTY_DIR "/data/property" struct prop_cb { virtual void exec(const char *name, const char *value) = 0; }; template struct prop_cb_impl : public prop_cb { typedef void (*callback_type)(const char *, const char *, T&); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdangling-field" // Dangling field is expected prop_cb_impl(T &arg, callback_type fn) : arg(arg), fn(fn) {} #pragma GCC diagnostic pop void exec(const char *name, const char *value) override { fn(name, value, arg); } private: T &arg; callback_type fn; }; extern bool use_pb; using prop_list = std::map; struct prop_collector : prop_cb_impl { prop_collector(prop_list &list) : prop_cb_impl(list, [](auto name, auto val, auto list){ list.emplace(name, val); }) {} }; template prop_cb_impl make_prop_cb(T &arg, Func f) { return prop_cb_impl(arg, f); } std::string persist_getprop(const char *name); void persist_getprops(prop_cb *prop_cb); bool persist_deleteprop(const char *name); void persist_cleanup();