MongoDB C++ Driver current
Loading...
Searching...
No Matches
array.hpp
1// Copyright 2014 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/array/value.hpp>
18#include <bsoncxx/array/view.hpp>
19#include <bsoncxx/builder/basic/impl.hpp>
20#include <bsoncxx/builder/basic/kvp.hpp>
21#include <bsoncxx/builder/basic/sub_array.hpp>
22#include <bsoncxx/builder/core.hpp>
23
24#include <bsoncxx/config/prelude.hpp>
25
26namespace bsoncxx {
27inline namespace v_noabi {
28namespace builder {
29namespace basic {
30
35class array : public sub_array {
36 public:
40 BSONCXX_INLINE array() : sub_array(&_core), _core(true) {}
41
45 BSONCXX_INLINE array(array&& arr) noexcept : sub_array(&_core), _core(std::move(arr._core)) {}
46
50 BSONCXX_INLINE array& operator=(array&& arr) noexcept {
51 _core = std::move(arr._core);
52 return *this;
53 }
54
58 BSONCXX_INLINE bsoncxx::array::view view() const {
59 return _core.view_array();
60 }
61
68 BSONCXX_INLINE operator bsoncxx::array::view() const {
69 return view();
70 }
71
81 BSONCXX_INLINE bsoncxx::array::value extract() {
82 return _core.extract_array();
83 }
84
88 BSONCXX_INLINE void clear() {
89 _core.clear();
90 }
91
92 private:
93 core _core;
94};
95
106template <typename... Args>
107bsoncxx::array::value BSONCXX_CALL make_array(Args&&... args) {
109 array.append(std::forward<Args>(args)...);
110
111 return array.extract();
112}
113
114} // namespace basic
115} // namespace builder
116} // namespace v_noabi
117} // namespace bsoncxx
118
119#include <bsoncxx/config/postlude.hpp>
A JSON-like builder for creating arrays.
Definition list.hpp:166
A traditional builder-style interface for constructing a BSON array.
Definition array.hpp:35
void clear()
Reset the underlying BSON to an empty array.
Definition array.hpp:88
bsoncxx::array::value extract()
Transfer ownership of the underlying array to the caller.
Definition array.hpp:81
array(array &&arr) noexcept
Move constructor.
Definition array.hpp:45
bsoncxx::array::view view() const
Definition array.hpp:58
array()
Default constructor.
Definition array.hpp:40
array & operator=(array &&arr) noexcept
Move assignment operator.
Definition array.hpp:50
An internal class of builder::basic.
Definition sub_array.hpp:39
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:43
void clear()
Deletes the contents of the underlying BSON datum.
array::view view_array() const
Gets a view over the array.
array::value extract_array()
Transfers ownership of the underlying document to the caller.
The top-level namespace for bsoncxx library entities.
Definition element.hpp:24