MongoDB C++ Driver current
Loading...
Searching...
No Matches
document.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/impl.hpp>
18#include <bsoncxx/builder/basic/kvp.hpp>
19#include <bsoncxx/builder/basic/sub_document.hpp>
20#include <bsoncxx/builder/core.hpp>
21#include <bsoncxx/document/value.hpp>
22#include <bsoncxx/document/view.hpp>
23
24#include <bsoncxx/config/prelude.hpp>
25
26namespace bsoncxx {
27inline namespace v_noabi {
28namespace builder {
29namespace basic {
30
31class array;
32
37class document : public sub_document {
38 public:
42 BSONCXX_INLINE document() : sub_document(&_core), _core(false) {}
43
47 BSONCXX_INLINE document(document&& doc) noexcept
48 : sub_document(&_core), _core(std::move(doc._core)) {}
49
53 BSONCXX_INLINE document& operator=(document&& doc) noexcept {
54 _core = std::move(doc._core);
55 return *this;
56 }
57
61 BSONCXX_INLINE bsoncxx::document::view view() const {
62 return _core.view_document();
63 }
64
71 BSONCXX_INLINE operator bsoncxx::document::view() const {
72 return view();
73 }
74
84 BSONCXX_INLINE bsoncxx::document::value extract() {
85 return _core.extract_document();
86 }
87
91 BSONCXX_INLINE void clear() {
92 _core.clear();
93 }
94
95 private:
96 core _core;
97};
98
109template <typename... Args>
110bsoncxx::document::value BSONCXX_CALL make_document(Args&&... args) {
112 document.append(std::forward<Args>(args)...);
113
114 return document.extract();
115}
116
117} // namespace basic
118} // namespace builder
119} // namespace v_noabi
120} // namespace bsoncxx
121
122#include <bsoncxx/config/postlude.hpp>
A traditional builder-style interface for constructing a BSON document.
Definition document.hpp:37
bsoncxx::document::value extract()
Transfer ownership of the underlying document to the caller.
Definition document.hpp:84
bsoncxx::document::view view() const
Definition document.hpp:61
document(document &&doc) noexcept
Move constructor.
Definition document.hpp:47
document()
Default constructor.
Definition document.hpp:42
void clear()
Reset the underlying BSON to an empty document.
Definition document.hpp:91
document & operator=(document &&doc) noexcept
Move assignment operator.
Definition document.hpp:53
An internal class of builder::basic.
Definition sub_document.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.
document::value extract_document()
Transfers ownership of the underlying document to the caller.
document::view view_document() const
Gets a view over the document.
A JSON-like builder for creating documents.
Definition list.hpp:142
The top-level namespace for bsoncxx library entities.
Definition element.hpp:24