diff options
Diffstat (limited to 'include/Conf.hpp')
-rw-r--r-- | include/Conf.hpp | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp index 2b38e95..c27046b 100644 --- a/include/Conf.hpp +++ b/include/Conf.hpp @@ -2,11 +2,73 @@ #define SIBS_CONF_HPP #include "Result.hpp" -#include <string> +#include "StringView.hpp" +#include "utils.hpp" +#include <vector> +#include <cassert> namespace sibs { - Result<std::string> readConf(const char *filepath); + 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<StringView> &_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<StringView> asList() const + { + assert(isList()); + return values; + } + private: + Type type; + std::vector<StringView> 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<bool> readFromFile(const char *filepath, const ConfigCallback &callback); + }; } #endif //SIBS_CONF_HPP |