From fb2072deb3e50afdb062570a3a80ec1afb5bfb56 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 9 Dec 2017 01:14:41 +0100 Subject: Finished project config file parsing --- include/Conf.hpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'include/Conf.hpp') 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 +#include "StringView.hpp" +#include "utils.hpp" +#include +#include namespace sibs { - Result 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 &_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 -- cgit v1.2.3-70-g09d2