MongoDB C++ Driver  mongocxx-3.10.2
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 <mongocxx/validation_criteria-fwd.hpp>
18 
19 #include <bsoncxx/document/view_or_value.hpp>
20 #include <bsoncxx/stdx/optional.hpp>
21 #include <mongocxx/stdx.hpp>
22 
23 #include <mongocxx/config/prelude.hpp>
24 
25 namespace mongocxx {
26 namespace v_noabi {
27 
34  public:
46 
53  const stdx::optional<bsoncxx::v_noabi::document::view_or_value>& rule() const;
54 
63  enum class validation_level {
64  k_off,
65  k_moderate,
66  k_strict,
67  };
68 
80 
87  const stdx::optional<validation_level>& level() const;
88 
96  enum class validation_action {
97  k_error,
98  k_warn,
99  };
100 
112 
120  const stdx::optional<validation_action>& action() const;
121 
131  MONGOCXX_DEPRECATED bsoncxx::v_noabi::document::value to_document() const;
132  bsoncxx::v_noabi::document::value to_document_deprecated() const;
133 
139  MONGOCXX_DEPRECATED MONGOCXX_INLINE operator bsoncxx::v_noabi::document::value() const;
140 
141  private:
142  stdx::optional<bsoncxx::v_noabi::document::view_or_value> _rule;
143  stdx::optional<validation_level> _level;
144  stdx::optional<validation_action> _action;
145 };
146 
147 MONGOCXX_API bool MONGOCXX_CALL operator==(const validation_criteria& lhs,
148  const validation_criteria& rhs);
149 MONGOCXX_API bool MONGOCXX_CALL operator!=(const validation_criteria& lhs,
150  const validation_criteria& rhs);
151 
152 MONGOCXX_INLINE validation_criteria::operator bsoncxx::v_noabi::document::value() const {
153  return to_document_deprecated();
154 }
155 
156 } // namespace v_noabi
157 } // namespace mongocxx
158 
159 namespace mongocxx {
160 
161 using ::mongocxx::v_noabi::operator==;
162 using ::mongocxx::v_noabi::operator!=;
163 
164 } // namespace mongocxx
165 
166 #include <mongocxx/config/postlude.hpp>
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:38
Class representing criteria for document validation, to be applied to a collection.
Definition: validation_criteria.hpp:33
validation_criteria & action(validation_action action)
Sets a validation action to run when documents failing validation are inserted or modified.
validation_criteria & rule(bsoncxx::v_noabi::document::view_or_value rule)
Sets a validation rule for this validation object.
const stdx::optional< validation_action > & action() const
Gets the validation action to run when documents failing validation are inserted or modified.
validation_action
A class to represent the different validation action options.
Definition: validation_criteria.hpp:96
validation_level
A class to represent the different validation level options.
Definition: validation_criteria.hpp:63
const stdx::optional< validation_level > & level() const
Gets the validation level.
const stdx::optional< bsoncxx::v_noabi::document::view_or_value > & rule() const
Gets the validation rule for this validation object.
bsoncxx::v_noabi::document::value to_document() const
Returns a bson document representing this set of validation criteria.
validation_criteria & level(validation_level level)
Sets a validation level.
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19