MongoDB C++ Driver mongocxx-3.0.0
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/core.hpp>
18#include <bsoncxx/builder/stream/key_context.hpp>
19#include <bsoncxx/builder/stream/single_context.hpp>
20#include <bsoncxx/document/value.hpp>
21#include <bsoncxx/document/view.hpp>
22
23#include <bsoncxx/config/prelude.hpp>
24
25namespace bsoncxx {
26BSONCXX_INLINE_NAMESPACE_BEGIN
27namespace builder {
28namespace stream {
29
34class document : public key_context<> {
35 public:
36
40 BSONCXX_INLINE document() : key_context<>(&_core), _core(false) {
41 }
42
46 BSONCXX_INLINE bsoncxx::document::view view() const {
47 return _core.view_document();
48 }
49
53 BSONCXX_INLINE operator bsoncxx::document::view() const {
54 return view();
55 }
56
67 return _core.extract_document();
68 }
69
73 BSONCXX_INLINE void clear() {
74 _core.clear();
75 }
76
77 private:
78 core _core;
79};
80
81} // namespace stream
82} // namespace builder
83BSONCXX_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
document::view view_document() const
Get a view over the document.
document::value extract_document()
Transfer ownership of the underlying document to the caller.
void clear()
Delete the contents of the underlying BSON datum.
A streaming interface for constructing a BSON document.
Definition document.hpp:34
bsoncxx::document::value extract()
Transfer ownership of the underlying document to the caller.
Definition document.hpp:66
bsoncxx::document::view view() const
Definition document.hpp:46
document()
Default constructor.
Definition document.hpp:40
void clear()
Reset the underlying BSON to an empty document.
Definition document.hpp:73
A stream context which expects a key, which can later be followed by value, then more key/value pairs...
Definition key_context.hpp:48
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:33
A read-only, non-owning view of a BSON document.
Definition view.hpp:33