MongoDB C++ Driver 4.4.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 <bsoncxx/v1/array/view-fwd.hpp> // IWYU pragma: export
18
19//
20
22
24#include <bsoncxx/v1/document/view.hpp> // IWYU pragma: export
25#include <bsoncxx/v1/element/view.hpp> // IWYU pragma: export
26
27#include <cstddef>
28#include <cstdint>
29
30namespace bsoncxx {
31namespace v1 {
32namespace array {
33
47class view {
48 public:
51
54
55 private:
57
58 public:
60 view() = default;
61
63 explicit view(std::uint8_t const* data) : _view{data} {}
64
66 view(std::uint8_t const* data, std::size_t length) : _view{data, length} {}
67
69 std::uint8_t const* data() const {
70 return _view.data();
71 }
72
74 std::size_t size() const {
75 return _view.size();
76 }
77
79 std::size_t length() const {
80 return _view.length();
81 }
82
84 bool empty() const {
85 return _view.empty();
86 }
87
89 explicit operator bool() const {
90 return _view.operator bool();
91 }
92
95 return _view.cbegin();
96 }
97
100 return {};
101 }
102
105 return this->cbegin();
106 }
107
110 return this->cend();
111 }
112
125
137 v1::element::view operator[](std::uint32_t i) const {
138 return *(this->find(i));
139 }
140
144 /* explicit(false) */ operator v1::document::view() const {
145 return _view;
146 }
147
149 friend bool operator==(view lhs, view rhs) {
150 return lhs._view == rhs._view;
151 }
152
154 friend bool operator!=(view lhs, view rhs) {
155 return !(lhs == rhs);
156 }
157};
158
159} // namespace array
160} // namespace v1
161} // namespace bsoncxx
162
164
Provides macros to control the set of symbols exported in the ABI.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
The bsoncxx v1 macro guard postlude header.
The bsoncxx v1 macro guard prelude header.
std::uint8_t const * data() const
Return a pointer to the BSON bytes being represented.
Definition view.hpp:69
view(std::uint8_t const *data, std::size_t length)
Equivalent to view(std::uint8_t const* data), but validates the embedded length against length.
Definition view.hpp:66
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:104
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition view.hpp:79
friend bool operator!=(view lhs, view rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition view.hpp:154
friend bool operator==(view lhs, view rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition view.hpp:149
const_iterator iterator
Equivalent to const_iterator.
Definition view.hpp:53
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:94
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition view.hpp:84
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition view.hpp:50
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition view.hpp:74
const_iterator find(std::uint32_t i) const
Return a const iterator to the element within the represented BSON array at index i via key string co...
const_iterator cend() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:99
v1::element::view operator[](std::uint32_t i) const
Return the first element within the represented BSON array whose key compares equal to i.
Definition view.hpp:137
view(std::uint8_t const *data)
Initialize with the given BSON bytes.
Definition view.hpp:63
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:109
view()=default
Initialize as an empty view.
A const iterator over the elements of a view.
Definition view.hpp:264
A non-owning, read-only BSON document.
Definition view.hpp:52
A non-owning, read-only BSON element.
Definition view.hpp:82
Declares entities representing a BSON array.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v1::array::view.
Provides bsoncxx::v1::document::view.
Provides bsoncxx::v1::element::view.