MongoDB C++ Driver  mongocxx-3.9.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
26 namespace bsoncxx {
27 inline namespace v_noabi {
28 namespace types {
29 namespace bson_value {
30 class view;
31 } // namespace bson_value
32 } // namespace types
33 
34 namespace array {
35 
39 class BSONCXX_API view {
40  public:
41  class BSONCXX_API const_iterator;
42  using iterator = const_iterator;
43 
48 
53 
58 
63 
74  const_iterator find(std::uint32_t i) const;
75 
86  element operator[](std::uint32_t i) const;
87 
92  view();
93 
103  view(const std::uint8_t* data, std::size_t length);
104 
110  const std::uint8_t* data() const;
111 
120  std::size_t length() const;
121 
128  bool empty() const;
129 
133  operator document::view() const;
134 
142  friend BSONCXX_API bool BSONCXX_CALL operator==(view, view);
143  friend BSONCXX_API bool BSONCXX_CALL operator!=(view, view);
147 
148  private:
149  document::view _view;
150 };
151 
158 class BSONCXX_API view::const_iterator {
159  public:
164  using reference = element&;
165  using pointer = element*;
166  using iterator_category = std::forward_iterator_tag;
167  using difference_type = std::ptrdiff_t;
168 
169  const_iterator();
170  explicit const_iterator(const element& element);
171 
172  reference operator*();
173  pointer operator->();
174 
175  const_iterator& operator++();
176  const_iterator operator++(int);
177 
185  friend BSONCXX_API bool BSONCXX_CALL operator==(const const_iterator&, const const_iterator&);
186  friend BSONCXX_API bool BSONCXX_CALL operator!=(const const_iterator&, const const_iterator&);
190 
191  private:
192  element _element;
193 };
194 
195 } // namespace array
196 } // namespace v_noabi
197 } // namespace bsoncxx
198 
199 #include <bsoncxx/config/postlude.hpp>
A variant view type that accesses values in serialized BSON arrays.
Definition: element.hpp:41
A const iterator over the contents of an array view.
Definition: view.hpp:158
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:39
bool empty() const
Checks if the underlying buffer is empty, i.e.
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 find(std::uint32_t i) const
Indexes into this BSON array.
const_iterator end() const
const_iterator begin() const
const_iterator cend() const
const_iterator cbegin() const
view()
Default constructs a view.
friend bool operator!=(view, view)
Compare two views for (in)-equality.
view(const std::uint8_t *data, std::size_t length)
Constructs a view from a buffer.
const std::uint8_t * data() const
Access the raw bytes of the underlying array.
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
The top-level namespace for bsoncxx library entities.
Definition: element.hpp:24