MongoDB C++ Driver 4.2.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 <bsoncxx/array/element-fwd.hpp> // IWYU pragma: export
18
19//
20
22
23#include <bsoncxx/v1/element/view.hpp> // IWYU pragma: export
24
25#include <cstddef>
26#include <cstdint> // IWYU pragma: keep: backward compatibility, to be removed.
27
28#include <bsoncxx/array/view-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
30
31#include <bsoncxx/document/element.hpp> // IWYU pragma: export
32
34
35namespace bsoncxx {
36namespace v_noabi {
37namespace array {
38
46class element : private v_noabi::document::element {
47 public:
49
50 /* explicit(false) */ element(v1::element::view const& v) : v_noabi::document::element{v} {}
51
52 using v_noabi::document::element::operator v1::element::view;
53
54 using v_noabi::document::element::operator bool;
55
57
59
61
63
65
67
68#pragma push_macro("X")
69#undef X
70#define X(_name, _value) using v_noabi::document::element::get_##_name;
72#pragma pop_macro("X")
73
75
77
79
81
82 using v_noabi::document::element::operator[];
83
84 friend bool operator==(element const& lhs, v_noabi::types::bson_value::view const& rhs);
85};
86
93
95inline bool operator==(element const& lhs, v_noabi::types::bson_value::view const& rhs) {
96 return static_cast<v_noabi::document::element const&>(lhs) == rhs;
97}
98
100inline bool operator==(v_noabi::types::bson_value::view const& lhs, element const& rhs) {
101 return rhs == lhs;
102}
103
105inline bool operator!=(element const& lhs, v_noabi::types::bson_value::view const& rhs) {
106 return !(lhs == rhs);
107}
108
110inline bool operator!=(v_noabi::types::bson_value::view const& lhs, element const& rhs) {
111 return !(lhs == rhs);
112}
113
116
117} // namespace array
118} // namespace v_noabi
119} // namespace bsoncxx
120
121namespace bsoncxx {
122namespace v_noabi {
123
124// Ambiguous whether `v1::element::view` should be converted to `v_noabi::array::element` or
125// `v_noabi::document::element.` Require users to explicitly cast to the expected type instead.
126//
127// v_noabi::array::element from_v1(v1::element::view const& v);
128
135
136} // namespace v_noabi
137} // namespace bsoncxx
138
139namespace bsoncxx {
140namespace array {
141
142using v_noabi::array::operator==;
143using v_noabi::array::operator!=;
144
145} // namespace array
146} // namespace bsoncxx
147
149
Declares bsoncxx::v_noabi::array::element.
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
A non-owning, read-only BSON element.
Definition view.hpp:84
A variant view type that accesses values in serialized BSON arrays.
Definition element.hpp:46
friend bool operator==(element const &lhs, v_noabi::types::bson_value::view const &rhs)
Convenience methods to compare for equality against a bson_value.
Definition element.hpp:95
bool operator==(v_noabi::types::bson_value::view const &lhs, element const &rhs)
Convenience methods to compare for equality against a bson_value.
Definition element.hpp:100
bool operator!=(v_noabi::types::bson_value::view const &lhs, element const &rhs)
Convenience methods to compare for equality against a bson_value.
Definition element.hpp:110
bool operator!=(element const &lhs, v_noabi::types::bson_value::view const &rhs)
Convenience methods to compare for equality against a bson_value.
Definition element.hpp:105
A variant view type that accesses values in serialized BSON documents.
Definition element.hpp:52
v_noabi::types::bson_value::view get_value() const
Getter for a types::bson_value::view variant wrapper of the value portion of the element.
std::uint32_t keylen() const
Getter for the element's key length.
Definition element.hpp:117
v1::stdx::string_view key() const
Getter for the element's key.
v_noabi::types::bson_value::value type_value() const
Equivalent to get_owning_value() const.
std::uint8_t const * raw() const
Getter for the raw bson bytes the element points to.
Definition element.hpp:90
std::uint32_t length() const
Getter for length of the raw bson bytes the element points to.
Definition element.hpp:99
std::uint32_t offset() const
Getter for the offset into the raw bson bytes the element points to.
Definition element.hpp:108
element()=default
Construct an invalid element.
v_noabi::types::bson_value::view type_view() const
Equivalent to get_value() const.
v_noabi::types::bson_value::value get_owning_value() const
Getter for a types::bson_value::value variant wrapper of the value portion of the element....
v_noabi::type type() const
Getter for the type of the element.
A non-owning variant that can contain any BSON type.
Definition view.hpp:62
Provides bsoncxx::v_noabi::document::element.
Declares entities representing a BSON array.
Declares entities representing a BSON array.
bool operator==(element const &lhs, v_noabi::types::bson_value::view const &rhs)
Convenience methods to compare for equality against a bson_value.
Definition element.hpp:95
Declares entities whose ABI stability is NOT guaranteed.
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
The top-level namespace within which all bsoncxx library entities are declared.
Provides bsoncxx::v1::element::view.
Declares enumerations identifying the type of a BSON element.
#define BSONCXX_V1_TYPES_XMACRO(X)
X-macro over the name and value of BSON types.
Definition id-fwd.hpp:44
Declares bsoncxx::v_noabi::array::view.
Declares bsoncxx::v_noabi::types::bson_value::view.