MongoDB C++ Driver  mongocxx-3.10.2
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/view-fwd.hpp>
22 #include <bsoncxx/types/bson_value/view-fwd.hpp>
23 
24 #include <bsoncxx/array/element.hpp>
25 #include <bsoncxx/document/view.hpp>
26 
27 #include <bsoncxx/config/prelude.hpp>
28 
29 namespace bsoncxx {
30 namespace v_noabi {
31 namespace array {
32 
36 class view {
37  public:
38  class BSONCXX_API const_iterator;
39  using iterator = const_iterator;
40 
45 
50 
55 
60 
71  const_iterator find(std::uint32_t i) const;
72 
83  element operator[](std::uint32_t i) const;
84 
89  view();
90 
100  view(const std::uint8_t* data, std::size_t length);
101 
107  const std::uint8_t* data() const;
108 
117  std::size_t length() const;
118 
125  bool empty() const;
126 
130  operator document::view() const;
131 
139  friend BSONCXX_API bool BSONCXX_CALL operator==(view, view);
140  friend BSONCXX_API bool BSONCXX_CALL operator!=(view, view);
144 
145  private:
146  document::view _view;
147 };
148 
156  public:
161  using reference = element&;
162  using pointer = element*;
163  using iterator_category = std::forward_iterator_tag;
164  using difference_type = std::ptrdiff_t;
165 
166  const_iterator();
167  explicit const_iterator(const element& element);
168 
169  reference operator*();
170  pointer operator->();
171 
172  const_iterator& operator++();
173  const_iterator operator++(int);
174 
182  friend BSONCXX_API bool BSONCXX_CALL operator==(const const_iterator&, const const_iterator&);
183  friend BSONCXX_API bool BSONCXX_CALL operator!=(const const_iterator&, const const_iterator&);
187 
188  private:
189  element _element;
190 };
191 
192 } // namespace array
193 } // namespace v_noabi
194 } // namespace bsoncxx
195 
196 #include <bsoncxx/config/postlude.hpp>
A variant view type that accesses values in serialized BSON arrays.
Definition: element.hpp:39
A const iterator over the contents of an array view.
Definition: view.hpp:155
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:36
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:35
The top-level namespace for bsoncxx library entities.
Definition: element-fwd.hpp:19