MongoDB C++ Driver  mongocxx-3.7.0
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 MONGOCXX_INLINE_NAMESPACE_BEGIN
25 
31 class MONGOCXX_API validation_criteria {
32  public:
44 
51  const stdx::optional<bsoncxx::document::view_or_value>& rule() const;
52 
61  enum class validation_level {
62  k_off,
63  k_moderate,
64  k_strict,
65  };
66 
77  validation_criteria& level(validation_level level);
78 
85  const stdx::optional<validation_level>& level() const;
86 
94  enum class validation_action {
95  k_error,
96  k_warn,
97  };
98 
109  validation_criteria& action(validation_action action);
110 
118  const stdx::optional<validation_action>& action() const;
119 
129  MONGOCXX_DEPRECATED bsoncxx::document::value to_document() const;
130  bsoncxx::document::value to_document_deprecated() const;
131 
137  MONGOCXX_DEPRECATED MONGOCXX_INLINE operator bsoncxx::document::value() const;
138 
139  private:
140  stdx::optional<bsoncxx::document::view_or_value> _rule;
141  stdx::optional<validation_level> _level;
142  stdx::optional<validation_action> _action;
143 };
144 
145 MONGOCXX_API bool MONGOCXX_CALL operator==(const validation_criteria& lhs,
146  const validation_criteria& rhs);
147 MONGOCXX_API bool MONGOCXX_CALL operator!=(const validation_criteria& lhs,
148  const validation_criteria& rhs);
149 
150 MONGOCXX_INLINE validation_criteria::operator bsoncxx::document::value() const {
151  return to_document_deprecated();
152 }
153 
154 MONGOCXX_INLINE_NAMESPACE_END
155 } // namespace mongocxx
156 
157 #include <mongocxx/config/postlude.hpp>
mongocxx::validation_criteria::validation_level
validation_level
A class to represent the different validation level options.
Definition: validation_criteria.hpp:61
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx::view_or_value< document::view, document::value >
mongocxx::validation_criteria::validation_action
validation_action
A class to represent the different validation action options.
Definition: validation_criteria.hpp:94
bsoncxx::document::value
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:34
mongocxx::validation_criteria
Class representing criteria for document validation, to be applied to a collection.
Definition: validation_criteria.hpp:31