#pragma once #include #include #include #include #include #include namespace jvalidate::adapter { inline std::ostream & operator<<(std::ostream & os, Type type) { switch (type) { case Type::Null: return os << "null"; case Type::Boolean: return os << "boolean"; case Type::Integer: return os << "integer"; case Type::Number: return os << "number"; case Type::String: return os << "string"; case Type::Array: return os << "array"; case Type::Object: return os << "object"; } } } namespace jvalidate::schema { inline std::ostream & operator<<(std::ostream & os, Version version) { switch (version) { case Version::Draft03: return os << "draft3"; case Version::Draft04: return os << "draft4"; case Version::Draft06: return os << "draft6"; case Version::Draft07: return os << "draft7"; case Version::Draft2019_09: return os << "draft2019-09"; case Version::Draft2020_12: return os << "draft2020-12"; } } } namespace jvalidate { inline std::ostream & operator<<(std::ostream & os, Status st) { if (st == Status::Accept) { return os << "Accept"; } if (st == Status::Reject) { return os << "Reject"; } return os << "Noop"; } template inline std::ostream & operator<<(std::ostream & os, std::set const & data) { if (data.size() == 1) { return os << *data.begin(); } os << '['; std::string div = " "; for (auto const & elem : data) { os << std::exchange(div, ", ") << elem; } return os << ' ' << ']'; } template inline std::ostream & operator<<(std::ostream & os, std::unordered_set const & data) { if (data.size() == 1) { return os << *data.begin(); } os << '['; std::string div = " "; for (auto const & elem : data) { os << std::exchange(div, ", ") << elem; } return os << ' ' << ']'; } template requires(std::is_constructible_v) // Optimization to avoid running string-like objects through a // std::stringstream in fmtlist. static std::string to_string(S const & str) { return std::string(str); } // Format va_args into a single string to annotate or mark an error message static std::string to_string(auto const &... args) { std::stringstream ss; using ::jvalidate::operator<<; [[maybe_unused]] int _[] = {(ss << args, 0)...}; return ss.str(); } // Format an iterable argument into a vector of strings to annotate or mark // an error. static std::vector to_string_list(auto const & arg) { std::vector strs; for (auto const & elem : arg) { strs.push_back(::jvalidate::to_string(elem)); } return strs; } }