#ifndef SIBS_CONF_HPP #define SIBS_CONF_HPP #include "Result.hpp" #include "StringView.hpp" #include "utils.hpp" #include #include namespace sibs { class ConfigValue { public: enum class Type { NONE, SINGLE, LIST }; ConfigValue() : type(Type::NONE) {} ConfigValue(StringView value) : type(Type::SINGLE) { values.push_back(value); } ConfigValue(const std::vector &_values) : type(Type::LIST), values(_values) { } bool isSingle() const { return type == Type::SINGLE; } bool isList() const { return type == Type::LIST; } StringView asSingle() const { assert(isSingle()); return values[0]; } const std::vector asList() const { assert(isList()); return values; } private: Type type; std::vector values; }; class Parser; class ConfigCallback { friend class Parser; protected: virtual void processObject(StringView name) = 0; virtual void processField(StringView name, const ConfigValue &value) = 0; virtual void finished() = 0; }; class Config { public: static Result readFromFile(const char *filepath, const ConfigCallback &callback); }; } #endif //SIBS_CONF_HPP