diff options
author | Your Name <you@example.com> | 2021-06-12 15:32:53 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2021-06-12 15:32:53 -0400 |
commit | 01293baa64fa905c5763020bd6c0b4903d41fc78 (patch) | |
tree | 4c49a63852fd84ead388a8fd092d64d2df7f9e1b /src/utils.h | |
parent | b27700a7e0b281ece3dea23060c17e0cae28715d (diff) | |
download | dmtool-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.h | 18 |
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 { |