MongoDB C++ Driver 4.4.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
82class view {
83 private:
84 class impl;
85
86 alignas(BSONCXX_PRIVATE_MAX_ALIGN_T) std::array<unsigned char, 32> _storage;
87
88 public:
93
94 // Handled by the nothrow copy constructor.
95 // view(view&& other) noexcept;
96
97 // Handled by the nothrow copy assignment operator.
98 // view& operator=(view&& other) noexcept;
99
103 BSONCXX_ABI_EXPORT_CDECL() view(view const& other) noexcept;
104
108 BSONCXX_ABI_EXPORT_CDECL(view&) operator=(view const& other) noexcept;
109
114
120 explicit BSONCXX_ABI_EXPORT_CDECL() operator bool() const;
121
127 BSONCXX_ABI_EXPORT_CDECL(std::uint8_t const*) raw() const;
128
134 BSONCXX_ABI_EXPORT_CDECL(std::uint32_t) length() const;
135
141 BSONCXX_ABI_EXPORT_CDECL(std::uint32_t) offset() const;
142
148 BSONCXX_ABI_EXPORT_CDECL(std::uint32_t) keylen() const;
149
157
164 BSONCXX_ABI_EXPORT_CDECL(v1::stdx::string_view) key() const;
165
166#pragma push_macro("X")
167#undef X
168#define X(_name, _value) BSONCXX_ABI_EXPORT_CDECL(v1::types::b_##_name) get_##_name() const;
169
182#pragma pop_macro("X")
183
191
199
213
227
236
240 static BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
241
245 friend std::error_code make_error_code(errc v) {
246 return {static_cast<int>(v), error_category()};
247 }
248
249 class internal;
250
251 private:
252 explicit view(impl i);
253};
254
255} // namespace element
256} // namespace v1
257} // namespace bsoncxx
258
259template <>
260struct std::is_error_code_enum<bsoncxx::v1::element::view::errc> : true_type {};
261
263
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:82
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:245
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:231
@ invalid_view
View is invalid.
Definition view.hpp:233
@ zero
Zero.
Definition view.hpp:232
@ invalid_data
Data is invalid.
Definition view.hpp:234
~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:52
A non-owning, read-only union of BSON type values.
Definition view.hpp:979
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.