MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
element.hpp
Go to the documentation of this file.
1// Copyright 2009-present 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
23#include <bsoncxx/types-fwd.hpp>
26
29
31
32namespace bsoncxx {
33namespace v_noabi {
34namespace document {
35
46class element {
47 public:
55
60 explicit BSONCXX_ABI_EXPORT_CDECL() operator bool() const;
61
67 BSONCXX_ABI_EXPORT_CDECL(const std::uint8_t*) raw() const;
68
75
82
91
99 BSONCXX_ABI_EXPORT_CDECL(stdx::string_view) key() const;
100
107
115 BSONCXX_ABI_EXPORT_CDECL(types::b_double) get_double() const;
116
127
135 BSONCXX_ABI_EXPORT_CDECL(types::b_string) get_string() const;
136
144 BSONCXX_ABI_EXPORT_CDECL(types::b_document) get_document() const;
145
153 BSONCXX_ABI_EXPORT_CDECL(types::b_array) get_array() const;
154
162 BSONCXX_ABI_EXPORT_CDECL(types::b_binary) get_binary() const;
163
171 BSONCXX_ABI_EXPORT_CDECL(types::b_undefined) get_undefined() const;
172
180 BSONCXX_ABI_EXPORT_CDECL(types::b_oid) get_oid() const;
181
189 BSONCXX_ABI_EXPORT_CDECL(types::b_bool) get_bool() const;
190
198 BSONCXX_ABI_EXPORT_CDECL(types::b_date) get_date() const;
199
207 BSONCXX_ABI_EXPORT_CDECL(types::b_null) get_null() const;
208
216 BSONCXX_ABI_EXPORT_CDECL(types::b_regex) get_regex() const;
217
225 BSONCXX_ABI_EXPORT_CDECL(types::b_dbpointer) get_dbpointer() const;
226
234 BSONCXX_ABI_EXPORT_CDECL(types::b_code) get_code() const;
235
243 BSONCXX_ABI_EXPORT_CDECL(types::b_symbol) get_symbol() const;
244
252 BSONCXX_ABI_EXPORT_CDECL(types::b_codewscope) get_codewscope() const;
253
261 BSONCXX_ABI_EXPORT_CDECL(types::b_int32) get_int32() const;
262
270 BSONCXX_ABI_EXPORT_CDECL(types::b_timestamp) get_timestamp() const;
271
279 BSONCXX_ABI_EXPORT_CDECL(types::b_int64) get_int64() const;
280
288 BSONCXX_ABI_EXPORT_CDECL(types::b_decimal128) get_decimal128() const;
289
297 BSONCXX_ABI_EXPORT_CDECL(types::b_minkey) get_minkey() const;
298
306 BSONCXX_ABI_EXPORT_CDECL(types::b_maxkey) get_maxkey() const;
307
314 BSONCXX_ABI_EXPORT_CDECL(types::bson_value::view) get_value() const;
315
323
338 BSONCXX_ABI_EXPORT_CDECL(element) operator[](stdx::string_view key) const;
339
354 BSONCXX_ABI_EXPORT_CDECL(array::element) operator[](std::uint32_t i) const;
355
356 private:
369 explicit element(const std::uint8_t* raw,
370 std::uint32_t length,
371 std::uint32_t offset,
372 std::uint32_t keylen);
373
374 // Construct an invalid element with a key. Useful for exceptions.
375 explicit element(const stdx::string_view key);
376
377 friend ::bsoncxx::v_noabi::array::element;
378 friend ::bsoncxx::v_noabi::document::view;
379
380 const std::uint8_t* _raw;
381 std::uint32_t _length;
382 std::uint32_t _offset;
383 std::uint32_t _keylen;
384 // _key will only exist when a caller attempts to find a key in the BSON but is unsuccessful.
385 // The key is stored for a more helpful error message if the user tries to access the value of
386 // a key that does not exist.
387 stdx::optional<stdx::string_view> _key;
388};
389
396
398BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const element& elem, const types::bson_value::view& v);
399
401BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const types::bson_value::view& v, const element& elem);
402
404BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const element& elem, const types::bson_value::view& v);
405
407BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const types::bson_value::view& v, const element& elem);
408
411
412} // namespace document
413} // namespace v_noabi
414} // namespace bsoncxx
415
416namespace bsoncxx {
417namespace document {
418
419using ::bsoncxx::v_noabi::document::operator==;
420using ::bsoncxx::v_noabi::document::operator!=;
421
422} // namespace document
423} // namespace bsoncxx
424
426
431
432#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
433
434namespace bsoncxx {
435namespace document {
436
439
442
445
448
449} // namespace document
450} // namespace bsoncxx
451
452#endif // defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
Declares bsoncxx::v_noabi::array::element.
The bsoncxx macro guard postlude header.
The bsoncxx macro guard prelude header.
A variant view type that accesses values in serialized BSON documents.
Definition element.hpp:46
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.
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....
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.
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_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.
BSONCXX_DEPRECATED types::b_string get_utf8() const
Getter for elements of the b_string type.
types::b_maxkey get_maxkey() const
Getter for elements of the b_maxkey type.
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 read-only BSON document that owns its underlying buffer. When a document::value goes out of scope,...
Definition value.hpp:38
A read-only, non-owning view of a BSON document.
Definition view.hpp:35
A view-only variant that can contain any BSON type.
Definition view.hpp:41
Declares bsoncxx::v_noabi::document::element.
Declares bsoncxx::v_noabi::document::view.
#define BSONCXX_DEPRECATED
Declares the associated entity as deprecated.
Definition fwd.hpp:261
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:225
bool operator!=(const v_noabi::document::element &elem, const v_noabi::types::bson_value::view &v)
bsoncxx::v_noabi::document::operator!=(const v_noabi::document::element& elem, const v_noabi::types::...
bool operator==(const v_noabi::document::element &elem, const v_noabi::types::bson_value::view &v)
bsoncxx::v_noabi::document::operator==(const v_noabi::document::element& elem, const v_noabi::types::...
type
An enumeration of each BSON type.
Definition types.hpp:43
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Declares entities used to represent BSON types.
Declares bsoncxx::v_noabi::types::bson_value::value.
Declares bsoncxx::v_noabi::types::bson_value::view.