Loading...
Searching...
No Matches
value.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/value-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/type_traits.hpp>
#include <bsoncxx/v1/types/value.hpp> // IWYU pragma: export
#include <iostream> // IWYU pragma: keep: backward compatibility, to be removed.
#include <memory> // IWYU pragma: keep: backward compatibility, to be removed.
#include <string>
#include <utility>
#include <vector>
#include <bsoncxx/document/element-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/array/view_or_value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
#include <bsoncxx/document/view_or_value.hpp>
#include <bsoncxx/types/bson_value/view.hpp>
#include <bsoncxx/config/prelude.hpp>
namespace bsoncxx {
namespace v_noabi {
namespace types {
namespace bson_value {
class value {
private:
v1::types::value _value;
template <typename T>
using is_value = detail::is_alike<T, value>;
template <typename T>
using from_v1_expr = decltype(from_v1(std::declval<T>()));
template <typename T>
struct has_from_v1 : detail::conjunction<detail::negation<is_value<T>>, detail::is_detected<from_v1_expr, T>> {};
public:
value() = default;
/* explicit(false) */ value(v1::types::value v) : _value{std::move(v)} {}
template <typename T, detail::enable_if_t<has_from_v1<T>::value>* = nullptr>
/* explicit(false) */ value(T v) : value{from_v1(v)} {}
#pragma push_macro("X")
#undef X
#define X(_name, _unused) \
/* explicit(false) */ value(v_noabi::types::b_##_name v) : _value{to_v1(v)} {}
BSONCXX_V1_TYPES_XMACRO(X)
#pragma pop_macro("X")
/* explicit(false) */ value(char const* v) : _value{v} {}
/* explicit(false) */ value(std::string v) : _value{std::move(v)} {}
/* explicit(false) */ value(v1::stdx::string_view v) : _value{v} {}
/* explicit(false) */ value(std::int32_t v) : _value{v} {}
/* explicit(false) */ value(std::int64_t v) : _value{v} {}
/* explicit(false) */ value(double v) : _value{v} {}
/* explicit(false) */ value(bool v) : _value{v} {}
/* explicit(false) */ value(v_noabi::oid v) : _value{to_v1(v)} {}
/* explicit(false) */ value(v_noabi::decimal128 v) : _value{to_v1(v)} {}
/* explicit(false) */ value(std::chrono::milliseconds v) : _value{v} {}
/* explicit(false) */ value(std::nullptr_t) : _value{nullptr} {}
/* explicit(false) */ value(v_noabi::document::view v) : _value{to_v1(v)} {}
/* explicit(false) */ value(v_noabi::array::view v) : _value{to_v1(v)} {}
/* explicit(false) */
value(std::vector<unsigned char> v, v_noabi::binary_sub_type const sub_type = {})
: _value{reinterpret_cast<std::uint8_t const*>(v.data()), v.size(), to_v1(sub_type)} {}
/* explicit(false) */
value(std::uint8_t const* data, std::size_t size, v_noabi::binary_sub_type const sub_type = {})
: _value{data, size, to_v1(sub_type)} {}
/* explicit(false) */ value(v1::stdx::string_view collection, v_noabi::oid value)
: _value{collection, to_v1(value)} {}
/* explicit(false) */ value(v1::stdx::string_view code, v_noabi::document::view_or_value scope)
: _value{code, to_v1(scope.view())} {}
/* explicit(false) */ value(v1::stdx::string_view regex, v1::stdx::string_view options)
: _value{v1::types::b_regex{regex, options}} {}
/* explicit(false) */ BSONCXX_ABI_EXPORT_CDECL_UNSTABLE() value(v_noabi::type const id, v1::stdx::string_view v);
/* explicit(false) */ BSONCXX_ABI_EXPORT_CDECL_UNSTABLE() value(v_noabi::type const id);
BSONCXX_ABI_EXPORT_CDECL_UNSTABLE() value(v_noabi::type const id, std::uint64_t a, std::uint64_t b);
explicit value(v_noabi::types::bson_value::view const& v) : _value{to_v1(v)} {}
explicit operator v1::types::value() && {
return std::move(_value);
}
explicit operator v1::types::value() const& {
return _value;
}
v_noabi::type type() const {
return this->view().type();
}
v_noabi::type type_id() const {
return this->view().type_id();
}
v_noabi::types::bson_value::view view() const noexcept {
return _value.view();
}
/* explicit(false) */ operator v_noabi::types::bson_value::view() const noexcept {
return _value.view();
}
#pragma push_macro("X")
#undef X
#define X(_name, _value) \
v_noabi::types::b_##_name const& get_##_name() const { \
return this->view().get_##_name(); \
}
BSONCXX_V1_TYPES_XMACRO(X)
#pragma pop_macro("X")
};
inline bool operator==(value const& lhs, value const& rhs) {
return (lhs.view() == rhs.view());
}
inline bool operator!=(value const& lhs, value const& rhs) {
return !(lhs == rhs);
}
inline bool operator==(value const& lhs, view const& rhs) {
return (lhs.view() == rhs);
}
inline bool operator==(view const& lhs, value const& rhs) {
return (rhs == lhs);
}
inline bool operator!=(value const& lhs, view const& rhs) {
return !(lhs == rhs);
}
inline bool operator!=(view const& lhs, value const& rhs) {
return !(lhs == rhs);
}
} // namespace bson_value
} // namespace types
} // namespace v_noabi
} // namespace bsoncxx
namespace bsoncxx {
namespace v_noabi {
inline v_noabi::types::bson_value::value from_v1(v1::types::value v) {
return {std::move(v)};
}
inline v1::types::value to_v1(v_noabi::types::bson_value::value v) {
return v1::types::value{std::move(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>
view_or_value.hpp
Provides bsoncxx::v_noabi::array::view_or_value.
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::value::value
value()=default
Initialize with bsoncxx::v1::types::b_null.
bsoncxx::v1::stdx::string_view
A polyfill for std::string_view.
Definition string_view.hpp:412
bsoncxx::v1::types::value
A union of BSON type values.
Definition value.hpp:52
bsoncxx::v_noabi::array::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:41
bsoncxx::v_noabi::decimal128
Represents a MongoDB BSON Decimal128.
Definition decimal128.hpp:45
bsoncxx::v_noabi::document::view
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
bsoncxx::v_noabi::oid
Represents a MongoDB BSON ObjectId.
Definition oid.hpp:41
bsoncxx::v_noabi::types::bson_value::value
An owning variant type that represents any BSON type.
Definition value.hpp:57
bsoncxx::v_noabi::types::bson_value::value::value
value(T v)
Construct with the bsoncxx::v1 equivalent.
Definition value.hpp:86
bsoncxx::v_noabi::types::bson_value::value::operator!=
bool operator!=(value const &lhs, view const &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:388
bsoncxx::v_noabi::types::bson_value::value::value
value(v_noabi::document::view v)
Constructs a BSON document value.
Definition value.hpp:160
bsoncxx::v_noabi::types::bson_value::value::value
value(v_noabi::decimal128 v)
Constructs a BSON Decimal128 value.
Definition value.hpp:145
bsoncxx::v_noabi::types::bson_value::value::value
value(v1::stdx::string_view v)
Constructs a BSON UTF-8 string value.
Definition value.hpp:115
bsoncxx::v_noabi::types::bson_value::value::operator==
bool operator==(value const &lhs, value const &rhs)
Compares values for (in)-equality.
Definition value.hpp:360
bsoncxx::v_noabi::types::bson_value::value::value
value(v_noabi::array::view v)
Constructs a BSON array value.
Definition value.hpp:165
bsoncxx::v_noabi::types::bson_value::value::value
value(v1::stdx::string_view collection, v_noabi::oid value)
Constructs a BSON DBPointer value.
Definition value.hpp:203
bsoncxx::v_noabi::types::bson_value::value::value
value(char const *v)
Constructs a BSON UTF-8 string value.
Definition value.hpp:105
bsoncxx::v_noabi::types::bson_value::value::operator!=
bool operator!=(view const &lhs, value const &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:393
bsoncxx::v_noabi::types::bson_value::value::value
value(std::uint8_t const *data, std::size_t size, v_noabi::binary_sub_type const sub_type={})
Constructs a BSON binary data value.
Definition value.hpp:190
bsoncxx::v_noabi::types::bson_value::value::value
value(v1::types::value v)
Construct with the bsoncxx::v1 equivalent.
Definition value.hpp:77
bsoncxx::v_noabi::types::bson_value::value::value
value(double v)
Constructs a BSON double value.
Definition value.hpp:130
bsoncxx::v_noabi::types::bson_value::value::type_id
v_noabi::type type_id() const
Equivalent to type() const.
Definition value.hpp:316
bsoncxx::v_noabi::types::bson_value::value::value
value(std::string v)
Constructs a BSON UTF-8 string value.
Definition value.hpp:110
bsoncxx::v_noabi::types::bson_value::value::operator==
bool operator==(value const &lhs, view const &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:378
bsoncxx::v_noabi::types::bson_value::value::operator==
bool operator==(view const &lhs, value const &rhs)
Compares a value with a view for (in)equality.
Definition value.hpp:383
bsoncxx::v_noabi::types::bson_value::value::view
v_noabi::types::bson_value::view view() const noexcept
Get a view over the bson_value owned by this object.
Definition value.hpp:323
bsoncxx::v_noabi::types::bson_value::value::value
value()=default
Initialize with bsoncxx::v1::types::b_null.
bsoncxx::v_noabi::types::bson_value::value::value
value(std::chrono::milliseconds v)
Constructs a BSON date value.
Definition value.hpp:150
bsoncxx::v_noabi::types::bson_value::value::type
v_noabi::type type() const
Returns the type of the underlying BSON value stored in this object.
Definition value.hpp:307
bsoncxx::v_noabi::types::bson_value::value::value
value(std::int32_t v)
Constructs a BSON 32-bit signed integer value.
Definition value.hpp:120
bsoncxx::v_noabi::types::bson_value::value::value
value(v1::stdx::string_view code, v_noabi::document::view_or_value scope)
Constructs a BSON JavaScript code with scope value.
Definition value.hpp:214
bsoncxx::v_noabi::types::bson_value::value::value
value(bool v)
Constructs a BSON boolean value.
Definition value.hpp:135
bsoncxx::v_noabi::types::bson_value::value::value
value(std::vector< unsigned char > v, v_noabi::binary_sub_type const sub_type={})
Constructs a BSON binary data value.
Definition value.hpp:176
bsoncxx::v_noabi::types::bson_value::value::operator!=
bool operator!=(value const &lhs, value const &rhs)
Compares values for (in)-equality.
Definition value.hpp:365
bsoncxx::v_noabi::types::bson_value::value::value
value(v1::stdx::string_view regex, v1::stdx::string_view options)
Constructs a BSON regex value with options.
Definition value.hpp:225
bsoncxx::v_noabi::types::bson_value::value::value
value(v_noabi::oid v)
Constructs a BSON ObjectId value.
Definition value.hpp:140
bsoncxx::v_noabi::types::bson_value::value::value
value(std::int64_t v)
Constructs a BSON 64-bit signed integer value.
Definition value.hpp:125
bsoncxx::v_noabi::types::bson_value::value::value
value(std::nullptr_t)
Constructs a BSON null value.
Definition value.hpp:155
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::type_id
v_noabi::type type_id() const
Equivalent to type() const.
Definition view.hpp:144
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::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
element-fwd.hpp
Declares bsoncxx::v_noabi::document::element.
view_or_value.hpp
Provides bsoncxx::v_noabi::document::view_or_value.
bsoncxx::types::bson_value
Declares entities representing any BSON value type.
bsoncxx::types
Declares entities representing BSON value types.
bsoncxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
bsoncxx::v_noabi::document::view_or_value
v_noabi::view_or_value< v_noabi::document::view, v_noabi::document::value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::document::view, v_noabi::document::value>.
Definition view_or_value.hpp:30
bsoncxx::v_noabi::stdx
Declares C++17 standard library polyfills.
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::binary_sub_type
binary_sub_type
An enumeration of each BSON binary sub type.
Definition types.hpp:78
bsoncxx::v_noabi::type
type
An enumeration of each BSON type.
Definition types.hpp:47
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.
bsoncxx::v_noabi::types::b_regex
A BSON regex value.
Definition types.hpp:423
type_traits.hpp
For internal use only!
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
value.hpp
Provides bsoncxx::v1::types::value.
value-fwd.hpp
Declares bsoncxx::v_noabi::types::bson_value::value.
view.hpp
Provides bsoncxx::v_noabi::types::bson_value::view.