MongoDB C++ Driver mongocxx-3.1.1
Loading...
Searching...
No Matches
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
24namespace bsoncxx {
25BSONCXX_INLINE_NAMESPACE_BEGIN
26
27enum class type : std::uint8_t;
28enum class binary_sub_type : std::uint8_t;
29
30namespace types {
31struct b_eod;
32struct b_double;
33struct b_utf8;
34struct b_document;
35struct b_array;
36struct b_binary;
37struct b_undefined;
38struct b_oid;
39struct b_bool;
40struct b_date;
41struct b_null;
42struct b_regex;
43struct b_dbpointer;
44struct b_code;
45struct b_symbol;
46struct b_codewscope;
47struct b_int32;
48struct b_timestamp;
49struct b_int64;
50struct b_decimal128;
51struct b_minkey;
52struct b_maxkey;
53class value;
54} // namespace types
55
56namespace array {
57class element;
58} // namespace array
59
60namespace document {
61
71class BSONCXX_API element {
72 public:
80
93 explicit element(const std::uint8_t* raw, std::uint32_t length, std::uint32_t offset);
94
98 explicit operator bool() const;
99
105 const std::uint8_t* raw() const;
106
113 void raw(const std::uint8_t* raw);
114
120 std::uint32_t length() const;
121
128 void length(std::uint32_t length);
129
135 std::uint32_t offset() const;
136
143 void offset(std::uint32_t offset);
144
153
161 stdx::string_view key() const;
162
171
180
189
198
207
216
225
234
243
252
261
270
279
288
297
306
315
324
333
342
351
359
374 element operator[](stdx::string_view key) const;
375
390 array::element operator[](std::uint32_t i) const;
391
392 private:
393 const std::uint8_t* _raw;
394 std::uint32_t _length;
395 std::uint32_t _offset;
396};
397
398} // namespace document
399
400BSONCXX_INLINE_NAMESPACE_END
401} // namespace bsoncxx
402
403#include <bsoncxx/config/postlude.hpp>
A variant view type that accesses values in serialized BSON arrays.
Definition element.hpp:36
A variant view type that accesses values in serialized BSON documents.
Definition element.hpp:71
void offset(std::uint32_t offset)
Setter for the offset into the raw bson bytes the element points to.
types::b_regex get_regex() const
Getter for elements of the b_regex type.
array::element operator[](std::uint32_t i) const
If this element is an array, indexes into this BSON array.
types::b_timestamp get_timestamp() const
Getter for elements of the b_timestamp type.
bsoncxx::type type() const
Getter for the type of the element.
types::b_array get_array() const
Getter for elements of the b_array type.
types::b_codewscope get_codewscope() const
Getter for elements of the b_codewscope type.
std::uint32_t length() const
Getter for length of the raw bson bytes the element points to.
stdx::string_view key() const
Getter for the element's key.
element(const std::uint8_t *raw, std::uint32_t length, std::uint32_t offset)
Construct an element as an offset into a buffer of bson bytes.
types::b_utf8 get_utf8() const
Getter for elements of the b_utf8 type.
types::b_dbpointer get_dbpointer() const
Getter for elements of the b_dbpointer type.
types::b_date get_date() const
Getter for elements of the b_date type.
types::b_minkey get_minkey() const
Getter for elements of the b_minkey type.
types::b_oid get_oid() const
Getter for elements of the b_oid type.
types::value get_value() const
Getter for a types::value variant wrapper of the value portion of the element.
const std::uint8_t * raw() const
Getter for the raw bson bytes the element points to.
types::b_null get_null() const
Getter for elements of the b_null type.
types::b_symbol get_symbol() const
Getter for elements of the b_symbol type.
types::b_code get_code() const
Getter for elements of the b_code type.
types::b_undefined get_undefined() const
Getter for elements of the b_undefined type.
types::b_int64 get_int64() const
Getter for elements of the b_int64 type.
element()
Construct an invalid element.
std::uint32_t offset() const
Getter for the offset into the raw bson bytes the element points to.
void length(std::uint32_t length)
Setter for length of the raw bson bytes the element points to.
types::b_decimal128 get_decimal128() const
Getter for elements of the b_decimal128 type.
types::b_document get_document() const
Getter for elements of the b_document type.
element operator[](stdx::string_view key) const
If this element is a document, finds the first element of the document with the provided key.
void raw(const std::uint8_t *raw)
Setter for the raw bson bytes the element points to.
types::b_bool get_bool() const
Getter for elements of the b_bool type.
types::b_binary get_binary() const
Getter for elements of the b_binary type.
types::b_int32 get_int32() const
Getter for elements of the b_int32 type.
types::b_double get_double() const
Getter for elements of the b_double type.
types::b_maxkey get_maxkey() const
Getter for elements of the b_maxkey type.
A variant that can contain any BSON type.
Definition value.hpp:37
Top level namespace for MongoDB C++ BSON functionality.
Definition element.hpp:24
type
An enumeration of each BSON type.
Definition types.hpp:39
binary_sub_type
An enumeration of each BSON binary sub type.
Definition types.hpp:54
A BSON array value.
Definition types.hpp:180
A BSON binary data value.
Definition types.hpp:205
A BSON boolean value.
Definition types.hpp:263
A BSON JavaScript code value.
Definition types.hpp:420
A BSON JavaScript code with scope value.
Definition types.hpp:499
A BSON date value.
Definition types.hpp:288
A BSON DBPointer value.
Definition types.hpp:401
A BSON Decimal128 value.
Definition types.hpp:605
A BSON document value.
Definition types.hpp:148
A BSON double value.
Definition types.hpp:85
A BSON signed 32-bit integer value.
Definition types.hpp:532
A BSON 64-bit signed integer value.
Definition types.hpp:580
A BSON max-key value.
Definition types.hpp:652
A BSON min-key value.
Definition types.hpp:636
A BSON null value.
Definition types.hpp:349
A BSON ObjectId value.
Definition types.hpp:245
A BSON regex value.
Definition types.hpp:365
A BSON Symbol value.
Definition types.hpp:461
A BSON replication timestamp value.
Definition types.hpp:561
A BSON undefined value.
Definition types.hpp:229
A BSON UTF-8 encoded string value.
Definition types.hpp:110