MongoDB C++ Driver mongocxx-4.0.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
124 BSONCXX_ABI_EXPORT_CDECL(types::b_string) get_string() const;
125
133 BSONCXX_ABI_EXPORT_CDECL(types::b_document) get_document() const;
134
142 BSONCXX_ABI_EXPORT_CDECL(types::b_array) get_array() const;
143
151 BSONCXX_ABI_EXPORT_CDECL(types::b_binary) get_binary() const;
152
160 BSONCXX_ABI_EXPORT_CDECL(types::b_undefined) get_undefined() const;
161
169 BSONCXX_ABI_EXPORT_CDECL(types::b_oid) get_oid() const;
170
178 BSONCXX_ABI_EXPORT_CDECL(types::b_bool) get_bool() const;
179
187 BSONCXX_ABI_EXPORT_CDECL(types::b_date) get_date() const;
188
196 BSONCXX_ABI_EXPORT_CDECL(types::b_null) get_null() const;
197
205 BSONCXX_ABI_EXPORT_CDECL(types::b_regex) get_regex() const;
206
214 BSONCXX_ABI_EXPORT_CDECL(types::b_dbpointer) get_dbpointer() const;
215
223 BSONCXX_ABI_EXPORT_CDECL(types::b_code) get_code() const;
224
232 BSONCXX_ABI_EXPORT_CDECL(types::b_symbol) get_symbol() const;
233
241 BSONCXX_ABI_EXPORT_CDECL(types::b_codewscope) get_codewscope() const;
242
250 BSONCXX_ABI_EXPORT_CDECL(types::b_int32) get_int32() const;
251
259 BSONCXX_ABI_EXPORT_CDECL(types::b_timestamp) get_timestamp() const;
260
268 BSONCXX_ABI_EXPORT_CDECL(types::b_int64) get_int64() const;
269
277 BSONCXX_ABI_EXPORT_CDECL(types::b_decimal128) get_decimal128() const;
278
286 BSONCXX_ABI_EXPORT_CDECL(types::b_minkey) get_minkey() const;
287
295 BSONCXX_ABI_EXPORT_CDECL(types::b_maxkey) get_maxkey() const;
296
303 BSONCXX_ABI_EXPORT_CDECL(types::bson_value::view) get_value() const;
304
312
327 BSONCXX_ABI_EXPORT_CDECL(element) operator[](stdx::string_view key) const;
328
343 BSONCXX_ABI_EXPORT_CDECL(array::element) operator[](std::uint32_t i) const;
344
345 private:
358 explicit element(const std::uint8_t* raw,
359 std::uint32_t length,
360 std::uint32_t offset,
361 std::uint32_t keylen);
362
363 // Construct an invalid element with a key. Useful for exceptions.
364 explicit element(const stdx::string_view key);
365
366 friend ::bsoncxx::v_noabi::array::element;
367 friend ::bsoncxx::v_noabi::document::view;
368
369 const std::uint8_t* _raw;
370 std::uint32_t _length;
371 std::uint32_t _offset;
372 std::uint32_t _keylen;
373 // _key will only exist when a caller attempts to find a key in the BSON but is unsuccessful.
374 // The key is stored for a more helpful error message if the user tries to access the value of
375 // a key that does not exist.
376 stdx::optional<stdx::string_view> _key;
377};
378
385
387BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const element& elem, const types::bson_value::view& v);
388
390BSONCXX_ABI_EXPORT_CDECL(bool) operator==(const types::bson_value::view& v, const element& elem);
391
393BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const element& elem, const types::bson_value::view& v);
394
396BSONCXX_ABI_EXPORT_CDECL(bool) operator!=(const types::bson_value::view& v, const element& elem);
397
400
401} // namespace document
402} // namespace v_noabi
403} // namespace bsoncxx
404
405namespace bsoncxx {
406namespace document {
407
408using ::bsoncxx::v_noabi::document::operator==;
409using ::bsoncxx::v_noabi::document::operator!=;
410
411} // namespace document
412} // namespace bsoncxx
413
415
420
421#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
422
423namespace bsoncxx {
424namespace document {
425
428
431
434
437
438} // namespace document
439} // namespace bsoncxx
440
441#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.
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:54
Declares bsoncxx::v_noabi::document::element.
Declares bsoncxx::v_noabi::document::view.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition fwd.hpp:177
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.