#pragma once #include #include #include namespace jvalidate::constraint { /** * @brief A plugin class that allows the for Domain-Specific Grammers to be * implemented for a json-schema. * * These custom Constraints are implemented by creating two extension classes: * - A constraint inheriting from {@see jvalidate::ConstraintBase}, which in * turn inherits from ExtensionConstraint::Impl. This acts as a simple data * wrapper for describing the Constraint. * - A visitor inheriting from {@see jvalidate::extension::Visitor}. * * https://json-schema.org/draft/2020-12/json-schema-core#section-6.5 */ struct ExtensionConstraint { public: struct Impl { virtual ~Impl() = default; virtual Status visit(extension::VisitorBase const &) const = 0; }; public: /** * @brief Convenience function for constructing this ExtensionConstraint from * the concrete underlying extension in the format that is required for use * with {@see jvalidate::ConstraintFactory}. * * @tparam T A concrete type subtyping ExtensionConstraint::Impl * @tparam Args The argument types for initializing the object * * @params args... The constructor arguments for T * * @return A unique_ptr to a new ExtensionConstraint of underlying type T, * wrapped in the Constraint variant type. */ template static std::unique_ptr make(Args &&... args) { return std::make_unique( ExtensionConstraint{std::make_unique(std::forward(args)...)}); } public: std::unique_ptr pimpl; }; }