userver: userver/formats/json/impl/types.hpp Source File
Loading...
Searching...
No Matches
types.hpp
1#pragma once
2
3#include <memory>
4#include <type_traits>
5
6#include <userver/formats/common/type.hpp>
7
8// copypasted from rapidjson/fwd.h
9namespace rapidjson {
10template <typename CharType>
11struct UTF8;
12class CrtAllocator;
13template <typename Encoding, typename Allocator>
14class GenericValue;
15template <typename Encoding, typename Allocator, typename StackAllocator>
16class GenericDocument;
17} // namespace rapidjson
18
19USERVER_NAMESPACE_BEGIN
20
21namespace formats::json {
22
23using formats::common::Type;
24
25class Value;
26
27namespace impl {
28// rapidjson integration
29using UTF8 = ::rapidjson::UTF8<char>;
30using Value = ::rapidjson::GenericValue<UTF8, ::rapidjson::CrtAllocator>;
31using Document = ::rapidjson::GenericDocument<UTF8, ::rapidjson::CrtAllocator,
32 ::rapidjson::CrtAllocator>;
33
34class VersionedValuePtr final {
35 public:
36 static constexpr size_t kInvalidVersion = -1;
37
38 VersionedValuePtr() noexcept;
39
40 template <typename... Args>
41 static VersionedValuePtr Create(Args&&... args);
42
43 VersionedValuePtr(const VersionedValuePtr&) = default;
44 VersionedValuePtr(VersionedValuePtr&&) = default;
45 VersionedValuePtr& operator=(const VersionedValuePtr&) = default;
46 VersionedValuePtr& operator=(VersionedValuePtr&&) noexcept = default;
47
48 ~VersionedValuePtr();
49
50 explicit operator bool() const;
51 bool IsUnique() const;
52
53 const impl::Value* Get() const;
54 impl::Value* Get();
55
56 const impl::Value& operator*() const;
57 impl::Value& operator*();
58 const impl::Value* operator->() const;
59 impl::Value* operator->();
60
61 size_t Version() const;
62 void BumpVersion();
63
64 private:
65 struct Data;
66
67 explicit VersionedValuePtr(std::shared_ptr<Data>&&) noexcept;
68
69 std::shared_ptr<Data> data_;
70};
71
72} // namespace impl
73} // namespace formats::json
74
75USERVER_NAMESPACE_END