File: IsWriter.hpp

package info (click to toggle)
reflect-cpp 0.18.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,524 kB
  • sloc: cpp: 44,484; python: 131; makefile: 30; sh: 3
file content (102 lines) | stat: -rw-r--r-- 4,149 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef RFL_PARSING_ISWRITER_HPP_
#define RFL_PARSING_ISWRITER_HPP_

#include <concepts>
#include <string>
#include <string_view>

#include "../Result.hpp"

namespace rfl {
namespace parsing {

template <class W, class T>
concept IsWriter = requires(W w, T t, std::string_view name,
                            std::string basic_value,
                            typename W::OutputArrayType arr,
                            typename W::OutputObjectType obj,
                            typename W::OutputVarType var, size_t size) {
  /// Sets an empty array as the root element of the document.
  /// Some serialization formats require you to pass the expected size in
  /// advance. If you are not working with such a format, you can ignore the
  /// parameter `size`. Returns the new array for further modification.
  { w.array_as_root(size) } -> std::same_as<typename W::OutputArrayType>;

  /// Sets an empty object as the root element of the document.
  /// Some serialization formats require you to pass the expected size in
  /// advance. If you are not working with such a format, you can ignore the
  /// parameter `size`.
  /// Returns the new object for further modification.
  { w.object_as_root(size) } -> std::same_as<typename W::OutputObjectType>;

  /// Sets a null as the root element of the document. Returns OutputVarType
  /// containing the null value.
  { w.null_as_root() } -> std::same_as<typename W::OutputVarType>;

  /// Sets a basic value (bool, numeric, string) as the root element of the
  /// document. Returns an OutputVarType containing the new value.
  { w.value_as_root(basic_value) } -> std::same_as<typename W::OutputVarType>;

  /// Adds an empty array to an existing array. Returns the new
  /// array for further modification.
  {
    w.add_array_to_array(size, &arr)
    } -> std::same_as<typename W::OutputArrayType>;

  /// Adds an empty object to an existing array. Returns the new
  /// object for further modification.
  {
    w.add_object_to_array(size, &arr)
    } -> std::same_as<typename W::OutputObjectType>;

  /// Adds an empty array to an existing object. The key or name of the field is
  /// signified by `name`. Returns the new array for further modification.
  {
    w.add_array_to_object(name, size, &obj)
    } -> std::same_as<typename W::OutputArrayType>;

  /// Adds an empty object to an existing object. The key or name of the field
  /// is signified by `name`. Returns the new object for further modification.
  {
    w.add_object_to_object(name, size, &obj)
    } -> std::same_as<typename W::OutputObjectType>;

  /// Adds a basic value (bool, numeric, string) to an array. Returns an
  /// OutputVarType containing the new value.
  {
    w.add_value_to_array(basic_value, &arr)
    } -> std::same_as<typename W::OutputVarType>;

  /// Adds a basic value (bool, numeric, string) to an existing object. The key
  /// or name of the field is signified by `name`. Returns an
  /// OutputVarType containing the new value.
  {
    w.add_value_to_object(name, basic_value, &obj)
    } -> std::same_as<typename W::OutputVarType>;

  /// Adds a null value to an array. Returns an
  /// OutputVarType containing the null value.
  { w.add_null_to_array(&arr) } -> std::same_as<typename W::OutputVarType>;

  /// Adds a null value to an existing object. The key
  /// or name of the field is signified by `name`. Returns an
  /// OutputVarType containing the null value.
  {
    w.add_null_to_object(name, &obj)
    } -> std::same_as<typename W::OutputVarType>;

  /// Signifies to the writer that we do not want to add any further elements to
  /// this array. Some serialization formats require this. If you are working
  /// with a serialization format that doesn't, just leave the function empty.
  { w.end_array(&arr) } -> std::same_as<void>;

  /// Signifies to the writer that we do not want to add any further elements to
  /// this object. Some serialization formats require this. If you are working
  /// with a serialization format that doesn't, just leave the function empty.
  { w.end_object(&obj) } -> std::same_as<void>;
};

}  // namespace parsing
}  // namespace rfl

#endif