| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #pragma once
- #include <memory>
- #include <jvalidate/forward.h>
- #include <jvalidate/status.h>
- 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 <typename T, typename... Args> static std::unique_ptr<Constraint> make(Args &&... args) {
- return std::make_unique<Constraint>(
- ExtensionConstraint{std::make_unique<T>(std::forward<Args>(args)...)});
- }
- public:
- std::unique_ptr<Impl> pimpl;
- };
- }
|