MongoDB C++ Driver  mongocxx-3.7.0
validate.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 <cstdint>
18 #include <memory>
19 
20 #include <bsoncxx/document/view.hpp>
21 #include <bsoncxx/stdx/optional.hpp>
22 
23 #include <bsoncxx/config/prelude.hpp>
24 
25 namespace bsoncxx {
26 BSONCXX_INLINE_NAMESPACE_BEGIN
27 
28 class validator;
29 
44 BSONCXX_API stdx::optional<document::view> BSONCXX_CALL validate(const std::uint8_t* data,
45  std::size_t length);
46 
67 BSONCXX_API stdx::optional<document::view> BSONCXX_CALL
68 validate(const std::uint8_t* data,
69  std::size_t length,
70  const validator& validator,
71  std::size_t* invalid_offset = nullptr);
76 class BSONCXX_API validator {
77  public:
81  validator();
82 
86  ~validator();
87 
94  void check_utf8(bool check_utf8);
95 
101  bool check_utf8() const;
102 
111  void check_utf8_allow_null(bool check_utf8_allow_null);
112 
120  bool check_utf8_allow_null() const;
121 
128  void check_dollar_keys(bool check_dollar_keys);
129 
136  bool check_dollar_keys() const;
137 
144  void check_dot_keys(bool check_dot_keys);
145 
152  bool check_dot_keys() const;
153 
154  private:
155  struct BSONCXX_PRIVATE impl;
156  std::unique_ptr<impl> _impl;
157 };
158 
159 BSONCXX_INLINE_NAMESPACE_END
160 } // namespace bsoncxx
161 
162 #include <bsoncxx/config/postlude.hpp>
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::validate
stdx::optional< document::view > validate(const std::uint8_t *data, std::size_t length)
Validates a BSON document.
bsoncxx::validator
A validator is used to enable or disable specific checks that can be performed during BSON validation...
Definition: validate.hpp:76