MongoDB C++ Driver  mongocxx-3.4.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
element.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 
20 #include <bsoncxx/stdx/string_view.hpp>
21 
22 #include <bsoncxx/config/prelude.hpp>
23 
24 namespace bsoncxx {
25 BSONCXX_INLINE_NAMESPACE_BEGIN
26 
27 enum class type : std::uint8_t;
28 enum class binary_sub_type : std::uint8_t;
29 
30 namespace types {
31 struct b_eod;
32 struct b_double;
33 struct b_utf8;
34 struct b_document;
35 struct b_array;
36 struct b_binary;
37 struct b_undefined;
38 struct b_oid;
39 struct b_bool;
40 struct b_date;
41 struct b_null;
42 struct b_regex;
43 struct b_dbpointer;
44 struct b_code;
45 struct b_symbol;
46 struct b_codewscope;
47 struct b_int32;
48 struct b_timestamp;
49 struct b_int64;
50 struct b_decimal128;
51 struct b_minkey;
52 struct b_maxkey;
53 class value;
54 } // namespace types
55 
56 namespace array {
57 class element;
58 } // namespace array
59 
60 namespace document {
61 
71 class BSONCXX_API element {
72  public:
79  element();
80 
85  explicit operator bool() const;
86 
92  const std::uint8_t* raw() const;
93 
99  std::uint32_t length() const;
100 
106  std::uint32_t offset() const;
107 
115  bsoncxx::type type() const;
116 
124  stdx::string_view key() const;
125 
131  std::uint32_t keylen() const;
132 
140  types::b_double get_double() const;
141 
149  types::b_utf8 get_utf8() const;
150 
158  types::b_document get_document() const;
159 
167  types::b_array get_array() const;
168 
176  types::b_binary get_binary() const;
177 
185  types::b_undefined get_undefined() const;
186 
194  types::b_oid get_oid() const;
195 
203  types::b_bool get_bool() const;
204 
212  types::b_date get_date() const;
213 
221  types::b_null get_null() const;
222 
230  types::b_regex get_regex() const;
231 
239  types::b_dbpointer get_dbpointer() const;
240 
248  types::b_code get_code() const;
249 
257  types::b_symbol get_symbol() const;
258 
266  types::b_codewscope get_codewscope() const;
267 
275  types::b_int32 get_int32() const;
276 
284  types::b_timestamp get_timestamp() const;
285 
293  types::b_int64 get_int64() const;
294 
302  types::b_decimal128 get_decimal128() const;
303 
311  types::b_minkey get_minkey() const;
312 
320  types::b_maxkey get_maxkey() const;
321 
328  types::value get_value() const;
329 
344  element operator[](stdx::string_view key) const;
345 
360  array::element operator[](std::uint32_t i) const;
361 
362  private:
375  BSONCXX_PRIVATE explicit element(const std::uint8_t* raw,
376  std::uint32_t length,
377  std::uint32_t offset,
378  std::uint32_t keylen);
379 
380  friend class view;
381  friend class array::element;
382 
383  const std::uint8_t* _raw;
384  std::uint32_t _length;
385  std::uint32_t _offset;
386  std::uint32_t _keylen;
387 };
388 
389 } // namespace document
390 
391 BSONCXX_INLINE_NAMESPACE_END
392 } // namespace bsoncxx
393 
394 #include <bsoncxx/config/postlude.hpp>
A BSON signed 32-bit integer value.
Definition: types.hpp:529
A BSON double value.
Definition: types.hpp:85
A BSON Symbol value.
Definition: types.hpp:457
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
binary_sub_type
An enumeration of each BSON binary sub type.
Definition: types.hpp:54
A BSON null value.
Definition: types.hpp:345
A BSON regex value.
Definition: types.hpp:361
A BSON binary data value.
Definition: types.hpp:203
A BSON DBPointer value.
Definition: types.hpp:399
A BSON max-key value.
Definition: types.hpp:648
A BSON UTF-8 encoded string value.
Definition: types.hpp:110
A BSON date value.
Definition: types.hpp:286
A BSON min-key value.
Definition: types.hpp:632
A BSON JavaScript code value.
Definition: types.hpp:418
A BSON JavaScript code with scope value.
Definition: types.hpp:493
A BSON 64-bit signed integer value.
Definition: types.hpp:577
A BSON replication timestamp value.
Definition: types.hpp:558
A BSON document value.
Definition: types.hpp:146
A variant view type that accesses values in serialized BSON documents.
Definition: element.hpp:71
type
An enumeration of each BSON type.
Definition: types.hpp:39
A BSON boolean value.
Definition: types.hpp:261
A variant view type that accesses values in serialized BSON arrays.
Definition: element.hpp:36
A BSON ObjectId value.
Definition: types.hpp:243
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
A BSON undefined value.
Definition: types.hpp:227
A BSON array value.
Definition: types.hpp:178
A variant that can contain any BSON type.
Definition: value.hpp:37
A BSON Decimal128 value.
Definition: types.hpp:602