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/v1/types/value-fwd.hpp> // IWYU pragma: export
//
#include <bsoncxx/v1/detail/prelude.hpp>
#include <bsoncxx/v1/array/view-fwd.hpp>
#include <bsoncxx/v1/decimal128-fwd.hpp>
#include <bsoncxx/v1/document/view-fwd.hpp>
#include <bsoncxx/v1/oid-fwd.hpp>
#include <bsoncxx/v1/types/id-fwd.hpp>
#include <bsoncxx/v1/config/export.hpp>
#include <bsoncxx/v1/detail/macros.hpp>
#include <bsoncxx/v1/stdx/string_view.hpp>
#include <bsoncxx/v1/types/view.hpp> // IWYU pragma: export
#include <array>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <string>
#include <system_error>
#include <type_traits>
#include <vector>
namespace bsoncxx {
namespace v1 {
namespace types {
class value {
private:
class impl;
alignas(BSONCXX_PRIVATE_MAX_ALIGN_T) std::array<unsigned char, 32> _storage;
public:
BSONCXX_ABI_EXPORT_CDECL() ~value();
BSONCXX_ABI_EXPORT_CDECL() value(value&& other) noexcept;
BSONCXX_ABI_EXPORT_CDECL(value&) operator=(value&& other) noexcept;
BSONCXX_ABI_EXPORT_CDECL() value(value const& other);
BSONCXX_ABI_EXPORT_CDECL(value&) operator=(value const& other);
value() : value{v1::types::b_null{}} {}
explicit BSONCXX_ABI_EXPORT_CDECL() value(v1::types::view const& v);
#pragma push_macro("X")
#undef X
#define X(_name, _value) explicit BSONCXX_ABI_EXPORT_CDECL() value(v1::types::b_##_name v);
BSONCXX_V1_TYPES_XMACRO(X)
#pragma pop_macro("X")
explicit value(std::nullptr_t) : value{v1::types::b_null{}} {}
explicit value(v1::stdx::string_view v) : value{v1::types::b_string{v}} {}
explicit value(std::int32_t v) : value{v1::types::b_int32{v}} {}
explicit value(std::int64_t v) : value{v1::types::b_int64{v}} {}
explicit value(double v) : value{v1::types::b_double{v}} {}
explicit value(bool v) : value{v1::types::b_bool{v}} {}
explicit value(v1::oid v) : value{v1::types::b_oid{v}} {}
explicit value(v1::decimal128 v) : value{v1::types::b_decimal128{v}} {}
explicit value(std::chrono::milliseconds v) : value{v1::types::b_date{v}} {}
explicit value(v1::document::view v) : value{v1::types::b_document{v}} {}
explicit value(v1::array::view v) : value{v1::types::b_array{v}} {}
explicit value(std::vector<std::uint8_t> const& v)
: value{v.data(), v.size(), v1::types::binary_subtype::k_binary} {}
explicit value(std::vector<std::uint8_t> const& v, v1::types::binary_subtype subtype)
: value{v.data(), v.size(), subtype} {}
explicit value(v1::stdx::string_view c, v1::oid v) : value{v1::types::b_dbpointer{c, v}} {}
explicit value(v1::stdx::string_view code, v1::document::view scope)
: value{v1::types::b_codewscope{code, scope}} {}
explicit value(v1::stdx::string_view regex, v1::stdx::string_view options)
: value{v1::types::b_regex{regex, options}} {}
explicit value(char const* v) : value{v1::stdx::string_view{v}} {}
explicit value(std::string const& v) : value{v1::stdx::string_view{v}} {}
explicit value(std::uint8_t const* data, std::size_t size)
: value{data, size, v1::types::binary_subtype::k_binary} {}
explicit BSONCXX_ABI_EXPORT_CDECL()
value(std::uint8_t const* data, std::size_t size, v1::types::binary_subtype const sub_type);
BSONCXX_ABI_EXPORT_CDECL(v1::types::id) type_id() const;
BSONCXX_ABI_EXPORT_CDECL(v1::types::view) view() const;
/* explicit(false) */ operator v1::types::view() const {
return this->view();
}
#pragma push_macro("X")
#undef X
#define X(_name, _value) \
v1::types::b_##_name get_##_name() const { \
return this->view().get_##_name(); \
}
BSONCXX_V1_TYPES_XMACRO(X)
#pragma pop_macro("X")
friend bool operator==(value const& lhs, value const& rhs) {
return lhs.view() == rhs.view();
}
friend bool operator!=(value const& lhs, value const& rhs) {
return !(lhs == rhs);
}
enum class errc {
zero,
invalid_type,
invalid_length_u32,
};
static BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
friend std::error_code make_error_code(errc v) {
return {static_cast<int>(v), error_category()};
}
class internal;
};
} // namespace types
} // namespace v1
} // namespace bsoncxx
template <>
struct std::is_error_code_enum<bsoncxx::v1::types::value::errc> : true_type {};
#include <bsoncxx/v1/detail/postlude.hpp>
export.hpp
Provides macros to control the set of symbols exported in the ABI.
BSONCXX_ABI_EXPORT_CDECL
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
macros.hpp
For internal use only!
postlude.hpp
The bsoncxx v1 macro guard postlude header.
prelude.hpp
The bsoncxx v1 macro guard prelude header.
bsoncxx::v1::array::view
A non-owning, read-only BSON array.
Definition view.hpp:47
bsoncxx::v1::decimal128
A BSON Decimal128.
Definition decimal128.hpp:37
bsoncxx::v1::document::view
A non-owning, read-only BSON document.
Definition view.hpp:52
bsoncxx::v1::oid
A BSON ObjectID.
Definition oid.hpp:41
bsoncxx::v1::stdx::string_view
A polyfill for std::string_view.
Definition string_view.hpp:412
bsoncxx::v1::types::value::value
value(std::vector< std::uint8_t > const &v, v1::types::binary_subtype subtype)
Initialize with v as a bsoncxx::v1::types::b_binary with subtype.
Definition value.hpp:199
bsoncxx::v1::types::value::value
value(std::int64_t v)
Initialize as a bsoncxx::v1::types::b_int64.
Definition value.hpp:152
bsoncxx::v1::types::value::type_id
v1::types::id type_id() const
Return the type of the underlying BSON type value.
bsoncxx::v1::types::value::value
value(v1::oid v)
Initialize as a bsoncxx::v1::types::b_oid.
Definition value.hpp:167
bsoncxx::v1::types::value::value
value(std::nullptr_t)
Initialize as a bsoncxx::v1::types::b_null.
Definition value.hpp:137
bsoncxx::v1::types::value::errc
errc
Errors codes which may be returned by bsoncxx::v1::types::value.
Definition value.hpp:296
bsoncxx::v1::types::value::errc::invalid_type
@ invalid_type
Requested BSON type is not supported.
Definition value.hpp:298
bsoncxx::v1::types::value::errc::invalid_length_u32
@ invalid_length_u32
Length is too long (exceeds UINT32_MAX).
Definition value.hpp:299
bsoncxx::v1::types::value::errc::zero
@ zero
Zero.
Definition value.hpp:297
bsoncxx::v1::types::value::operator==
friend bool operator==(value const &lhs, value const &rhs)
Equivalent to lhs.view() == rhs.view().
Definition value.hpp:282
bsoncxx::v1::types::value::value
value(v1::decimal128 v)
Initialize as a bsoncxx::v1::types::b_decimal128.
Definition value.hpp:172
bsoncxx::v1::types::value::value
value(bool v)
Initialize as a bsoncxx::v1::types::b_bool.
Definition value.hpp:162
bsoncxx::v1::types::value::value
value(char const *v)
Initialize as a bsoncxx::v1::types::b_string.
Definition value.hpp:222
bsoncxx::v1::types::value::value
value(v1::stdx::string_view c, v1::oid v)
Initialize as a bsoncxx::v1::types::b_dbpointer.
Definition value.hpp:205
bsoncxx::v1::types::value::value
value(v1::stdx::string_view regex, v1::stdx::string_view options)
Initialize as a bsoncxx::v1::types::b_regex.
Definition value.hpp:216
bsoncxx::v1::types::value::value
value(v1::document::view v)
Initialize as a bsoncxx::v1::types::b_document.
Definition value.hpp:182
bsoncxx::v1::types::value::view
v1::types::view view() const
Return a view of the underlying BSON type value.
bsoncxx::v1::types::value::value
value(double v)
Initialize as a bsoncxx::v1::types::b_double.
Definition value.hpp:157
bsoncxx::v1::types::value::value
value(std::int32_t v)
Initialize as a bsoncxx::v1::types::b_int32.
Definition value.hpp:147
bsoncxx::v1::types::value::value
value(v1::stdx::string_view code, v1::document::view scope)
Initialize as a bsoncxx::v1::types::b_codewscope.
Definition value.hpp:210
bsoncxx::v1::types::value::make_error_code
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition value.hpp:310
bsoncxx::v1::types::value::value
value(value &&other) noexcept
Move construction.
bsoncxx::v1::types::value::value
value(v1::stdx::string_view v)
Initialize as a bsoncxx::v1::types::b_string.
Definition value.hpp:142
bsoncxx::v1::types::value::value
value(std::uint8_t const *data, std::size_t size)
Initialize as a bsoncxx::v1::types::b_binary with bsoncxx::v1::types::binary_subtype::k_binary.
Definition value.hpp:233
bsoncxx::v1::types::value::value
value(std::string const &v)
Initialize as a bsoncxx::v1::types::b_string.
Definition value.hpp:227
bsoncxx::v1::types::value::value
value(std::chrono::milliseconds v)
Initialize as a bsoncxx::v1::types::b_date.
Definition value.hpp:177
bsoncxx::v1::types::value::error_category
static std::error_category const & error_category()
The error category for bsoncxx::v1::types::value::errc.
bsoncxx::v1::types::value::operator!=
friend bool operator!=(value const &lhs, value const &rhs)
Equivalent to !(lhs == rhs).
Definition value.hpp:289
bsoncxx::v1::types::value::~value
~value()
Destroy this object.
bsoncxx::v1::types::value::value
value(std::vector< std::uint8_t > const &v)
Initialize as a bsoncxx::v1::types::b_binary with bsoncxx::v1::types::binary_subtype::k_binary.
Definition value.hpp:193
bsoncxx::v1::types::value::value
value(v1::array::view v)
Initialize as a bsoncxx::v1::types::b_array.
Definition value.hpp:187
bsoncxx::v1::stdx
Declares C++17 standard library polyfills.
bsoncxx::v1::types
Declares entities representing a BSON type value.
bsoncxx::v1::types::binary_subtype
binary_subtype
Enumeration identifying a BSON binary subtype.
Definition id.hpp:71
bsoncxx::v1::types::id::k_binary
@ k_binary
Binary data.
Definition id.hpp:43
bsoncxx::v1
Declares entities whose ABI stability is guaranteed for documented symbols.
bsoncxx
The top-level namespace within which all bsoncxx library entities are declared.
bsoncxx::v1::types::b_array
BSON type value "Array".
Definition view.hpp:193
bsoncxx::v1::types::b_bool
BSON type value "Boolean".
Definition view.hpp:376
bsoncxx::v1::types::b_codewscope
BSON type value "JavaScript Code With Scope".
Definition view.hpp:694
bsoncxx::v1::types::b_date
BSON type value "UTC Datetime".
Definition view.hpp:422
bsoncxx::v1::types::b_dbpointer
BSON type value "DBPointer".
Definition view.hpp:554
bsoncxx::v1::types::b_decimal128
BSON type value "Decimal128".
Definition view.hpp:874
bsoncxx::v1::types::b_document
BSON type value "Embedded Document".
Definition view.hpp:143
bsoncxx::v1::types::b_double
BSON type value "64-bit Binary Floating Point".
Definition view.hpp:48
bsoncxx::v1::types::b_int32
BSON type value "32-bit Integer".
Definition view.hpp:738
bsoncxx::v1::types::b_int64
BSON type value "64-bit Integer".
Definition view.hpp:828
bsoncxx::v1::types::b_null
BSON type value "Null Value".
Definition view.hpp:479
bsoncxx::v1::types::b_oid
BSON type value "ObjectID".
Definition view.hpp:330
bsoncxx::v1::types::b_regex
BSON type value "Regular Expression".
Definition view.hpp:503
bsoncxx::v1::types::b_string
BSON type value "UTF-8 String".
Definition view.hpp:97
view-fwd.hpp
Declares bsoncxx::v1::array::view.
decimal128-fwd.hpp
Declares bsoncxx::v1::decimal128.
view-fwd.hpp
Declares bsoncxx::v1::document::view.
oid-fwd.hpp
Declares bsoncxx::v1::oid.
string_view.hpp
Provides std::string_view-related polyfills for library API usage.
id-fwd.hpp
Declares enumerations identifying the type of a BSON element.
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-fwd.hpp
Declares bsoncxx::v1::types::value.
view.hpp
Provides non-owning, read-only entities representing a BSON type value.