Arguments.h
1/*
2 Copyright (C) 2009-2026 by Marc Duerner
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the:
26 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 Boston, MA 02110-1301 USA
28*/
29
30#ifndef PT_REMOTING_ARGUMENTS_H
31#define PT_REMOTING_ARGUMENTS_H
32
33#include <Pt/Remoting/Api.h>
34#include <Pt/Composer.h>
35#include <Pt/SerializationContext.h>
36#include <cstddef>
37
38namespace Pt {
39
40namespace Remoting {
41
42template <typename T>
43struct Argument
44{
45 T value;
46 BasicComposer<T> composer;
47
48 explicit Argument(SerializationContext* ctx)
49 : composer(ctx)
50 {}
51
52 void begin()
53 {
54 composer.begin(value);
55 }
56};
57
58
59template <typename... Ts>
60class Arguments;
61
62
63template <>
64class Arguments<>
65{
66 public:
67 explicit Arguments(SerializationContext* /*ctx*/)
68 {}
69
70 void begin()
71 {}
72
73 void fill(std::size_t i, Composer** args)
74 {
75 args[i] = 0;
76 }
77};
78
79
80template <typename T, typename... Ts>
81class Arguments<T, Ts...>
82{
83 public:
84 explicit Arguments(SerializationContext* ctx)
85 : _head(ctx)
86 , _tail(ctx)
87 {}
88
89 void begin()
90 {
91 _head.begin();
92 _tail.begin();
93 }
94
95 void fill(std::size_t i, Composer** args)
96 {
97 args[i] = &_head.composer;
98 _tail.fill(i + 1, args);
99 }
100
101 T& head()
102 {
103 return _head.value;
104 }
105
106 const T& head() const
107 {
108 return _head.value;
109 }
110
111 Arguments<Ts...>& tail()
112 {
113 return _tail;
114 }
115
116 const Arguments<Ts...>& tail() const
117 {
118 return _tail;
119 }
120
121 private:
122 Argument<T> _head;
123 Arguments<Ts...> _tail;
124};
125
126
127template <std::size_t I>
128struct At
129{
130 template <typename T, typename... Ts>
131 static auto& get(Arguments<T, Ts...>& args)
132 {
133 return At<I - 1>::get(args.tail());
134 }
135
136 template <typename T, typename... Ts>
137 static const auto& get(const Arguments<T, Ts...>& args)
138 {
139 return At<I - 1>::get(args.tail());
140 }
141};
142
143
144template <>
145struct At<0>
146{
147 template <typename T, typename... Ts>
148 static T& get(Arguments<T, Ts...>& args)
149 {
150 return args.head();
151 }
152
153 template <typename T, typename... Ts>
154 static const T& get(const Arguments<T, Ts...>& args)
155 {
156 return args.head();
157 }
158};
159
160
161template <std::size_t I, typename... Ts>
162auto& get(Arguments<Ts...>& args)
163{
164 return At<I>::get(args);
165}
166
167
168template <std::size_t I, typename... Ts>
169const auto& get(const Arguments<Ts...>& args)
170{
171 return At<I>::get(args);
172}
173
174} // namespace
175
176} // namespace
177
178#endif // include guard
Remote services and clients.
Definition HttpService.h:39
Core module.
Definition Allocator.h:33