View on GitHub
jbson
C++11/1y BSON library
Public Member Functions | List of all members
jbson::builder Struct Reference

builder provides a simple interface for document construction. More...

#include <builder.hpp>

Public Member Functions

 builder ()=default
 Default constructor. More...
 
template<typename Arg1 , typename... ArgN>
 builder (Arg1 &&arg, ArgN &&...args)
 Constructor which forwards to emplace. More...
 
template<typename... Args>
builderemplace (Args &&...args)&
 Constructs a BSON element in place with the supplied args. More...
 
template<typename... Args>
builder && emplace (Args &&...args)&&
 Rvalue overload. Forwards *this as an rvalue reference. Constructs a BSON element in place with the supplied args. More...
 
template<typename Container , typename EContainer >
 operator basic_document< Container, EContainer > () const &
 Implicit conversion to basic_document. More...
 
template<typename Container , typename EContainer >
 operator basic_document< Container, EContainer > ()&&
 Implicit move-conversion to basic_document. More...
 
template<typename... Args>
builderoperator() (Args &&...args)&
 Forwards to emplace. More...
 
template<typename... Args>
builder && operator() (Args &&...args)&&
 Rvalue overload. Forwards *this as an rvalue reference. Constructs a BSON element in place with the supplied args. More...
 

Detailed Description

builder provides a simple interface for document construction.

builder uses basic_element::write_to_container() to construct elements directly to a container, in an easier manner than by doing so manually. builder is implicitly convertible to a basic_document. After conversion, it is still a valid builder object and can be expanded and/or converted again.

builder can also be used on rvalues, propagating itself as an rvalue reference (builder&&) rather than an lvalue reference (builder&). This means that rvalue builders can be implicitly move converted to a document (basic_document<std::vector<char>>), without an explicit cast or std::move(). This is generally only beneficial in this case.

Example of implicit move conversion: To create the JSON object: { "abc": "some string", "def": 123, "xyz": {} }

auto doc = (document)builder("abc", "some string")
("def", 123);
("xyz", builder());
// equivalent to:
auto build = builder("abc", "some string")
("def", 123);
("xyz", builder());
auto doc = document(std::move(build));
See also
array_builder

Definition at line 44 of file builder.hpp.

Constructor & Destructor Documentation

jbson::builder::builder ( )
default

Default constructor.

A default constructed builder can be converted to a valid, empty basic_document.

Exceptions
somethingif vector constructor throws
template<typename Arg1 , typename... ArgN>
jbson::builder::builder ( Arg1 &&  arg,
ArgN &&...  args 
)
inlineexplicit

Constructor which forwards to emplace.

Equivalent to builder().emplace(arg, args...).

See also
emplace()
Exceptions
somethingif vector constructor throws
invalid_element_typeWhen supplied/deduced element_type is invalid.
incompatible_type_conversionWhen data is supplied to a void element_type. When data is not supplied to a non-void element_type.

Definition at line 66 of file builder.hpp.

Member Function Documentation

template<typename... Args>
builder& jbson::builder::emplace ( Args &&...  args)
inline

Constructs a BSON element in place with the supplied args.

Warning
Strong exception guarantee.
See also
basic_element::write_to_container()
Exceptions
somethingif vector constructor throws
invalid_element_typeWhen supplied/deduced element_type is invalid.
incompatible_type_conversionWhen data is supplied to a void element_type. When data is not supplied to a non-void element_type.

Definition at line 98 of file builder.hpp.

template<typename... Args>
builder&& jbson::builder::emplace ( Args &&...  args)
inline

Rvalue overload. Forwards *this as an rvalue reference. Constructs a BSON element in place with the supplied args.

Warning
Strong exception guarantee.
See also
basic_element::write_to_container()
Exceptions
somethingif vector constructor throws
invalid_element_typeWhen supplied/deduced element_type is invalid.
incompatible_type_conversionWhen data is supplied to a void element_type. When data is not supplied to a non-void element_type.

Definition at line 144 of file builder.hpp.

template<typename Container , typename EContainer >
jbson::builder::operator basic_document< Container, EContainer > ( ) const
inline

Implicit conversion to basic_document.

Constructs a basic_document with copy of internal storage.

Definition at line 153 of file builder.hpp.

template<typename Container , typename EContainer >
jbson::builder::operator basic_document< Container, EContainer > ( )
inline

Implicit move-conversion to basic_document.

Constructs a basic_document with the internal storage.

Definition at line 170 of file builder.hpp.

template<typename... Args>
builder& jbson::builder::operator() ( Args &&...  args)
inline

Forwards to emplace.

See also
emplace()
Exceptions
somethingif vector constructor throws
invalid_element_typeWhen supplied/deduced element_type is invalid.
incompatible_type_conversionWhen data is supplied to a void element_type. When data is not supplied to a non-void element_type.

Definition at line 81 of file builder.hpp.

template<typename... Args>
builder&& jbson::builder::operator() ( Args &&...  args)
inline

Rvalue overload. Forwards *this as an rvalue reference. Constructs a BSON element in place with the supplied args.

Warning
Strong exception guarantee.
See also
basic_element::write_to_container()
Exceptions
somethingif vector constructor throws
invalid_element_typeWhen supplied/deduced element_type is invalid.
incompatible_type_conversionWhen data is supplied to a void element_type. When data is not supplied to a non-void element_type.

Definition at line 127 of file builder.hpp.


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