userver: userver/formats/bson/bson_builder.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
bson_builder.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/bson/bson_builder.hpp
4/// @brief Internal helpers for inline document build
5
6#include <chrono>
7#include <cstddef>
8#include <string_view>
9
10#include <userver/compiler/select.hpp>
11#include <userver/formats/bson/types.hpp>
12#include <userver/formats/bson/value.hpp>
13#include <userver/utils/fast_pimpl.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace formats::bson::impl {
18
19class MutableBson;
20
21class BsonBuilder {
22 public:
23 BsonBuilder();
24 explicit BsonBuilder(const ValueImpl&);
25 ~BsonBuilder();
26
27 BsonBuilder(const BsonBuilder&);
28 BsonBuilder(BsonBuilder&&) noexcept;
29 BsonBuilder& operator=(const BsonBuilder&);
30 BsonBuilder& operator=(BsonBuilder&&) noexcept;
31
32 BsonBuilder& Append(std::string_view key, std::nullptr_t);
33 BsonBuilder& Append(std::string_view key, bool);
34 BsonBuilder& Append(std::string_view key, int);
35 BsonBuilder& Append(std::string_view key, unsigned int);
36 BsonBuilder& Append(std::string_view key, long);
37 BsonBuilder& Append(std::string_view key, unsigned long);
38 BsonBuilder& Append(std::string_view key, long long);
39 BsonBuilder& Append(std::string_view key, unsigned long long);
40 BsonBuilder& Append(std::string_view key, double);
41 BsonBuilder& Append(std::string_view key, const char*);
42 BsonBuilder& Append(std::string_view key, std::string_view);
43 BsonBuilder& Append(std::string_view key,
44 std::chrono::system_clock::time_point);
45 BsonBuilder& Append(std::string_view key, const Oid&);
46 BsonBuilder& Append(std::string_view key, const Binary&);
47 BsonBuilder& Append(std::string_view key, const Decimal128&);
48 BsonBuilder& Append(std::string_view key, MinKey);
49 BsonBuilder& Append(std::string_view key, MaxKey);
50 BsonBuilder& Append(std::string_view key, const Timestamp&);
51
52 BsonBuilder& Append(std::string_view key, const Value&);
53
54 BsonBuilder& Append(std::string_view key, const bson_t*);
55
56 const bson_t* Get() const;
57 bson_t* Get();
58
59 BsonHolder Extract();
60
61 private:
62 void AppendInto(bson_t*, std::string_view key, const ValueImpl&);
63
64 static constexpr std::size_t kSize = compiler::SelectSize() //
65 .For64Bit(8)
66 .For32Bit(4);
67 static constexpr std::size_t kAlignment = alignof(void*);
68 utils::FastPimpl<MutableBson, kSize, kAlignment, utils::kStrictMatch> bson_;
69};
70
71} // namespace formats::bson::impl
72
73USERVER_NAMESPACE_END