MongoDB C++ Driver 4.2.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
49class view {
50 public:
53
56
57 private:
59
60 public:
62 view() = default;
63
65 explicit view(std::uint8_t const* data) : _view{data} {}
66
68 view(std::uint8_t const* data, std::size_t length) : _view{data, length} {}
69
71 std::uint8_t const* data() const {
72 return _view.data();
73 }
74
76 std::size_t size() const {
77 return _view.size();
78 }
79
81 std::size_t length() const {
82 return _view.length();
83 }
84
86 bool empty() const {
87 return _view.empty();
88 }
89
91 explicit operator bool() const {
92 return _view.operator bool();
93 }
94
97 return _view.cbegin();
98 }
99
102 return {};
103 }
104
107 return this->cbegin();
108 }
109
112 return this->cend();
113 }
114
127
139 v1::element::view operator[](std::uint32_t i) const {
140 return *(this->find(i));
141 }
142
146 /* explicit(false) */ operator v1::document::view() const {
147 return _view;
148 }
149
151 friend bool operator==(view lhs, view rhs) {
152 return lhs._view == rhs._view;
153 }
154
156 friend bool operator!=(view lhs, view rhs) {
157 return !(lhs == rhs);
158 }
159};
160
161} // namespace array
162} // namespace v1
163} // namespace bsoncxx
164
166
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:71
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:68
const_iterator begin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:106
std::size_t length() const
Return the length of the BSON bytes being represented.
Definition view.hpp:81
friend bool operator!=(view lhs, view rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition view.hpp:156
friend bool operator==(view lhs, view rhs)
Compare equal when the BSON bytes represented by lhs and rhs compare equal.
Definition view.hpp:151
const_iterator iterator
Equivalent to const_iterator.
Definition view.hpp:55
const_iterator cbegin() const
Return a const iterator to the beginning of the range of BSON elements within this view.
Definition view.hpp:96
bool empty() const
Return true when the BSON bytes represents an empty view:
Definition view.hpp:86
v1::document::view::const_iterator const_iterator
A const iterator over the elements of a view.
Definition view.hpp:52
std::size_t size() const
Return the length of the BSON bytes being represented.
Definition view.hpp:76
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:101
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:139
view(std::uint8_t const *data)
Initialize with the given BSON bytes.
Definition view.hpp:65
const_iterator end() const
Return a const iterator to the end of the range of BSON elements within this view.
Definition view.hpp:111
view()=default
Initialize as an empty view.
A const iterator over the elements of a view.
Definition view.hpp:274
A non-owning, read-only BSON document.
Definition view.hpp:54
A non-owning, read-only BSON element.
Definition view.hpp:84
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.