#pragma once #include #include #include #include namespace esmb { typedef std::variant ArgumentVariant; typedef std::map ArgumentMap; } // namespace esmb #define MapContainsKey(MAP, KEY) (MAP.find(KEY) != MAP.end()) struct InvalidTypeException : public std::exception { public: InvalidTypeException(std::string ss) : s(ss) {} ~InvalidTypeException() throw() {} const char *what() const throw() { return s.c_str(); } private: std::string s; }; template T GetArgument(esmb::ArgumentMap map, std::string key) { if (!MapContainsKey(map, key)) throw InvalidTypeException("Invalid requested type from variant."); return std::get(map.at(key)); } template T GetArgumentWithFallback(esmb::ArgumentMap map, std::string key, T fallback) { if (!MapContainsKey(map, key)) return fallback; return std::get(map.at(key)); }