MongoDB C++ Driver mongocxx-3.7.0
Loading...
Searching...
No Matches
view.hpp
1// Copyright 2014 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
21#include <bsoncxx/array/element.hpp>
22#include <bsoncxx/document/view.hpp>
23
24#include <bsoncxx/config/prelude.hpp>
25
26namespace bsoncxx {
27BSONCXX_INLINE_NAMESPACE_BEGIN
28
29namespace types {
30namespace bson_value {
31class view;
32} // namespace bson_value
33} // namespace types
34
35namespace array {
36
40class BSONCXX_API view {
41 public:
42 class BSONCXX_API const_iterator;
44
49
54
59
64
75 const_iterator find(std::uint32_t i) const;
76
87 element operator[](std::uint32_t i) const;
88
94
104 view(const std::uint8_t* data, std::size_t length);
105
111 const std::uint8_t* data() const;
112
121 std::size_t length() const;
122
129 bool empty() const;
130
134 operator document::view() const;
135
143 friend BSONCXX_API bool BSONCXX_CALL operator==(view, view);
144 friend BSONCXX_API bool BSONCXX_CALL operator!=(view, view);
148
149 private:
150 document::view _view;
151};
152
159class BSONCXX_API view::const_iterator {
160 public:
165 using reference = element&;
166 using pointer = element*;
167 using iterator_category = std::forward_iterator_tag;
168 using difference_type = std::ptrdiff_t;
169
171 explicit const_iterator(const element& element);
172
173 reference operator*();
174 pointer operator->();
175
176 const_iterator& operator++();
177 const_iterator operator++(int);
178
186 friend BSONCXX_API bool BSONCXX_CALL operator==(const const_iterator&, const const_iterator&);
187 friend BSONCXX_API bool BSONCXX_CALL operator!=(const const_iterator&, const const_iterator&);
191
192 private:
193 element _element;
194};
195
196} // namespace array
197BSONCXX_INLINE_NAMESPACE_END
198} // namespace bsoncxx
199
200#include <bsoncxx/config/postlude.hpp>
A variant view type that accesses values in serialized BSON arrays.
Definition element.hpp:42
A const iterator over the contents of an array view.
Definition view.hpp:159
friend bool operator!=(const const_iterator &, const const_iterator &)
Compare two const_iterators for (in)-equality.
friend bool operator==(const const_iterator &, const const_iterator &)
Compare two const_iterators for (in)-equality.
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
const_iterator cend() const
friend bool operator==(view, view)
Compare two views for (in)-equality.
const_iterator cbegin() const
const std::uint8_t * data() const
Access the raw bytes of the underlying array.
bool empty() const
Checks if the underlying buffer is empty, i.e.
view(const std::uint8_t *data, std::size_t length)
Constructs a view from a buffer.
view()
Default constructs a view.
const_iterator find(std::uint32_t i) const
Indexes into this BSON array.
const_iterator begin() const
std::size_t length() const
Gets the length of the underlying buffer.
friend bool operator!=(view, view)
Compare two views for (in)-equality.
const_iterator end() const
element operator[](std::uint32_t i) const
Indexes into this BSON array.
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24