22 static _consteval
auto name() {
return "/set"; }
23 static _consteval
auto usage() {
return "component-name endpoint-name [value] [value] [...]"; }
24 static _consteval
auto description() {
return "Change the current value of the given endoint"; }
27 requires std::integral<T>
28 T from_chars(
const char * start,
const char * end,
bool& success)
31 auto [ptr, ec] = std::from_chars(start, end, ret);
32 if (ec == std::errc{}) success =
true;
38 requires std::floating_point<T>
39 T from_chars(
const char * start,
const char * end,
bool& success)
44 if constexpr (std::is_same_v<T, float>)
45 ret = std::strtof(start, &e);
46 else if constexpr (std::is_same_v<T, double>)
47 ret = std::strtod(start, &e);
48 else if constexpr (std::is_same_v<T, long double>)
49 ret = std::strtold(start, &e);
50 if (start == e) success =
false;
55 auto [ptr, ec] = std::from_chars(start, end, ret);
56 if (ec == std::errc{}) success =
true;
62 requires requires (T t,
const char * s) {t = s;}
63 T from_chars(
const char * start,
const char *,
bool& success)
70 int parse_and_set(
auto& log,
auto& endpoint,
const char * argstart)
72 auto argend = argstart;
75 for (
int i = 0; *argend != 0 && i < 256; ++i, ++argend) {}
78 log.println(
"Unable to parse number, couldn't find end of token");
82 T val = from_chars<T>(argstart, argend, success);
90 log.println(
"Unable to parse token '", argstart,
"'");
94 int parse_and_set(
auto& log,
auto& endpoint,
int argc,
char ** argv)
96 for (
int i = 0; i < argc; ++i)
98 using T =
decltype(value_of(endpoint)[0]);
99 auto ret = parse_and_set<std::remove_cvref_t<T>>(log, value_of(endpoint)[i], argv[i]);
100 if (ret != 0)
return ret;
106 int set_endpoint_value(
auto& log, T& endpoint,
int argc,
char ** argv)
110 if (argc != 0) log.println(
"Note: no arguments are required to set a bang.");
111 set_value(endpoint,
true);
116 if (argc < size<value_t<T>>())
118 log.println(
"Not enough arguments to set this endpoint.");
121 else return parse_and_set(log, endpoint, argc, argv);
127 log.println(
"Not enough arguments to set this endpoint.");
130 else return parse_and_set<value_t<T>>(log, endpoint, argv[0]);
135 template<
typename Components>
136 int main(
int argc,
char** argv,
auto& log, Components& components)
140 log.println(
"usage: ", usage());
143 for_each_endpoint(components, [&]<
typename T>(T& endpoint) {
145 set_endpoint_value(log, endpoint, argc-2, argv+2);
bool osc_match_pattern(const char *pattern, const char *address)
Match an OSC address pattern against the given address.
Definition sygbp-osc_match_pattern.cpp:12