MongoDB C++ Driver 4.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sub_binary.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
18
19//
20
21#include <cstdint>
22
26
28#include <bsoncxx/types.hpp>
29
31
32namespace bsoncxx {
33namespace v_noabi {
34namespace builder {
35namespace basic {
36
41 public:
45 sub_binary(core* core) : _core{core} {}
46
54 std::uint8_t* allocate(binary_sub_type sub_type, std::uint32_t length) {
55 return _core->append(sub_type, length);
56 }
57
66 template <typename Format, typename SFINAE = typename vector::detail::format_traits<Format>::value_type>
67 vector::accessor<Format> allocate(Format fmt, std::size_t element_count) {
68 (void)fmt;
69 std::uint32_t binary_data_length = Format::length_for_append(element_count);
70 std::uint8_t* binary_data = allocate(binary_sub_type::k_vector, binary_data_length);
71 Format::write_frame(binary_data, binary_data_length, element_count);
72 return {vector::detail::accessor_data<Format>(binary_data, binary_data_length)};
73 }
74
75 private:
76 core* _core;
77};
78
79} // namespace basic
80} // namespace builder
81} // namespace v_noabi
82} // namespace bsoncxx
83
85
Declares bsoncxx::v_noabi::vector::accessor.
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
sub_binary(core *core)
Default constructor.
Definition sub_binary.hpp:45
vector::accessor< Format > allocate(Format fmt, std::size_t element_count)
Allocate and format space for a BSON Binary Vector with uninitialized elements.
Definition sub_binary.hpp:67
std::uint8_t * allocate(binary_sub_type sub_type, std::uint32_t length)
Allocate space for an un-initialized BSON Binary element of any subtype.
Definition sub_binary.hpp:54
sub_binary(core *core)
Default constructor.
Definition sub_binary.hpp:45
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:46
Accessor for the contents of a valid BSON Binary Vector.
Definition accessor.hpp:53
Provides bsoncxx::v_noabi::builder::core.
For internal use only!
Declares entities in bsoncxx::v_noabi::vector::formats.
Declares entities used with "basic" BSON builder syntax.
Declares entities used to build BSON documents.
Declares entities whose ABI stability is NOT guaranteed.
binary_sub_type
An enumeration of each BSON binary sub type.
Definition types.hpp:72
@ k_vector
BSON Binary Vector.
Definition types.hpp:82
The top-level namespace within which all bsoncxx library entities are declared.
Declares bsoncxx::v_noabi::builder::basic::sub_binary.
Provides entities used to represent BSON types.