Loading...
Searching...
No Matches
validation_criteria.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <mongocxx/validation_criteria-fwd.hpp> // IWYU pragma: export
#include <bsoncxx/document/view_or_value.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <mongocxx/config/prelude.hpp>
namespace mongocxx {
namespace v_noabi {
class validation_criteria {
public:
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(validation_criteria&)
rule(bsoncxx::v_noabi::document::view_or_value rule);
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> const&)
rule() const;
enum class validation_level {
k_off,
k_moderate,
k_strict,
};
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(validation_criteria&) level(validation_level level);
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::stdx::optional<validation_level> const&)
level() const;
enum class validation_action {
k_error,
k_warn,
};
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(validation_criteria&) action(validation_action action);
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::stdx::optional<validation_action> const&)
action() const;
MONGOCXX_DEPRECATED MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::document::value) to_document() const;
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bsoncxx::v_noabi::document::value) to_document_deprecated() const;
MONGOCXX_DEPRECATED operator bsoncxx::v_noabi::document::value() const {
return to_document_deprecated();
}
private:
bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view_or_value> _rule;
bsoncxx::v_noabi::stdx::optional<validation_level> _level;
bsoncxx::v_noabi::stdx::optional<validation_action> _action;
};
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool)
operator==(validation_criteria const& lhs, validation_criteria const& rhs);
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(bool)
operator!=(validation_criteria const& lhs, validation_criteria const& rhs);
} // namespace v_noabi
} // namespace mongocxx
namespace mongocxx {
using v_noabi::operator==;
using v_noabi::operator!=;
} // namespace mongocxx
#include <mongocxx/config/postlude.hpp>
bsoncxx::v1::stdx::optional
A polyfill for std::optional<T>.
Definition optional.hpp:799
mongocxx::v_noabi::validation_criteria
Supports creating validation rules for fields.
Definition validation_criteria.hpp:36
mongocxx::v_noabi::validation_criteria::rule
validation_criteria & rule(bsoncxx::v_noabi::document::view_or_value rule)
Sets a validation rule for this validation object.
mongocxx::v_noabi::validation_criteria::level
validation_criteria & level(validation_level level)
Sets a validation level.
mongocxx::v_noabi::validation_criteria::value
operator bsoncxx::v_noabi::document::value() const
Definition validation_criteria.hpp:148
mongocxx::v_noabi::validation_criteria::validation_action
validation_action
A class to represent the different validation action options.
Definition validation_criteria.hpp:99
mongocxx::v_noabi::validation_criteria::validation_action::k_error
@ k_error
Reject any insertion or update that violates the validation criteria.
Definition validation_criteria.hpp:101
mongocxx::v_noabi::validation_criteria::validation_action::k_warn
@ k_warn
Log any violations of the validation criteria, but allow the insertion or update to proceed.
Definition validation_criteria.hpp:105
mongocxx::v_noabi::validation_criteria::validation_level
validation_level
A class to represent the different validation level options.
Definition validation_criteria.hpp:63
mongocxx::v_noabi::validation_criteria::validation_level::k_moderate
@ k_moderate
Apply validation rules to inserts, and apply validation rules to updates only if the document to be u...
Definition validation_criteria.hpp:69
mongocxx::v_noabi::validation_criteria::validation_level::k_strict
@ k_strict
Apply validation rules to all inserts and updates.
Definition validation_criteria.hpp:72
mongocxx::v_noabi::validation_criteria::validation_level::k_off
@ k_off
Disable validation entirely.
Definition validation_criteria.hpp:65
mongocxx::v_noabi::validation_criteria::action
validation_criteria & action(validation_action action)
Sets a validation action to run when documents failing validation are inserted or modified.
mongocxx::v_noabi::validation_criteria::to_document
bsoncxx::v_noabi::document::value to_document() const
Returns a bson document representing this set of validation criteria.
view_or_value.hpp
Provides bsoncxx::v_noabi::document::view_or_value.
MONGOCXX_DEPRECATED
#define MONGOCXX_DEPRECATED
Declares the associated entity as deprecated.
Definition export.hpp:25
MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The mongocxx v_noabi macro guard postlude header.
prelude.hpp
The mongocxx v_noabi macro guard prelude header.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
mongocxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
mongocxx
The top-level namespace within which all mongocxx library entities are declared.
optional.hpp
Provides std::optional-related polyfills for library API usage.
validation_criteria-fwd.hpp
Declares mongocxx::v_noabi::validation_criteria.