userver: userver/formats/bson/bson_builder.hpp Source File
Loading...
Searching...
No Matches
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 {
22public:
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, std::chrono::system_clock::time_point);
44 BsonBuilder& Append(std::string_view key, const Oid&);
45 BsonBuilder& Append(std::string_view key, const Binary&);
46 BsonBuilder& Append(std::string_view key, const Decimal128&);
47 BsonBuilder& Append(std::string_view key, MinKey);
48 BsonBuilder& Append(std::string_view key, MaxKey);
49 BsonBuilder& Append(std::string_view key, const Timestamp&);
50
51 BsonBuilder& Append(std::string_view key, const Value&);
52
53 BsonBuilder& Append(std::string_view key, const bson_t*);
54
55 const bson_t* Get() const;
56 bson_t* Get();
57
58 BsonHolder Extract();
59
60private:
61 void AppendInto(bson_t*, std::string_view key, const ValueImpl&);
62
63 static constexpr std::size_t kSize = compiler::SelectSize() //
64 .For64Bit(8)
65 .For32Bit(4);
66 static constexpr std::size_t kAlignment = alignof(void*);
67 utils::FastPimpl<MutableBson, kSize, kAlignment, utils::kStrictMatch> bson_;
68};
69
70} // namespace formats::bson::impl
71
72USERVER_NAMESPACE_END