MongoDB C++ Driver  mongocxx-3.6.2
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 
54 namespace bson_value {
55 class value;
56 class view;
57 } // namespace bson_value
58 
59 } // namespace types
60 
61 namespace array {
62 class element;
63 } // namespace array
64 
65 namespace document {
66 
76 class BSONCXX_API element {
77  public:
85 
90  explicit operator bool() const;
91 
97  const std::uint8_t* raw() const;
98 
104  std::uint32_t length() const;
105 
111  std::uint32_t offset() const;
112 
121 
129  stdx::string_view key() const;
130 
136  std::uint32_t keylen() const;
137 
146 
155 
164 
173 
182 
191 
200 
209 
218 
227 
236 
245 
254 
263 
272 
281 
290 
299 
308 
317 
326 
334 
342 
357  element operator[](stdx::string_view key) const;
358 
373  array::element operator[](std::uint32_t i) const;
374 
375  private:
388  BSONCXX_PRIVATE explicit element(const std::uint8_t* raw,
389  std::uint32_t length,
390  std::uint32_t offset,
391  std::uint32_t keylen);
392 
393  friend class view;
394  friend class array::element;
395 
396  const std::uint8_t* _raw;
397  std::uint32_t _length;
398  std::uint32_t _offset;
399  std::uint32_t _keylen;
400 };
401 
402 } // namespace document
403 
404 BSONCXX_INLINE_NAMESPACE_END
405 } // namespace bsoncxx
406 
407 #include <bsoncxx/config/postlude.hpp>
bsoncxx::types::b_array
A BSON array value.
Definition: types.hpp:181
bsoncxx::types::b_oid
A BSON ObjectId value.
Definition: types.hpp:246
bsoncxx::document::element::get_null
types::b_null get_null() const
Getter for elements of the b_null type.
bsoncxx::document::element::get_bool
types::b_bool get_bool() const
Getter for elements of the b_bool type.
bsoncxx::document::element::get_dbpointer
types::b_dbpointer get_dbpointer() const
Getter for elements of the b_dbpointer type.
bsoncxx::types::b_utf8
A BSON UTF-8 encoded string value.
Definition: types.hpp:113
bsoncxx::document::element::get_regex
types::b_regex get_regex() const
Getter for elements of the b_regex type.
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::document::element::key
stdx::string_view key() const
Getter for the element's key.
bsoncxx::document::element::operator[]
element operator[](stdx::string_view key) const
If this element is a document, finds the first element of the document with the provided key.
bsoncxx::types::b_document
A BSON document value.
Definition: types.hpp:149
bsoncxx::types::b_null
A BSON null value.
Definition: types.hpp:348
bsoncxx::document::element::get_minkey
types::b_minkey get_minkey() const
Getter for elements of the b_minkey type.
bsoncxx::types::b_codewscope
A BSON JavaScript code with scope value.
Definition: types.hpp:496
bsoncxx::types::b_int64
A BSON 64-bit signed integer value.
Definition: types.hpp:580
bsoncxx::binary_sub_type
binary_sub_type
An enumeration of each BSON binary sub type.
Definition: types.hpp:57
bsoncxx::document::element::get_timestamp
types::b_timestamp get_timestamp() const
Getter for elements of the b_timestamp type.
bsoncxx::types::b_binary
A BSON binary data value.
Definition: types.hpp:206
bsoncxx::document::element::length
std::uint32_t length() const
Getter for length of the raw bson bytes the element points to.
bsoncxx::document::element::operator[]
array::element operator[](std::uint32_t i) const
If this element is an array, indexes into this BSON array.
bsoncxx::document::element::get_double
types::b_double get_double() const
Getter for elements of the b_double type.
bsoncxx::types::b_symbol
A BSON Symbol value.
Definition: types.hpp:460
bsoncxx::types::b_dbpointer
A BSON DBPointer value.
Definition: types.hpp:402
bsoncxx::document::element::type
bsoncxx::type type() const
Getter for the type of the element.
bsoncxx::document::element::get_int32
types::b_int32 get_int32() const
Getter for elements of the b_int32 type.
bsoncxx::types::b_regex
A BSON regex value.
Definition: types.hpp:364
bsoncxx::types::b_maxkey
A BSON max-key value.
Definition: types.hpp:651
bsoncxx::document::element::raw
const std::uint8_t * raw() const
Getter for the raw bson bytes the element points to.
bsoncxx::types::b_timestamp
A BSON replication timestamp value.
Definition: types.hpp:561
bsoncxx::document::element::get_codewscope
types::b_codewscope get_codewscope() const
Getter for elements of the b_codewscope type.
bsoncxx::types::b_date
A BSON date value.
Definition: types.hpp:289
bsoncxx::types::b_int32
A BSON signed 32-bit integer value.
Definition: types.hpp:532
bsoncxx::types::b_minkey
A BSON min-key value.
Definition: types.hpp:635
bsoncxx::document::element::get_symbol
types::b_symbol get_symbol() const
Getter for elements of the b_symbol type.
bsoncxx::document::element::get_maxkey
types::b_maxkey get_maxkey() const
Getter for elements of the b_maxkey type.
bsoncxx::document::element::get_int64
types::b_int64 get_int64() const
Getter for elements of the b_int64 type.
bsoncxx::document::element
A variant view type that accesses values in serialized BSON documents.
Definition: element.hpp:76
bsoncxx::document::element::get_owning_value
types::bson_value::value get_owning_value() const
Getter for a types::bson_value::value variant wrapper of the value portion of the element.
bsoncxx::document::element::keylen
std::uint32_t keylen() const
Getter for the element's key length.
bsoncxx::types::b_code
A BSON JavaScript code value.
Definition: types.hpp:421
bsoncxx::document::element::get_date
types::b_date get_date() const
Getter for elements of the b_date type.
bsoncxx::document::element::get_array
types::b_array get_array() const
Getter for elements of the b_array type.
bsoncxx::document::element::get_document
types::b_document get_document() const
Getter for elements of the b_document type.
bsoncxx::types::b_decimal128
A BSON Decimal128 value.
Definition: types.hpp:605
bsoncxx::type
type
An enumeration of each BSON type.
Definition: types.hpp:39
bsoncxx::types::b_undefined
A BSON undefined value.
Definition: types.hpp:230
bsoncxx::document::element::get_code
types::b_code get_code() const
Getter for elements of the b_code type.
bsoncxx::document::element::get_decimal128
types::b_decimal128 get_decimal128() const
Getter for elements of the b_decimal128 type.
bsoncxx::document::element::get_binary
types::b_binary get_binary() const
Getter for elements of the b_binary type.
bsoncxx::document::element::get_value
types::bson_value::view get_value() const
Getter for a types::bson_value::view variant wrapper of the value portion of the element.
bsoncxx::document::element::get_utf8
types::b_utf8 get_utf8() const
Getter for elements of the b_utf8 type.
bsoncxx::document::element::get_oid
types::b_oid get_oid() const
Getter for elements of the b_oid type.
bsoncxx::types::bson_value::value
A variant owning type that represents any BSON type.
Definition: value.hpp:39
bsoncxx::types::b_bool
A BSON boolean value.
Definition: types.hpp:264
bsoncxx::types::b_double
A BSON double value.
Definition: types.hpp:88
bsoncxx::document::element::element
element()
Construct an invalid element.
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:36
bsoncxx::document::element::get_undefined
types::b_undefined get_undefined() const
Getter for elements of the b_undefined type.
bsoncxx::types::bson_value::view
A view-only variant that can contain any BSON type.
Definition: view.hpp:44
bsoncxx::document::element::offset
std::uint32_t offset() const
Getter for the offset into the raw bson bytes the element points to.