diff --git a/README.md b/README.md index 3fe15e1..296c465 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,12 @@ ThingSetUserFunction<0x410, 0x0, int, std::string &> xStringLength(getStringLeng ``` Note that, by default, parameters' IDs will be generated by incrementing the function -ID. It is possible to override this. +ID. It is possible to override this. Parameter names will be generated from a combination of the +function name, parameter type and parameter index. This too can be overridden: + +```c++ +ThingSetNamedUserFunction<0x470, 0x0, "xNamed", ThingSetParameterNames<"uAlpha", "uBeta">, int, uint16_t, float> xNamed([](uint16_t, float) { return 0; }); +``` Once you have declared your properties and functions, instantiate a server with an appropriate transport to expose them to clients. diff --git a/include/thingset++/ThingSetFunction.hpp b/include/thingset++/ThingSetFunction.hpp index b635b71..a990d9d 100644 --- a/include/thingset++/ThingSetFunction.hpp +++ b/include/thingset++/ThingSetFunction.hpp @@ -49,13 +49,27 @@ struct ThingSetParameterNames { static constexpr size_t count = sizeof...(Names); - template + template static constexpr auto get() { return std::get(std::tuple{ Names... }); } }; +/// @brief Empty specialisation of ThingSetParameterNames for the +/// default case which auto-generates parameter names. +template <> +struct ThingSetParameterNames<> +{ + static constexpr size_t count = 0; + + template + static constexpr auto get() + { + return Name + ThingSetType>::name + "_" + to_string_t<1 + Index>(); + } +}; + /// @brief Represents an executable function. /// @tparam Id The unique integer ID of the ThingSet node. /// @tparam ParentId The integer ID of the parent node. @@ -66,11 +80,9 @@ struct ThingSetParameterNames /// @tparam Result The return type of the function. /// @tparam ...Args The argument types of the function, if any. template + requires (ParamNames::count == 0 || ParamNames::count == sizeof...(Args)) class ThingSetFunction : public IdentifiableThingSetParentNode, public ThingSetInvocable { - static_assert(ParamNames::count == 0 || ParamNames::count == sizeof...(Args), - "ThingSetParameterNames must either be empty or name every argument"); - private: template class ThingSetFunctionParameter : public IdentifiableThingSetNode @@ -108,12 +120,7 @@ class ThingSetFunction : public IdentifiableThingSetParentNode(); - } - else { - return Name + ThingSetType>::name + "_" + to_string_t<1 + Index>(); - } + return ParamNames::template get(); } typedef ThingSetFunctionParameter type;