MongoDB C++ Driver  mongocxx-3.1.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:
40 
47  const stdx::optional<bsoncxx::document::view_or_value>& rule() const;
48 
57  enum class validation_level {
58  k_off,
59  k_moderate,
60  k_strict,
61  };
62 
69  validation_criteria& level(validation_level level);
70 
77  const stdx::optional<validation_level>& level() const;
78 
86  enum class validation_action {
87  k_error,
88  k_warn,
89  };
90 
97  validation_criteria& action(validation_action action);
98 
106  const stdx::optional<validation_action>& action() const;
107 
117  bsoncxx::document::value to_document() const;
118 
124  MONGOCXX_INLINE operator bsoncxx::document::value() const;
125 
126  private:
127  stdx::optional<bsoncxx::document::view_or_value> _rule;
128  stdx::optional<validation_level> _level;
129  stdx::optional<validation_action> _action;
130 };
131 
132 MONGOCXX_INLINE validation_criteria::operator bsoncxx::document::value() const {
133  return to_document();
134 }
135 
136 MONGOCXX_INLINE_NAMESPACE_END
137 } // namespace mongocxx
138 
139 #include <mongocxx/config/postlude.hpp>
Class representing criteria for document validation, to be applied to a collection.
Definition: validation_criteria.hpp:31
Definition: bulk_write.hpp:22
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
validation_level
A class to represent the different validation level options.
Definition: validation_criteria.hpp:57
validation_action
A class to represent the different validation action options.
Definition: validation_criteria.hpp:86