aboutsummaryrefslogtreecommitdiff
path: root/include/Conf.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-09 01:14:41 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-09 01:14:47 +0100
commitfb2072deb3e50afdb062570a3a80ec1afb5bfb56 (patch)
tree44baddd61a9aac3ead96ac8a6fab95d087d0bdd7 /include/Conf.hpp
parentbf24f6fc48b4eebb06cdcd7029d1d31d4c6028dd (diff)
Finished project config file parsing
Diffstat (limited to 'include/Conf.hpp')
-rw-r--r--include/Conf.hpp66
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