17 #include <boson/config/prelude.hpp> 21 #include <bsoncxx/builder/basic/document.hpp> 22 #include <bsoncxx/stdx/optional.hpp> 24 #include <boson/bson_archiver.hpp> 25 #include <boson/bson_streambuf.hpp> 28 BOSON_INLINE_NAMESPACE_BEGIN
39 bsoncxx::document::value to_document(
const T& obj) {
40 bsoncxx::stdx::optional<bsoncxx::document::value> doc;
41 bson_ostream bos([&doc](bsoncxx::document::value v) { doc = std::move(v); });
42 BSONOutputArchive archive(bos);
56 bsoncxx::document::value to_dotted_notation_document(
const T& obj) {
57 bsoncxx::stdx::optional<bsoncxx::document::value> doc;
58 bson_ostream bos([&doc](bsoncxx::document::value v) { doc = std::move(v); });
59 BSONOutputArchive archive(bos,
true);
75 T to_obj(bsoncxx::document::view v) {
76 static_assert(std::is_default_constructible<T>::value,
77 "Template type must be default constructible");
96 void to_obj(bsoncxx::document::view v, T& obj) {
111 bsoncxx::stdx::optional<T> to_optional_obj(
112 const bsoncxx::stdx::optional<bsoncxx::document::value>& opt) {
114 T obj = to_obj<T>(opt.value().view());
128 template <
class Iter>
130 :
public std::iterator<std::input_iterator_tag, bsoncxx::document::value> {
143 void operator++(
int) {
148 return _ci == rhs._ci;
152 return _ci != rhs._ci;
155 bsoncxx::document::value operator*() {
156 return to_document(*_ci);
163 BOSON_INLINE_NAMESPACE_END
166 #include <boson/config/postlude.hpp> An iterator that wraps another iterator of serializable objects, and yields BSON document views corre...
Definition: mapping_functions.hpp:129
An istream that uses a BSON document as a buffer.
Definition: bson_streambuf.hpp:166
Definition: bson_archiver.hpp:70