MongoDB C++ Driver  mongocxx-3.7.0
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 BSONCXX_INLINE_NAMESPACE_BEGIN
28 
29 namespace types {
30 namespace bson_value {
31 class view;
32 } // namespace bson_value
33 } // namespace types
34 
35 namespace array {
36 
40 class BSONCXX_API view {
41  public:
42  class BSONCXX_API const_iterator;
43  using iterator = const_iterator;
44 
48  const_iterator cbegin() const;
49 
53  const_iterator cend() const;
54 
58  const_iterator begin() const;
59 
63  const_iterator end() const;
64 
75  const_iterator find(std::uint32_t i) const;
76 
87  element operator[](std::uint32_t i) const;
88 
93  view();
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 
159 class 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 
170  const_iterator();
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
197 BSONCXX_INLINE_NAMESPACE_END
198 } // namespace bsoncxx
199 
200 #include <bsoncxx/config/postlude.hpp>
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::array::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:40
bsoncxx::array::view::const_iterator
A const iterator over the contents of an array view.
Definition: view.hpp:159
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
bsoncxx::array::element
A variant view type that accesses values in serialized BSON arrays.
Definition: element.hpp:42