Skip to content

Commit 01cbe20

Browse files
authored
const paths for registry and support for const variables (#1855)
* const paths for registry * Handle const variables
1 parent 1d106e5 commit 01cbe20

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

include/glaze/net/rest_registry_impl.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace glz
3939
}
4040

4141
template <class T, class RegistryType>
42-
static void register_endpoint(sv path, T& value, RegistryType& reg)
42+
static void register_endpoint(const sv path, T& value, RegistryType& reg)
4343
{
4444
std::string rest_path = convert_to_rest_path(path);
4545

@@ -61,7 +61,7 @@ namespace glz
6161
}
6262

6363
template <class Func, class Result, class RegistryType>
64-
static void register_function_endpoint(sv path, Func& func, RegistryType& reg)
64+
static void register_function_endpoint(const sv path, Func& func, RegistryType& reg)
6565
{
6666
std::string rest_path = convert_to_rest_path(path);
6767

@@ -79,7 +79,7 @@ namespace glz
7979
}
8080

8181
template <class Func, class Params, class RegistryType>
82-
static void register_param_function_endpoint(sv path, Func& func, RegistryType& reg)
82+
static void register_param_function_endpoint(const sv path, Func& func, RegistryType& reg)
8383
{
8484
std::string rest_path = convert_to_rest_path(path);
8585

@@ -107,7 +107,7 @@ namespace glz
107107
}
108108

109109
template <class Obj, class RegistryType>
110-
static void register_object_endpoint(sv path, Obj& obj, RegistryType& reg)
110+
static void register_object_endpoint(const sv path, Obj& obj, RegistryType& reg)
111111
{
112112
std::string rest_path = convert_to_rest_path(path);
113113

@@ -128,7 +128,7 @@ namespace glz
128128
}
129129

130130
template <class Value, class RegistryType>
131-
static void register_value_endpoint(sv path, Value& value, RegistryType& reg)
131+
static void register_value_endpoint(const sv path, Value& value, RegistryType& reg)
132132
{
133133
std::string rest_path = convert_to_rest_path(path);
134134

@@ -150,7 +150,7 @@ namespace glz
150150
}
151151

152152
template <class Var, class RegistryType>
153-
static void register_variable_endpoint(sv path, Var& var, RegistryType& reg)
153+
static void register_variable_endpoint(const sv path, Var& var, RegistryType& reg)
154154
{
155155
std::string rest_path = convert_to_rest_path(path);
156156

@@ -171,7 +171,7 @@ namespace glz
171171
}
172172

173173
template <class T, class F, class Ret, class RegistryType>
174-
static void register_member_function_endpoint(sv path, T& value, F func, RegistryType& reg)
174+
static void register_member_function_endpoint(const sv path, T& value, F func, RegistryType& reg)
175175
{
176176
std::string rest_path = convert_to_rest_path(path);
177177

@@ -189,7 +189,7 @@ namespace glz
189189
}
190190

191191
template <class T, class F, class Input, class Ret, class RegistryType>
192-
static void register_member_function_with_params_endpoint(sv path, T& value, F func, RegistryType& reg)
192+
static void register_member_function_with_params_endpoint(const sv path, T& value, F func, RegistryType& reg)
193193
{
194194
std::string rest_path = convert_to_rest_path(path);
195195

include/glaze/rpc/registry.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ namespace glz
143143
}
144144
else {
145145
// this is a variable and not a function, so we build RPC read/write calls
146-
impl::template register_variable_endpoint<std::remove_cvref_t<Func>>(full_key, func, *this);
146+
// We can't remove const here, because const fields need to be able to be written
147+
impl::template register_variable_endpoint<std::remove_reference_t<Func>>(full_key, func, *this);
147148
}
148149
}
149150
});

include/glaze/rpc/repe/repe_registry_impl.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace glz
2323
struct registry_impl<Opts, REPE>
2424
{
2525
template <class T, class RegistryType>
26-
static void register_endpoint(sv path, T& value, RegistryType& reg)
26+
static void register_endpoint(const sv path, T& value, RegistryType& reg)
2727
{
2828
reg.endpoints[path] = [&value](repe::state&& state) mutable {
2929
if (state.write()) {
@@ -46,7 +46,7 @@ namespace glz
4646
}
4747

4848
template <class Func, class Result, class RegistryType>
49-
static void register_function_endpoint(sv path, Func& func, RegistryType& reg)
49+
static void register_function_endpoint(const sv path, Func& func, RegistryType& reg)
5050
{
5151
if constexpr (std::same_as<Result, void>) {
5252
reg.endpoints[path] = [&func](repe::state&& state) mutable {
@@ -71,7 +71,7 @@ namespace glz
7171
}
7272

7373
template <class Func, class Params, class RegistryType>
74-
static void register_param_function_endpoint(sv path, Func& func, RegistryType& reg)
74+
static void register_param_function_endpoint(const sv path, Func& func, RegistryType& reg)
7575
{
7676
reg.endpoints[path] = [&func](repe::state&& state) mutable {
7777
static thread_local std::decay_t<Params> params{};
@@ -103,7 +103,7 @@ namespace glz
103103
}
104104

105105
template <class Obj, class RegistryType>
106-
static void register_object_endpoint(sv path, Obj& obj, RegistryType& reg)
106+
static void register_object_endpoint(const sv path, Obj& obj, RegistryType& reg)
107107
{
108108
reg.endpoints[path] = [&obj](repe::state&& state) mutable {
109109
if (state.write()) {
@@ -126,7 +126,7 @@ namespace glz
126126
}
127127

128128
template <class Value, class RegistryType>
129-
static void register_value_endpoint(sv path, Value& value, RegistryType& reg)
129+
static void register_value_endpoint(const sv path, Value& value, RegistryType& reg)
130130
{
131131
reg.endpoints[path] = [value](repe::state&& state) mutable {
132132
if (state.write()) {
@@ -150,7 +150,7 @@ namespace glz
150150
}
151151

152152
template <class Var, class RegistryType>
153-
static void register_variable_endpoint(sv path, Var& var, RegistryType& reg)
153+
static void register_variable_endpoint(const sv path, Var& var, RegistryType& reg)
154154
{
155155
reg.endpoints[path] = [&var](repe::state&& state) mutable {
156156
if (state.write()) {
@@ -174,7 +174,7 @@ namespace glz
174174
}
175175

176176
template <class T, class F, class Ret, class RegistryType>
177-
static void register_member_function_endpoint(sv path, T& value, F func, RegistryType& reg)
177+
static void register_member_function_endpoint(const sv path, T& value, F func, RegistryType& reg)
178178
{
179179
reg.endpoints[path] = [&value, func](repe::state&& state) mutable {
180180
if constexpr (std::same_as<Ret, void>) {
@@ -200,7 +200,7 @@ namespace glz
200200
}
201201

202202
template <class T, class F, class Input, class Ret, class RegistryType>
203-
static void register_member_function_with_params_endpoint(sv path, T& value, F func, RegistryType& reg)
203+
static void register_member_function_with_params_endpoint(const sv path, T& value, F func, RegistryType& reg)
204204
{
205205
reg.endpoints[path] = [&value, func](repe::state&& state) mutable {
206206
static thread_local Input input{};

0 commit comments

Comments
 (0)