MongoDB C++ Driver  mongocxx-3.4.0
sub_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/builder/basic/helpers.hpp>
18 #include <bsoncxx/builder/concatenate.hpp>
19 #include <bsoncxx/builder/core.hpp>
20 
21 #include <bsoncxx/config/prelude.hpp>
22 
23 namespace bsoncxx {
24 BSONCXX_INLINE_NAMESPACE_BEGIN
25 namespace builder {
26 namespace basic {
27 
28 namespace impl {
29 
30 template <typename T>
31 void value_append(core* core, T&& t);
32 
33 } // namespace impl
34 
39 class sub_array {
40  public:
44  BSONCXX_INLINE sub_array(core* core) : _core(core) {}
45 
49  template <typename Arg, typename... Args>
50  BSONCXX_INLINE void append(Arg&& a, Args&&... args) {
51  append_(std::forward<Arg>(a));
52  append(std::forward<Args>(args)...);
53  }
54 
58  BSONCXX_INLINE
59  void append() {}
60 
61  private:
62  //
63  // Appends a BSON value.
64  //
65  template <typename T>
66  BSONCXX_INLINE void append_(T&& t) {
67  impl::value_append(_core, std::forward<T>(t));
68  }
69 
70  //
71  // Concatenates another bson array directly.
72  //
73  BSONCXX_INLINE
74  void append_(concatenate_array array) {
75  _core->concatenate(array.view());
76  }
77 
78  core* _core;
79 };
80 
81 } // namespace basic
82 } // namespace builder
83 BSONCXX_INLINE_NAMESPACE_END
84 } // namespace bsoncxx
85 
86 #include <bsoncxx/config/postlude.hpp>
A low-level interface for constructing BSON documents and arrays.
Definition: core.hpp:42
An internal class of builder::basic.
Definition: sub_array.hpp:39
sub_array(core *core)
Default constructor.
Definition: sub_array.hpp:44
void append(Arg &&a, Args &&... args)
Appends multiple BSON values.
Definition: sub_array.hpp:50
void append()
Inductive base-case for the variadic append(...)
Definition: sub_array.hpp:59
array::view view() const
Accessor that provides a view of the wrapped concatenate array.
Definition: concatenate.hpp:85
A traditional builder-style interface for constructing a BSON array.
Definition: array.hpp:35
Container to concatenate an array.
Definition: concatenate.hpp:62
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24