MongoDB C++ Driver  mongocxx-3.7.0
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
25 namespace bsoncxx {
26 BSONCXX_INLINE_NAMESPACE_BEGIN
27 namespace builder {
28 namespace stream {
29 
38 class document : public key_context<> {
39  public:
43  BSONCXX_INLINE document() : key_context<>(&_core), _core(false) {}
44 
48  BSONCXX_INLINE bsoncxx::document::view view() const {
49  return _core.view_document();
50  }
51 
55  BSONCXX_INLINE operator bsoncxx::document::view() const {
56  return view();
57  }
58 
68  BSONCXX_INLINE bsoncxx::document::value extract() {
69  return _core.extract_document();
70  }
71 
75  BSONCXX_INLINE void clear() {
76  _core.clear();
77  }
78 
79  private:
80  core _core;
81 };
82 
83 } // namespace stream
84 } // namespace builder
85 BSONCXX_INLINE_NAMESPACE_END
86 } // namespace bsoncxx
87 
88 #include <bsoncxx/config/postlude.hpp>
bsoncxx::builder::core::extract_document
document::value extract_document()
Transfers ownership of the underlying document to the caller.
bsoncxx::builder::stream::document
A streaming interface for constructing a BSON document.
Definition: document.hpp:38
bsoncxx::builder::core::clear
void clear()
Deletes the contents of the underlying BSON datum.
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
bsoncxx::builder::stream::document::view
bsoncxx::document::view view() const
Definition: document.hpp:48
bsoncxx::builder::stream::document::extract
bsoncxx::document::value extract()
Transfer ownership of the underlying document to the caller.
Definition: document.hpp:68
bsoncxx::builder::stream::document::clear
void clear()
Reset the underlying BSON to an empty document.
Definition: document.hpp:75
bsoncxx::document::value
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:34
bsoncxx::builder::core::view_document
document::view view_document() const
Gets a view over the document.
bsoncxx::builder::core
A low-level interface for constructing BSON documents and arrays.
Definition: core.hpp:42
bsoncxx::builder::stream::document::document
document()
Default constructor.
Definition: document.hpp:43
bsoncxx::builder::stream::key_context
A stream context which expects a key, which can later be followed by value, then more key/value pairs...
Definition: array_context.hpp:32
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33