MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
validation_criteria.hpp
1 // Copyright 2015 MongoDB Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <bsoncxx/document/view_or_value.hpp>
18 #include <bsoncxx/stdx/optional.hpp>
19 #include <mongocxx/stdx.hpp>
20 
21 #include <mongocxx/config/prelude.hpp>
22 
23 namespace mongocxx {
24 inline namespace v_noabi {
30 class MONGOCXX_API validation_criteria {
31  public:
42  validation_criteria& rule(bsoncxx::document::view_or_value rule);
43 
50  const stdx::optional<bsoncxx::document::view_or_value>& rule() const;
51 
60  enum class validation_level {
61  k_off,
62  k_moderate,
63  k_strict,
64  };
65 
77 
84  const stdx::optional<validation_level>& level() const;
85 
93  enum class validation_action {
94  k_error,
95  k_warn,
96  };
97 
109 
117  const stdx::optional<validation_action>& action() const;
118 
128  MONGOCXX_DEPRECATED bsoncxx::document::value to_document() const;
129  bsoncxx::document::value to_document_deprecated() const;
130 
136  MONGOCXX_DEPRECATED MONGOCXX_INLINE operator bsoncxx::document::value() const;
137 
138  private:
139  stdx::optional<bsoncxx::document::view_or_value> _rule;
140  stdx::optional<validation_level> _level;
141  stdx::optional<validation_action> _action;
142 };
143 
144 MONGOCXX_API bool MONGOCXX_CALL operator==(const validation_criteria& lhs,
145  const validation_criteria& rhs);
146 MONGOCXX_API bool MONGOCXX_CALL operator!=(const validation_criteria& lhs,
147  const validation_criteria& rhs);
148 
149 MONGOCXX_INLINE validation_criteria::operator bsoncxx::document::value() const {
150  return to_document_deprecated();
151 }
152 
153 } // namespace v_noabi
154 } // namespace mongocxx
155 
156 #include <mongocxx/config/postlude.hpp>
Class representing criteria for document validation, to be applied to a collection.
Definition: validation_criteria.hpp:30
validation_criteria & action(validation_action action)
Sets a validation action to run when documents failing validation are inserted or modified.
const stdx::optional< validation_action > & action() const
Gets the validation action to run when documents failing validation are inserted or modified.
const stdx::optional< bsoncxx::document::view_or_value > & rule() const
Gets the validation rule for this validation object.
validation_action
A class to represent the different validation action options.
Definition: validation_criteria.hpp:93
validation_level
A class to represent the different validation level options.
Definition: validation_criteria.hpp:60
bsoncxx::document::value to_document() const
Returns a bson document representing this set of validation criteria.
validation_criteria & rule(bsoncxx::document::view_or_value rule)
Sets a validation rule for this validation object.
const stdx::optional< validation_level > & level() const
Gets the validation level.
validation_criteria & level(validation_level level)
Sets a validation level.
The top-level namespace for mongocxx library entities.
Definition: bulk_write.hpp:24