1 #ifndef _STATEFS_CONFIG_HPP_
2 #define _STATEFS_CONFIG_HPP_
4 #include <cor/sexp.hpp>
5 #include <cor/notlisp.hpp>
7 #include <boost/variant.hpp>
13 static inline std::string cfg_extension()
18 static inline std::string cfg_provider_prefix()
23 static inline std::string cfg_loader_prefix()
28 namespace nl = cor::notlisp;
30 typedef boost::variant<long, unsigned long, double, std::string> property_type;
31 typedef std::unordered_map<std::string, property_type> property_map_type;
33 void to_property(nl::expr_ptr expr, property_type &dst);
34 std::string to_string(property_type
const &p);
35 std::string to_nl_string(property_type
const &p);
37 long to_integer(property_type
const &src);
50 property_type
const &defval,
51 unsigned access = Read);
53 std::string defval()
const;
55 unsigned access()
const
60 int mode(
int umask = 0027)
const;
63 property_type defval_;
70 typedef std::shared_ptr<Property> prop_type;
71 typedef std::list<prop_type> storage_type;
80 Library(std::string
const &name, std::string
const &path);
88 typedef std::shared_ptr<Namespace> ns_type;
89 typedef std::list<ns_type> storage_type;
90 Plugin(std::string
const &name
91 , std::string
const &path
92 , property_map_type &&info
93 , storage_type &&namespaces);
96 property_map_type info_;
97 storage_type namespaces_;
103 Loader(std::string
const &name, std::string
const &path);
106 nl::env_ptr mk_parse_env();
108 template <
typename CharT,
typename ReceiverT>
109 void parse(std::basic_istream<CharT> &input, ReceiverT receiver)
113 env_ptr env(mk_parse_env());
115 Interpreter config(env);
116 cor::error_tracer([&input, &config]()
117 { cor::sexp::parse(input, config); });
119 ListAccessor res(config.results());
120 rest_casted<Library>(res, receiver);
123 typedef std::function<void (std::string
const &
124 , std::shared_ptr<Library>) > config_receiver_fn;
126 bool from_file(std::string
const &, config_receiver_fn);
131 virtual void provider_add(std::shared_ptr<Plugin>) =0;
132 virtual void provider_rm(std::shared_ptr<Plugin>) =0;
133 virtual void loader_add(std::shared_ptr<Loader>) =0;
134 virtual void loader_rm(std::shared_ptr<Loader>) =0;
141 #endif // _STATEFS_CONFIG_HPP_