MongoDB C++ Driver mongocxx-3.10.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/array/element-fwd.hpp>
21#include <bsoncxx/document/element-fwd.hpp>
22#include <bsoncxx/document/view-fwd.hpp>
23#include <bsoncxx/types-fwd.hpp>
24#include <bsoncxx/types/bson_value/value-fwd.hpp>
25#include <bsoncxx/types/bson_value/view-fwd.hpp>
26
27#include <bsoncxx/stdx/optional.hpp>
28#include <bsoncxx/stdx/string_view.hpp>
29
30#include <bsoncxx/config/prelude.hpp>
31
32namespace bsoncxx {
33namespace v_noabi {
34namespace document {
35
45class element {
46 public:
54
59 explicit operator bool() const;
60
66 const std::uint8_t* raw() const;
67
73 std::uint32_t length() const;
74
80 std::uint32_t offset() const;
81
90
98 stdx::string_view key() const;
99
105 std::uint32_t keylen() const;
106
115
125 BSONCXX_DEPRECATED types::b_string get_utf8() const;
126
135
144
153
162
171
180
189
198
207
216
225
234
243
252
261
270
279
288
297
306
314
322
337 element operator[](stdx::string_view key) const;
338
353 array::element operator[](std::uint32_t i) const;
354
355 private:
368 BSONCXX_PRIVATE explicit element(const std::uint8_t* raw,
369 std::uint32_t length,
370 std::uint32_t offset,
371 std::uint32_t keylen);
372
373 // Construct an invalid element with a key. Useful for exceptions.
374 BSONCXX_PRIVATE explicit element(const stdx::string_view key);
375
376 friend ::bsoncxx::v_noabi::array::element;
377 friend ::bsoncxx::v_noabi::document::view;
378
379 const std::uint8_t* _raw;
380 std::uint32_t _length;
381 std::uint32_t _offset;
382 std::uint32_t _keylen;
383 // _key will only exist when a caller attempts to find a key in the BSON but is unsuccessful.
384 // The key is stored for a more helpful error message if the user tries to access the value of
385 // a key that does not exist.
386 stdx::optional<stdx::string_view> _key;
387};
388
398BSONCXX_API bool BSONCXX_CALL operator==(const element& elem, const types::bson_value::view& v);
399BSONCXX_API bool BSONCXX_CALL operator==(const types::bson_value::view& v, const element& elem);
403
413BSONCXX_API bool BSONCXX_CALL operator!=(const element& elem, const types::bson_value::view& v);
414BSONCXX_API bool BSONCXX_CALL operator!=(const types::bson_value::view& v, const element& elem);
418
419} // namespace document
420} // namespace v_noabi
421} // namespace bsoncxx
422
423namespace bsoncxx {
424namespace document {
425
426using ::bsoncxx::v_noabi::document::operator==;
427using ::bsoncxx::v_noabi::document::operator!=;
428
429} // namespace document
430} // namespace bsoncxx
431
432#include <bsoncxx/config/postlude.hpp>
A variant view type that accesses values in serialized BSON arrays.
Definition element.hpp:39
A variant view type that accesses values in serialized BSON documents.
Definition element.hpp:45
std::uint32_t keylen() const
Getter for the element's key length.
types::b_codewscope get_codewscope() const
Getter for elements of the b_codewscope type.
types::b_code get_code() const
Getter for elements of the b_code type.
types::b_null get_null() const
Getter for elements of the b_null type.
types::b_binary get_binary() const
Getter for elements of the b_binary 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.
types::b_regex get_regex() const
Getter for elements of the b_regex type.
stdx::string_view key() const
Getter for the element's key.
types::b_symbol get_symbol() const
Getter for elements of the b_symbol type.
types::b_array get_array() const
Getter for elements of the b_array type.
types::b_document get_document() const
Getter for elements of the b_document type.
std::uint32_t length() const
Getter for length of the raw bson bytes the element points to.
std::uint32_t offset() const
Getter for the offset into the raw bson bytes the element points to.
types::b_undefined get_undefined() const
Getter for elements of the b_undefined type.
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::v_noabi::type type() const
Getter for the type of the element.
types::b_bool get_bool() const
Getter for elements of the b_bool type.
types::b_dbpointer get_dbpointer() const
Getter for elements of the b_dbpointer type.
types::b_oid get_oid() const
Getter for elements of the b_oid type.
types::bson_value::view get_value() const
Getter for a types::bson_value::view 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_double get_double() const
Getter for elements of the b_double type.
types::b_date get_date() const
Getter for elements of the b_date type.
bool operator==(const element &elem, const types::bson_value::view &v)
Convenience methods to compare for equality against a bson_value.
types::b_int32 get_int32() const
Getter for elements of the b_int32 type.
types::b_timestamp get_timestamp() const
Getter for elements of the b_timestamp type.
types::b_string get_utf8() const
Getter for elements of the b_string type.
array::element operator[](std::uint32_t i) const
If this element is an array, indexes into this BSON array.
types::b_int64 get_int64() const
Getter for elements of the b_int64 type.
types::b_minkey get_minkey() const
Getter for elements of the b_minkey type.
bool operator!=(const element &elem, const types::bson_value::view &v)
Convenience methods to compare for equality against a bson_value.
types::b_maxkey get_maxkey() const
Getter for elements of the b_maxkey type.
element()
Construct an invalid element.
types::b_string get_string() const
Getter for elements of the b_string type.
types::b_decimal128 get_decimal128() const
Getter for elements of the b_decimal128 type.
A variant owning type that represents any BSON type.
Definition value.hpp:46
A view-only variant that can contain any BSON type.
Definition view.hpp:41
type
An enumeration of each BSON type.
Definition types.hpp:48
The top-level namespace for bsoncxx library entities.
Definition element-fwd.hpp:19
A BSON array value.
Definition types.hpp:197
A BSON binary data value.
Definition types.hpp:222
A BSON boolean value.
Definition types.hpp:280
A BSON JavaScript code value.
Definition types.hpp:436
A BSON JavaScript code with scope value.
Definition types.hpp:507
A BSON date value.
Definition types.hpp:305
A BSON DBPointer value.
Definition types.hpp:417
A BSON Decimal128 value.
Definition types.hpp:610
A BSON document value.
Definition types.hpp:165
A BSON double value.
Definition types.hpp:99
A BSON signed 32-bit integer value.
Definition types.hpp:541
A BSON 64-bit signed integer value.
Definition types.hpp:585
A BSON max-key value.
Definition types.hpp:653
A BSON min-key value.
Definition types.hpp:637
A BSON null value.
Definition types.hpp:364
A BSON ObjectId value.
Definition types.hpp:262
A BSON regex value.
Definition types.hpp:380
A BSON UTF-8 encoded string value.
Definition types.hpp:124
A BSON Symbol value.
Definition types.hpp:473
A BSON replication timestamp value.
Definition types.hpp:566
A BSON undefined value.
Definition types.hpp:246