MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
Public Member Functions | List of all members
bsoncxx::builder::core Class Reference

A low-level interface for constructing BSON documents and arrays. More...

#include <core.hpp>

Public Member Functions

 core (bool is_array)
 Constructs an empty BSON datum.
 
void key_view (stdx::string_view key)
 Appends a key passed as a non-owning stdx::string_view.
 
void key_owned (std::string key)
 Appends a key passed as a STL string.
 
void open_document ()
 Opens a sub-document within this BSON datum.
 
void open_array ()
 Opens a sub-array within this BSON datum.
 
void close_document ()
 Closes the current sub-document within this BSON datum.
 
void close_array ()
 Closes the current sub-array within this BSON datum.
 
void concatenate (const document::view &view)
 Appends the keys from a BSON document into this BSON datum.
 
void append (const types::b_double &value)
 Append a BSON double.
 
void append (const types::b_utf8 &value)
 Append a BSON UTF-8 string.
 
void append (const types::b_document &value)
 Append a BSON document.
 
void append (const types::b_array &value)
 Append a BSON array.
 
void append (const types::b_binary &value)
 Append a BSON binary datum.
 
void append (const types::b_undefined &value)
 Append a BSON undefined.
 
void append (const types::b_oid &value)
 Append a BSON ObjectId.
 
void append (const types::b_bool &value)
 Append a BSON boolean.
 
void append (const types::b_date &value)
 Append a BSON date.
 
void append (const types::b_null &value)
 Append a BSON null.
 
void append (const types::b_regex &value)
 Append a BSON regex.
 
void append (const types::b_dbpointer &value)
 Append a BSON DBPointer.
 
void append (const types::b_code &value)
 Append a BSON JavaScript code.
 
void append (const types::b_symbol &value)
 Append a BSON symbol.
 
void append (const types::b_codewscope &value)
 Append a BSON JavaScript code with scope.
 
void append (const types::b_int32 &value)
 Append a BSON 32-bit signed integer.
 
void append (const types::b_timestamp &value)
 Append a BSON replication timestamp.
 
void append (const types::b_int64 &value)
 Append a BSON 64-bit signed integer.
 
void append (const types::b_minkey &value)
 Append a BSON min-key.
 
void append (const types::b_maxkey &value)
 Append a BSON max-key.
 
void append (const types::value &value)
 Append a BSON variant value.
 
void append (std::string str)
 Append a STL string as a BSON UTF-8 string.
 
void append (stdx::string_view str)
 Append a string view as a BSON UTF-8 string.
 
template<typename T >
void append (T *v)
 Append a char* or const char*.
 
void append (bool value)
 Append a native boolean as a BSON boolean.
 
void append (double value)
 Append a native double as a BSON double.
 
void append (std::int32_t value)
 Append a native int32_t as a BSON 32-bit signed integer.
 
void append (std::int64_t value)
 Append a native int64_t as a BSON 64-bit signed integer.
 
void append (const oid &value)
 Append an oid as a BSON ObjectId.
 
void append (document::view view)
 Append the given document view.
 
void append (array::view view)
 Append the given array view.
 
document::view view_document () const
 Get a view over the document.
 
array::view view_array () const
 Get a view over the array.
 
document::value extract_document ()
 Transfer ownership of the underlying document to the caller.
 
array::value extract_array ()
 Transfer ownership of the underlying document to the caller.
 
void clear ()
 Delete the contents of the underlying BSON datum.
 

Detailed Description

A low-level interface for constructing BSON documents and arrays.

Remarks
Generally it is recommended to use the classes in builder::basic or builder::stream instead of using this class directly. However, developers who wish to write their own abstractions may find this class useful.

Constructor & Destructor Documentation

◆ core()

bsoncxx::builder::core::core ( bool  is_array)
explicit

Constructs an empty BSON datum.

Parameters
is_arraytrue if the top-level BSON datum should be an array.

Member Function Documentation

◆ append()

template<typename T >
void bsoncxx::builder::core::append ( T *  v)
inline

Append a char* or const char*.

We disable all other pointer types to prevent the surprising implicit conversion to bool.

◆ clear()

void bsoncxx::builder::core::clear ( )

Delete the contents of the underlying BSON datum.

After calling clear the state of this class will be the same as it was immediately after construction.

◆ concatenate()

void bsoncxx::builder::core::concatenate ( const document::view view)

Appends the keys from a BSON document into this BSON datum.

Note
This can be used with an array::view as well by converting it to a document::view first.

◆ extract_array()

array::value bsoncxx::builder::core::extract_array ( )

Transfer ownership of the underlying document to the caller.

Returns
A document::value with ownership of the document.
Warning
It is undefined behavior to call this method if the underlying BSON datum is not a BSON array.
After calling extract_array() it is illegal to call any methods on this class, unless it is subsequenly moved into.

◆ extract_document()

document::value bsoncxx::builder::core::extract_document ( )

Transfer ownership of the underlying document to the caller.

Returns
A document::value with ownership of the document.
Warning
After calling extract_document() it is illegal to call any methods on this class, unless it is subsequenly moved into.

◆ key_owned()

void bsoncxx::builder::core::key_owned ( std::string  key)

Appends a key passed as a STL string.

Transfers ownership of the key to this class.

Parameters
keyA string key.

◆ key_view()

void bsoncxx::builder::core::key_view ( stdx::string_view  key)

Appends a key passed as a non-owning stdx::string_view.

Remarks
Use key_owned() unless you know what you are doing.
Warning
The caller must ensure that the lifetime of the backing string extends until the next value is appended.
Parameters
keyA null-terminated array of characters.

◆ view_array()

array::view bsoncxx::builder::core::view_array ( ) const

Get a view over the array.

Returns
An array::view of the internal BSON.
Warning
It is undefined behavior to call this method if the underlying BSON datum is not a BSON array.

◆ view_document()

document::view bsoncxx::builder::core::view_document ( ) const

Get a view over the document.

Returns
A document::view of the internal BSON.

The documentation for this class was generated from the following file: