MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
view.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/v1/element/view-fwd.hpp> // IWYU pragma: export
18
19//
20
22
26
30
31#include <array>
32#include <cstddef>
33#include <cstdint>
34#include <system_error>
35#include <type_traits>
36
37namespace bsoncxx {
38namespace v1 {
39namespace element {
40
84class view {
85 private:
86 class impl;
87
88 alignas(BSONCXX_PRIVATE_MAX_ALIGN_T) std::array<unsigned char, 32> _storage;
89
90 public:
95
96 // Handled by the nothrow copy constructor.
97 // view(view&& other) noexcept;
98
99 // Handled by the nothrow copy assignment operator.
100 // view& operator=(view&& other) noexcept;
101
105 BSONCXX_ABI_EXPORT_CDECL() view(view const& other) noexcept;
106
110 BSONCXX_ABI_EXPORT_CDECL(view&) operator=(view const& other) noexcept;
111
116
122 explicit BSONCXX_ABI_EXPORT_CDECL() operator bool() const;
123
129 BSONCXX_ABI_EXPORT_CDECL(std::uint8_t const*) raw() const;
130
136 BSONCXX_ABI_EXPORT_CDECL(std::uint32_t) length() const;
137
143 BSONCXX_ABI_EXPORT_CDECL(std::uint32_t) offset() const;
144
150 BSONCXX_ABI_EXPORT_CDECL(std::uint32_t) keylen() const;
151
159
166 BSONCXX_ABI_EXPORT_CDECL(v1::stdx::string_view) key() const;
167
168#pragma push_macro("X")
169#undef X
170#define X(_name, _value) BSONCXX_ABI_EXPORT_CDECL(v1::types::b_##_name) get_##_name() const;
171
184#pragma pop_macro("X")
185
193
201
215
229
240
246 static BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
247
253 friend std::error_code make_error_code(errc v) {
254 return {static_cast<int>(v), error_category()};
255 }
256
257 class internal;
258
259 private:
260 explicit view(impl i);
261};
262
263} // namespace element
264} // namespace v1
265} // namespace bsoncxx
266
267template <>
268struct std::is_error_code_enum<bsoncxx::v1::element::view::errc> : true_type {};
269
271
Provides macros to control the set of symbols exported in the ABI.
#define BSONCXX_ABI_EXPORT_CDECL(...)
Equivalent to BSONCXX_ABI_EXPORT with BSONCXX_ABI_CDECL.
Definition export.hpp:52
For internal use only!
The bsoncxx v1 macro guard postlude header.
The bsoncxx v1 macro guard prelude header.
A non-owning, read-only BSON element.
Definition view.hpp:84
v1::types::view type_view() const
Return a view of the underlying BSON type value.
view(view const &other) noexcept
Copy (or move) construction.
std::uint32_t length() const
Return the "length" component of the underlying BSON bytes.
v1::types::value type_value() const
Return a deep copy of the underlying BSON type value.
v1::types::id type_id() const
Return the type.
std::uint32_t keylen() const
Return the "keylen" component of the underlying BSON bytes.
v1::stdx::string_view key() const
Return the key.
std::uint8_t const * raw() const
Return the "raw" component of the underlying BSON bytes.
static std::error_category const & error_category()
The error category for bsoncxx::v1::element::view::errc.
std::uint32_t offset() const
Return the "offset" component of the underlying BSON bytes.
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition view.hpp:253
view()
Initialize as an invalid element without any associated BSON bytes.
v1::element::view operator[](std::uint32_t idx) const
Return the first element within the represented BSON array whose key compares equal to i.
errc
Errors codes which may be returned by bsoncxx::v1::element::view.
Definition view.hpp:235
@ invalid_view
View is invalid.
Definition view.hpp:237
@ zero
Zero.
Definition view.hpp:236
@ invalid_data
Data is invalid.
Definition view.hpp:238
~view()
Destroy this object.
v1::element::view operator[](v1::stdx::string_view key) const
Return the first element within the represented BSON document whose key compares equal to key.
A polyfill for std::string_view.
Definition string_view.hpp:412
A union of BSON type values.
Definition value.hpp:54
A non-owning, read-only union of BSON type values.
Definition view.hpp:1023
Declares entities representing a BSON element.
Declares C++17 standard library polyfills.
Declares entities representing a BSON type value.
Declares entities whose ABI stability is guaranteed for documented symbols.
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v1::element::view.
Provides std::string_view-related polyfills for library API usage.
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::v1::types::value.
Declares non-owning, read-only entities representing a BSON type value.