31 #ifndef DW_FRAMEWORK_PARAMETERCOLLECTIONDESCRIPTOR_HPP_ 32 #define DW_FRAMEWORK_PARAMETERCOLLECTIONDESCRIPTOR_HPP_ 36 #include <dw/core/container/VectorFixed.hpp> 38 #include <modern-json/json.hpp> 53 dw::core::StringView
const& name,
54 dw::core::StringView
const& typeName,
56 size_t const arraySize) noexcept;
68 dw::core::StringView
const&
getName()
const noexcept;
70 dw::core::StringView
const&
getTypeName()
const noexcept;
76 virtual void addDefault(nlohmann::ordered_json&
object)
const noexcept;
80 dw::core::StringView m_name;
82 dw::core::StringView m_typeName;
96 !std::is_enum<DefaultType>::value>* =
nullptr>
97 auto getDefaultValueForJson(DefaultType defaultValue)
99 return nlohmann::json(defaultValue);
104 typename DefaultType,
106 std::is_enum<DefaultType>::value>* =
nullptr>
107 auto getDefaultValueForJson(DefaultType defaultValue)
109 StringView name = mapEnumValueToName<DefaultType>(defaultValue);
110 std::string nameStr{name.data(), name.size()};
111 return nlohmann::json(nameStr);
116 typename DefaultType,
size_t N,
118 std::is_enum<DefaultType>::value>* =
nullptr>
119 auto getDefaultValueForJson(
const std::array<DefaultType, N>& defaultValues)
121 std::array<std::string, N> nameStrings;
122 for (
size_t i = 0; i < N; ++i)
124 StringView name = mapEnumValueToName<DefaultType>(defaultValues[i]);
125 std::string nameStr{name.data(), name.size()};
126 nameStrings[i] = nameStr;
128 return nlohmann::json(nameStrings);
134 template <
typename DefaultType>
140 dw::core::StringView name,
141 dw::core::StringView typeName,
144 DefaultType defaultValue)
146 , m_defaultValue(defaultValue)
160 void addDefault(nlohmann::ordered_json&
object)
const noexcept
override 162 object[
"default"] = detail::getDefaultValueForJson(m_defaultValue);
167 DefaultType m_defaultValue;
178 size_t getSize()
const;
181 const std::shared_ptr<const ParameterDescriptor>& getDescriptor(
size_t const index)
const;
188 size_t getIndex(dw::core::StringView
const& identifier)
const;
195 const std::shared_ptr<const ParameterDescriptor>& getDescriptor(dw::core::StringView
const& identifier)
const;
198 bool isValid(
size_t const index)
const;
201 bool isValid(dw::core::StringView
const& identifier)
const noexcept;
208 void addDescriptor(
const std::shared_ptr<const ParameterDescriptor>& descriptor);
212 typename NodeT,
size_t ConstructorArgumentIndex,
213 typename std::enable_if_t<ConstructorArgumentIndex == std::tuple_size<decltype(describeParameters<NodeT>())>::value,
void>* =
nullptr>
220 typename NodeT,
size_t ConstructorArgumentIndex,
221 typename std::enable_if_t<ConstructorArgumentIndex<std::tuple_size<decltype(describeParameters<NodeT>())>::value,
void>* =
nullptr>
void addDescriptors()
223 auto t = std::get<ConstructorArgumentIndex>(describeParameters<NodeT>());
224 const auto& t2 = std::get<PARAMETER_CONSTRUCTOR_ARGUMENT_DESCRIPTOR>(t);
226 addDescriptors<0>(t2);
228 addDescriptors<NodeT, ConstructorArgumentIndex + 1>();
234 size_t ParameterIndex,
typename ParamsT,
235 typename std::enable_if_t<ParameterIndex == dw::core::tuple_size<ParamsT>::value,
void>* =
nullptr>
236 void addDescriptors(
const ParamsT& params)
238 static_cast<void>(params);
243 size_t ParameterIndex,
typename ParamsT,
244 typename std::enable_if_t<ParameterIndex<dw::core::tuple_size<ParamsT>::value,
void>* =
nullptr>
void addDescriptors(
const ParamsT& params)
246 const auto& p = dw::core::get<ParameterIndex>(params);
248 addDescriptors<ParameterIndex + 1>(params);
255 void addDescriptor(
const ParamT& param)
257 const auto d = std::make_shared<const ParameterDescriptor>(
258 std::get<PARAMETER_NAME>(param),
259 std::get<PARAMETER_TYPE_NAME>(param),
260 std::get<PARAMETER_IS_INDEX>(param),
261 std::get<PARAMETER_ARRAY_SIZE>(param));
268 typename std::enable_if_t<PARAMETER_DEFAULT_VALUE<std::tuple_size<ParamT>::value,
void>* =
nullptr>
void addDescriptor(
const ParamT& param)
270 using DefaultT =
typename std::tuple_element_t<PARAMETER_DEFAULT_VALUE, ParamT>;
271 const auto d = std::make_shared<const ParameterDescriptorWithDefault<DefaultT>>(
272 std::get<PARAMETER_NAME>(param),
273 std::get<PARAMETER_TYPE_NAME>(param),
274 std::get<PARAMETER_IS_INDEX>(param),
275 std::get<PARAMETER_ARRAY_SIZE>(param),
276 std::get<PARAMETER_DEFAULT_VALUE>(param));
281 dw::core::VectorFixed<std::shared_ptr<const ParameterDescriptor>> m_descriptors;
285 template <
typename NodeT>
296 #endif // DW_FRAMEWORK_PARAMETERCOLLECTIONDESCRIPTOR_HPP_ virtual void addDefault(nlohmann::ordered_json &object) const noexcept
Add the default value to the passed JSON object (only used by ParameterDescriptorWithDefault()).
The description of a parameter.
ParameterDescriptor(dw::core::StringView const &name, dw::core::StringView const &typeName, const bool isIndex, size_t const arraySize) noexcept
Constructor.
ParameterDescriptor & operator=(ParameterDescriptor const &)=delete
Copy assignment operator.
ParameterDescriptorWithDefault(dw::core::StringView name, dw::core::StringView typeName, bool isIndex, size_t arraySize, DefaultType defaultValue)
Constructor.
size_t getArraySize() const noexcept
Get the array size, 0 for non-array parameters.
void addDescriptors()
Terminate recursion to add parameter descriptors for each node constructor argument to the collection...
void addDefault(nlohmann::ordered_json &object) const noexcept override
Add the default value to the passed JSON object.
static ParameterCollectionDescriptor createParameterCollectionDescriptor()
Create a parameter collection descriptor for a give node.
dw::core::StringView const & getName() const noexcept
Get the parameter name, can be empty for unnamed parameters.
bool isIndex() const noexcept
Check if parameter is an index.
A collection of parameter descriptors.
virtual ~ParameterDescriptor()=default
Destructor.
The description of a parameter with a default value.
dw::core::StringView const & getTypeName() const noexcept
Get the C++ type name of the parameter.
static constexpr size_t PARAMETER_DEFAULT_VALUE