MongoDB C++ Driver mongocxx-3.0.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/document/view.hpp>
22#include <bsoncxx/array/element.hpp>
23
24#include <bsoncxx/config/prelude.hpp>
25
26namespace bsoncxx {
27BSONCXX_INLINE_NAMESPACE_BEGIN
28namespace array {
29
33class BSONCXX_API view {
34 public:
35 class BSONCXX_API iterator;
36 class BSONCXX_API const_iterator;
37
42
47
51 iterator begin() const;
52
56 iterator end() const;
57
68 iterator find(std::uint32_t i) const;
69
80 element operator[](std::uint32_t i) const;
81
87
97 view(const std::uint8_t* data, std::size_t length);
98
104 const std::uint8_t* data() const;
105
114 std::size_t length() const;
115
122 bool empty() const;
123
124 operator document::view() const;
125
133 friend BSONCXX_API bool BSONCXX_CALL operator==(view, view);
134 friend BSONCXX_API bool BSONCXX_CALL operator!=(view, view);
138
139 private:
140 document::view _view;
141};
142
149class BSONCXX_API view::iterator : public std::iterator<std::forward_iterator_tag, element> {
150 public:
151 iterator();
152 explicit iterator(const element& element);
153
154 reference operator*();
155 pointer operator->();
156
157 iterator& operator++();
158 iterator operator++(int);
159
167 friend BSONCXX_API bool BSONCXX_CALL operator==(const iterator&, const iterator&);
168 friend BSONCXX_API bool BSONCXX_CALL operator!=(const iterator&, const iterator&);
172
173 private:
174 element _element;
175};
176
183class BSONCXX_API view::const_iterator
184 : public std::iterator<std::forward_iterator_tag, element, std::ptrdiff_t, const element*,
185 const element&> {
186 public:
188 explicit const_iterator(const element& element);
189
190 reference operator*();
191 pointer operator->();
192
193 const_iterator& operator++();
194 const_iterator operator++(int);
195
203 friend BSONCXX_API bool BSONCXX_CALL operator==(const const_iterator&, const const_iterator&);
204 friend BSONCXX_API bool BSONCXX_CALL operator!=(const const_iterator&, const const_iterator&);
208
209 private:
210 element _element;
211};
212
213} // namespace array
214BSONCXX_INLINE_NAMESPACE_END
215} // namespace bsoncxx
216
217#include <bsoncxx/config/postlude.hpp>
A variant view type that accesses values in serialized BSON arrays.
Definition element.hpp:36
A const iterator over the contents of an array view.
Definition view.hpp:185
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 mutable iterator over the contents of an array view.
Definition view.hpp:149
friend bool operator!=(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
friend bool operator==(const iterator &, const iterator &)
Compare two iterators for (in)-equality.
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
iterator end() const
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.
iterator find(std::uint32_t i) const
Indexes into this BSON array.
view(const std::uint8_t *data, std::size_t length)
Constructs a view from a buffer.
view()
Default constructs a view.
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.
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