MongoDB C++ Driver mongocxx-3.10.1
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/array-fwd.hpp>
18#include <bsoncxx/builder/basic/document-fwd.hpp>
19
20#include <bsoncxx/builder/basic/impl.hpp>
21#include <bsoncxx/builder/basic/kvp.hpp>
22#include <bsoncxx/builder/basic/sub_document.hpp>
23#include <bsoncxx/builder/core.hpp>
24#include <bsoncxx/document/value.hpp>
25#include <bsoncxx/document/view.hpp>
26
27#include <bsoncxx/config/prelude.hpp>
28
29namespace bsoncxx {
30namespace v_noabi {
31namespace builder {
32namespace basic {
33
38class document : public sub_document {
39 public:
43 BSONCXX_INLINE document() : sub_document(&_core), _core(false) {}
44
48 BSONCXX_INLINE document(document&& doc) noexcept
49 : sub_document(&_core), _core(std::move(doc._core)) {}
50
54 BSONCXX_INLINE document& operator=(document&& doc) noexcept {
55 _core = std::move(doc._core);
56 return *this;
57 }
58
62 BSONCXX_INLINE bsoncxx::v_noabi::document::view view() const {
63 return _core.view_document();
64 }
65
72 BSONCXX_INLINE operator bsoncxx::v_noabi::document::view() const {
73 return view();
74 }
75
86 return _core.extract_document();
87 }
88
92 BSONCXX_INLINE void clear() {
93 _core.clear();
94 }
95
96 private:
97 core _core;
98};
99
110template <typename... Args>
111bsoncxx::v_noabi::document::value BSONCXX_CALL make_document(Args&&... args) {
113 document.append(std::forward<Args>(args)...);
114 return document.extract();
115}
116
117} // namespace basic
118} // namespace builder
119} // namespace v_noabi
120} // namespace bsoncxx
121
122namespace bsoncxx {
123namespace builder {
124namespace basic {
125
126using ::bsoncxx::v_noabi::builder::basic::make_document;
127
128} // namespace basic
129} // namespace builder
130} // namespace bsoncxx
131
132#include <bsoncxx/config/postlude.hpp>
A traditional builder-style interface for constructing a BSON document.
Definition document.hpp:38
bsoncxx::v_noabi::document::value extract()
Transfer ownership of the underlying document to the caller.
Definition document.hpp:85
document(document &&doc) noexcept
Move constructor.
Definition document.hpp:48
document()
Default constructor.
Definition document.hpp:43
bsoncxx::v_noabi::document::view view() const
Definition document.hpp:62
void clear()
Reset the underlying BSON to an empty document.
Definition document.hpp:92
document & operator=(document &&doc) noexcept
Move assignment operator.
Definition document.hpp:54
An internal class of builder::basic.
Definition sub_document.hpp:43
A low-level interface for constructing BSON documents and arrays.
Definition core.hpp:45
void clear()
Deletes the contents of the underlying BSON datum.
bsoncxx::v_noabi::document::value extract_document()
Transfers ownership of the underlying document to the caller.
bsoncxx::v_noabi::document::view view_document() const
Gets a view over the document.
A JSON-like builder for creating documents.
Definition list.hpp:156
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:38
A read-only, non-owning view of a BSON document.
Definition view.hpp:35
The top-level namespace for bsoncxx library entities.
Definition element-fwd.hpp:19