aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-06-12 15:32:53 -0400
committerYour Name <you@example.com>2021-06-12 15:32:53 -0400
commit01293baa64fa905c5763020bd6c0b4903d41fc78 (patch)
tree4c49a63852fd84ead388a8fd092d64d2df7f9e1b /src/utils.h
parentb27700a7e0b281ece3dea23060c17e0cae28715d (diff)
downloaddmtool-01293baa64fa905c5763020bd6c0b4903d41fc78.tar.gz
dmtool-01293baa64fa905c5763020bd6c0b4903d41fc78.tar.bz2
dmtool-01293baa64fa905c5763020bd6c0b4903d41fc78.zip
Verified some creature attacks
Diffstat (limited to 'src/utils.h')
-rw-r--r--src/utils.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h
index 005e5be..77096e7 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -7,6 +7,7 @@
#include <map>
#include <sstream>
#include <memory>
+#include <optional>
#include <stdexcept>
#include <filesystem>
@@ -23,6 +24,23 @@ namespace nlohmann {
opt = std::shared_ptr<T>(T::create(j));
}
};
+
+ template <typename T> struct adl_serializer<std::optional<T>> {
+ static void to_json(json& j, const std::optional<T>& opt) {
+ if(opt) {
+ j = *opt;
+ } else {
+ j = nullptr;
+ }
+ }
+ static void from_json(const json& j, std::optional<T>& opt) {
+ if(j.is_null()) {
+ opt = std::optional<T>();
+ } else {
+ opt = j.get<T>();
+ }
+ }
+ };
}
namespace utils {