MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
view.hpp
Go to the documentation of this file.
1// Copyright 2009-present 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 <cstddef>
18#include <cstdint>
19#include <iterator>
20
22
25
27
28namespace bsoncxx {
29namespace v_noabi {
30namespace document {
31
35class view {
36 public:
37 class const_iterator;
39
45
55 BSONCXX_ABI_EXPORT_CDECL() view(const std::uint8_t* data, std::size_t length);
56
61
66
71
76
92 BSONCXX_ABI_EXPORT_CDECL(const_iterator) find(stdx::string_view key) const;
93
104 BSONCXX_ABI_EXPORT_CDECL(element) operator[](stdx::string_view key) const;
105
111 BSONCXX_ABI_EXPORT_CDECL(const std::uint8_t*) data() const;
112
122
130
137 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(view, view);
138 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(view, view);
141
142 private:
143 const std::uint8_t* _data;
144 std::size_t _length;
145};
146
154 public:
159 using reference = element&;
160 using pointer = element*;
161 using iterator_category = std::forward_iterator_tag;
162 using difference_type = std::ptrdiff_t;
163
166
168 BSONCXX_ABI_EXPORT_CDECL(pointer) operator->();
169
172
179 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const const_iterator&, const const_iterator&);
180 friend BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const const_iterator&, const const_iterator&);
183
184 private:
185 element _element;
186};
187
188} // namespace document
189} // namespace v_noabi
190} // namespace bsoncxx
191
192#include <bsoncxx/config/postlude.hpp>
193
The bsoncxx macro guard prelude header.
A variant view type that accesses values in serialized BSON documents.
Definition element.hpp:46
A const iterator over the contents of a document view.
Definition view.hpp:153
A read-only, non-owning view of a BSON document.
Definition view.hpp:35
bool empty() const
Checks if the underlying document is empty, i.e. it is equivalent to the trivial document '{}...
const_iterator cend() const
const std::uint8_t * data() const
Access the raw bytes of the underlying document.
std::size_t length() const
Gets the length of the underlying buffer.
const_iterator begin() const
const_iterator cbegin() const
const_iterator end() const
const_iterator find(stdx::string_view key) const
Finds the first element of the document with the provided key. If there is no such element,...
Provides bsoncxx::v_noabi::document::element.
Declares bsoncxx::v_noabi::document::view.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:225
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::string_view-related polyfills for library API usage.