Loading...
Searching...
No Matches
view.hpp
Go to the documentation of this file.
// Copyright 2009-present MongoDB, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <bsoncxx/types/bson_value/view-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/types/view.hpp> // IWYU pragma: export
#include <cstddef>
#include <cstdint> // IWYU pragma: keep: backward compatibility, to be removed.
#include <type_traits>
#include <bsoncxx/document/element-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/types/bson_value/value-fwd.hpp>
#include <bsoncxx/stdx/type_traits.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/config/prelude.hpp>
namespace bsoncxx {
namespace detail {
template <typename T>
using is_bson_view_compatible = detail::conjunction<
std::is_constructible<v_noabi::types::bson_value::view, T>,
detail::negation<detail::disjunction<
detail::is_alike<T, v_noabi::types::bson_value::view>,
detail::is_alike<T, v_noabi::types::bson_value::value>>>>;
} // namespace detail
} // namespace bsoncxx
namespace bsoncxx {
namespace v_noabi {
namespace types {
namespace bson_value {
class view {
private:
v_noabi::type _id;
#pragma push_macro("X")
#undef X
#define X(_name, _value) b_##_name _b_##_name;
union {
BSONCXX_V1_TYPES_XMACRO(X)
};
#pragma pop_macro("X")
public:
view() noexcept : _id{v_noabi::type::k_null}, _b_null{} {}
/* explicit(false) */ view(v1::types::view const& v) : _id{from_v1(v.type_id())} {
#pragma push_macro("X")
#undef X
#define X(_name, _value) \
case v_noabi::type::k_##_name: \
_b_##_name = from_v1(v.get_##_name()); \
break;
switch (_id) { BSONCXX_V1_TYPES_XMACRO(X) }
#pragma pop_macro("X")
}
#pragma push_macro("X")
#undef X
#define X(_name, _value) \
explicit view(v_noabi::types::b_##_name v) noexcept : _id{v.type_id}, _b_##_name{v} {}
BSONCXX_V1_TYPES_XMACRO(X)
#pragma pop_macro("X")
explicit operator v1::types::view() const {
#pragma push_macro("X")
#undef X
#define X(_name, _value) \
case v_noabi::type::k_##_name: \
return {to_v1(_b_##_name)};
switch (_id) {
BSONCXX_V1_TYPES_XMACRO(X)
default:
return {}; // Unreachable.
}
#pragma pop_macro("X")
}
v_noabi::type type() const {
return _id;
}
v_noabi::type type_id() const {
return _id;
}
#pragma push_macro("X")
#undef X
#define X(_name, _value) BSONCXX_ABI_EXPORT_CDECL_UNSTABLE(v_noabi::types::b_##_name const&) get_##_name() const;
BSONCXX_V1_TYPES_XMACRO(X)
#pragma pop_macro("X")
friend BSONCXX_ABI_EXPORT_CDECL_UNSTABLE(bool) operator==(view const& lhs, view const& rhs);
friend bool operator!=(view const& lhs, view const& rhs) {
return !(lhs == rhs);
}
};
template <typename T>
detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator==(view const& lhs, T&& rhs) {
return lhs == view{std::forward<T>(rhs)};
}
template <typename T>
detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator==(T&& lhs, view const& rhs) {
return view{std::forward<T>(lhs)} == rhs;
}
template <typename T>
detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator!=(view const& lhs, T&& rhs) {
return lhs != view{std::forward<T>(rhs)};
}
template <typename T>
detail::requires_t<bool, detail::is_bson_view_compatible<T>> operator!=(T&& lhs, view const& rhs) {
return view{std::forward<T>(lhs)} != rhs;
}
} // namespace bson_value
} // namespace types
} // namespace v_noabi
} // namespace bsoncxx
namespace bsoncxx {
namespace v_noabi {
inline v_noabi::types::bson_value::view from_v1(v1::types::view const& v) {
return {v};
}
inline v1::types::view to_v1(v_noabi::types::bson_value::view const& v) {
return v1::types::view{v};
}
} // namespace v_noabi
} // namespace bsoncxx
namespace bsoncxx {
namespace types {
namespace bson_value {
using v_noabi::types::bson_value::operator==;
using v_noabi::types::bson_value::operator!=;
} // namespace bson_value
} // namespace types
} // namespace bsoncxx
#include <bsoncxx/config/postlude.hpp>
BSONCXX_ABI_EXPORT_CDECL_UNSTABLE
#define BSONCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to BSONCXX_ABI_EXPORT_UNSTABLE with BSONCXX_ABI_CDECL.
Definition config.hpp:28
postlude.hpp
The bsoncxx v_noabi macro guard postlude header.
prelude.hpp
The bsoncxx v_noabi macro guard prelude header.
bsoncxx::types::bson_value::view::view
view() noexcept
Default constructs a bson_value::view. The resulting view will be initialized to point at a bson_valu...
Definition view.hpp:80
bsoncxx::v1::types::view
A non-owning, read-only union of BSON type values.
Definition view.hpp:979
bsoncxx::v_noabi::types::bson_value::view
A non-owning variant that can contain any BSON type.
Definition view.hpp:62
bsoncxx::v_noabi::types::bson_value::view::operator!=
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator!=(T &&lhs, view const &rhs)
Compares a view with a type representable as a view.
Definition view.hpp:207
bsoncxx::v_noabi::types::bson_value::view::type_id
v_noabi::type type_id() const
Equivalent to type() const.
Definition view.hpp:144
bsoncxx::v_noabi::types::bson_value::view::operator!=
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator!=(view const &lhs, T &&rhs)
Compares a view with a type representable as a view.
Definition view.hpp:201
bsoncxx::v_noabi::types::bson_value::view::operator==
friend bool operator==(view const &lhs, view const &rhs)
Compare two bson_value::views for equality.
bsoncxx::v_noabi::types::bson_value::view::type
v_noabi::type type() const
Returns the type of the underlying BSON value stored in this object.
Definition view.hpp:135
bsoncxx::v_noabi::types::bson_value::view::operator!=
friend bool operator!=(view const &lhs, view const &rhs)
Compare two bson_value::views for equality.
Definition view.hpp:172
bsoncxx::v_noabi::types::bson_value::view::operator==
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator==(view const &lhs, T &&rhs)
Compares a view with a type representable as a view.
Definition view.hpp:189
bsoncxx::v_noabi::types::bson_value::view::view
view() noexcept
Default constructs a bson_value::view. The resulting view will be initialized to point at a bson_valu...
Definition view.hpp:80
bsoncxx::v_noabi::types::bson_value::view::view
view(v1::types::view const &v)
Construct with the bsoncxx::v1 equivalent.
Definition view.hpp:85
bsoncxx::v_noabi::types::bson_value::view::operator==
detail::requires_t< bool, detail::is_bson_view_compatible< T > > operator==(T &&lhs, view const &rhs)
Compares a view with a type representable as a view.
Definition view.hpp:195
element-fwd.hpp
Declares bsoncxx::v_noabi::document::element.
bsoncxx::types::bson_value
Declares entities representing any BSON value type.
bsoncxx::types
Declares entities representing BSON value types.
bsoncxx::v_noabi::types::bson_value
Declares entities representing any BSON value type.
bsoncxx::v_noabi::types
Declares entities representing BSON value types.
bsoncxx::v_noabi
Declares entities whose ABI stability is NOT guaranteed.
bsoncxx::v_noabi::type
type
An enumeration of each BSON type.
Definition types.hpp:47
bsoncxx::v_noabi::type::k_null
@ k_null
Null value.
Definition types.hpp:57
bsoncxx::v_noabi::to_v1
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
bsoncxx::v_noabi::from_v1
v_noabi::array::value from_v1(v1::array::value const &v)
Convert from the bsoncxx::v1 equivalent of v.
Definition value.hpp:263
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
types.hpp
Provides entities used to represent BSON types.
BSONCXX_V1_TYPES_XMACRO
#define BSONCXX_V1_TYPES_XMACRO(X)
X-macro over the name and value of BSON types.
Definition id-fwd.hpp:44
view.hpp
Provides non-owning, read-only entities representing a BSON type value.
type_traits.hpp
For internal use only!
value-fwd.hpp
Declares bsoncxx::v_noabi::types::bson_value::value.
view-fwd.hpp
Declares bsoncxx::v_noabi::types::bson_value::view.