aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Conf.hpp12
-rw-r--r--include/FileUtil.hpp24
-rw-r--r--include/Result.hpp45
3 files changed, 81 insertions, 0 deletions
diff --git a/include/Conf.hpp b/include/Conf.hpp
new file mode 100644
index 0000000..2b38e95
--- /dev/null
+++ b/include/Conf.hpp
@@ -0,0 +1,12 @@
+#ifndef SIBS_CONF_HPP
+#define SIBS_CONF_HPP
+
+#include "Result.hpp"
+#include <string>
+
+namespace sibs
+{
+ Result<std::string> readConf(const char *filepath);
+}
+
+#endif //SIBS_CONF_HPP
diff --git a/include/FileUtil.hpp b/include/FileUtil.hpp
new file mode 100644
index 0000000..402f5f1
--- /dev/null
+++ b/include/FileUtil.hpp
@@ -0,0 +1,24 @@
+#ifndef SIBS_FILEUTIL_HPP
+#define SIBS_FILEUTIL_HPP
+
+#include "../external/tinydir.h"
+#include "Result.hpp"
+#include <functional>
+
+namespace sibs
+{
+ using FileWalkCallbackFunc = std::function<void(tinydir_file*)>;
+
+ enum class FileType
+ {
+ FILE_NOT_FOUND,
+ REGULAR,
+ DIRECTORY
+ };
+
+ FileType getFileType(const char *path);
+ void walkDirectory(const char *directory, FileWalkCallbackFunc callbackFunc);
+ Result<std::string> getFileContent(const char *filepath);
+}
+
+#endif //SIBS_FILEUTIL_HPP
diff --git a/include/Result.hpp b/include/Result.hpp
new file mode 100644
index 0000000..31f9e4d
--- /dev/null
+++ b/include/Result.hpp
@@ -0,0 +1,45 @@
+#ifndef SIBS_RESULT_HPP
+#define SIBS_RESULT_HPP
+
+#include <cassert>
+
+namespace sibs
+{
+ template <typename T>
+ class Result
+ {
+ public:
+ static Result Ok(const T &value)
+ {
+ return Result(value);
+ }
+
+ static Result Err(const char *errMsg)
+ {
+ return Result(errMsg);
+ }
+
+ bool isOk() const { return !errMsg; }
+ bool isErr() const { return errMsg; }
+
+ T& unwrap()
+ {
+ assert(isOk());
+ return value;
+ }
+
+ const char *getErrMsg() const
+ {
+ assert(isErr());
+ return errMsg;
+ }
+ private:
+ Result(const T &_value) : value(_value), errMsg(nullptr){}
+ Result(const char *_errMsg) : errMsg(_errMsg){}
+ private:
+ T value;
+ const char *errMsg;
+ };
+}
+
+#endif //SIBS_RESULT_HPP