MongoDB C++ Driver  mongocxx-3.0.1
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 
26 namespace bsoncxx {
27 BSONCXX_INLINE_NAMESPACE_BEGIN
28 namespace builder {
29 namespace basic {
30 
35 class array : public sub_array {
36  public:
40  BSONCXX_INLINE array() : sub_array(&_core), _core(true) {
41  }
42 
46  BSONCXX_INLINE bsoncxx::array::view view() const {
47  return _core.view_array();
48  }
49 
56  BSONCXX_INLINE operator bsoncxx::array::view() const {
57  return view();
58  }
59 
69  BSONCXX_INLINE bsoncxx::array::value extract() {
70  return _core.extract_array();
71  }
72 
76  BSONCXX_INLINE void clear() {
77  _core.clear();
78  }
79 
80  private:
81  core _core;
82 };
83 
84 } // namespace basic
85 } // namespace builder
86 BSONCXX_INLINE_NAMESPACE_END
87 } // namespace bsoncxx
88 
89 #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
A read-only BSON array that owns its underlying buffer.
Definition: value.hpp:34
void clear()
Delete the contents of the underlying BSON datum.
bsoncxx::array::view view() const
Definition: array.hpp:46
bsoncxx::array::value extract()
Transfer ownership of the underlying array to the caller.
Definition: array.hpp:69
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
array::view view_array() const
Get a view over the array.
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:76
array()
Default constructor.
Definition: array.hpp:40
array::value extract_array()
Transfer ownership of the underlying document to the caller.
Definition: element.hpp:24