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;
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>
97auto getDefaultValueForJson(DefaultType defaultValue)
99 return nlohmann::json(defaultValue);
104 typename DefaultType,
106 std::is_enum<DefaultType>::value>* =
nullptr>
109auto getDefaultValueForJson(DefaultType defaultValue)
111 StringView name = mapEnumValueToName<DefaultType>(defaultValue);
112 std::string nameStr{name.data(), name.size()};
113 return nlohmann::json(nameStr);
118 typename DefaultType,
size_t N,
120 std::is_enum<DefaultType>::value>* =
nullptr>
123auto getDefaultValueForJson(
const std::array<DefaultType, N>& defaultValues)
125 std::array<std::string, N> nameStrings;
126 for (
size_t i = 0; i < N; ++i)
128 StringView name = mapEnumValueToName<DefaultType>(defaultValues[i]);
129 std::string nameStr{name.data(), name.size()};
130 nameStrings[i] = nameStr;
132 return nlohmann::json(nameStrings);
141template <
typename DefaultType>
148 dw::core::StringView name,
149 dw::core::StringView typeName,
152 DefaultType defaultValue)
154 , m_defaultValue(defaultValue)
168 void addDefault(nlohmann::ordered_json&
object)
const noexcept override
170 object[
"default"] = detail::getDefaultValueForJson(m_defaultValue);
175 DefaultType m_defaultValue;
189 const std::shared_ptr<const ParameterDescriptor>&
getDescriptor(
size_t const index)
const;
196 size_t getIndex(dw::core::StringView
const& identifier)
const;
203 const std::shared_ptr<const ParameterDescriptor>&
getDescriptor(dw::core::StringView
const& identifier)
const;
209 bool isValid(dw::core::StringView
const& identifier)
const noexcept;
216 void addDescriptor(
const std::shared_ptr<const ParameterDescriptor>& descriptor);
220 typename NodeT,
size_t ConstructorArgumentIndex,
221 typename std::enable_if_t<ConstructorArgumentIndex == std::tuple_size<decltype(describeParameters<NodeT>())>::value,
void>* =
nullptr>
228 typename NodeT,
size_t ConstructorArgumentIndex,
229 typename std::enable_if_t<ConstructorArgumentIndex<std::tuple_size<decltype(describeParameters<NodeT>())>::value,
void>* =
nullptr>
void addDescriptors()
231 auto t = std::get<ConstructorArgumentIndex>(describeParameters<NodeT>());
232 const auto& t2 = std::get<PARAMETER_CONSTRUCTOR_ARGUMENT_DESCRIPTOR>(t);
234 addDescriptors<0>(t2);
236 addDescriptors<NodeT, ConstructorArgumentIndex + 1>();
242 size_t ParameterIndex,
typename ParamsT,
243 typename std::enable_if_t<ParameterIndex == dw::core::tuple_size<ParamsT>::value,
void>* =
nullptr>
244 void addDescriptors(
const ParamsT& params)
246 static_cast<void>(params);
251 size_t ParameterIndex,
typename ParamsT,
252 typename std::enable_if_t<ParameterIndex<dw::core::tuple_size<ParamsT>::value,
void>* =
nullptr>
void addDescriptors(
const ParamsT& params)
254 const auto& p = dw::core::get<ParameterIndex>(params);
256 addDescriptors<ParameterIndex + 1>(params);
263 void addDescriptor(
const ParamT& param)
265 const auto d = std::make_shared<const ParameterDescriptor>(
266 std::get<PARAMETER_NAME>(param),
267 std::get<PARAMETER_TYPE_NAME>(param),
268 std::get<PARAMETER_IS_INDEX>(param),
269 std::get<PARAMETER_ARRAY_SIZE>(param));
276 typename std::enable_if_t<PARAMETER_DEFAULT_VALUE<std::tuple_size<ParamT>::value,
void>* =
nullptr>
void addDescriptor(
const ParamT& param)
278 using DefaultT =
typename std::tuple_element_t<PARAMETER_DEFAULT_VALUE, ParamT>;
279 const auto d = std::make_shared<const ParameterDescriptorWithDefault<DefaultT>>(
280 std::get<PARAMETER_NAME>(param),
281 std::get<PARAMETER_TYPE_NAME>(param),
282 std::get<PARAMETER_IS_INDEX>(param),
283 std::get<PARAMETER_ARRAY_SIZE>(param),
284 std::get<PARAMETER_DEFAULT_VALUE>(param));
289 dw::core::VectorFixed<std::shared_ptr<const ParameterDescriptor>> m_descriptors;
293template <
typename NodeT>
A collection of parameter descriptors.
const std::shared_ptr< const ParameterDescriptor > & getDescriptor(size_t const index) const
Get the parameter descriptor for the passed index.
size_t getSize() const
Get the number of parameter descriptors.
void addDescriptors()
Terminate recursion to add parameter descriptors for each node constructor argument to the collection...
bool isValid(dw::core::StringView const &identifier) const noexcept
Check if the passed parameter name matches a parameter descriptor in the collection.
void addDescriptor(const std::shared_ptr< const ParameterDescriptor > &descriptor)
bool isValid(size_t const index) const
Check if the passed index is valid, which mean is within [0, size()).
const std::shared_ptr< const ParameterDescriptor > & getDescriptor(dw::core::StringView const &identifier) const
ParameterCollectionDescriptor(size_t const capacity)
Constructor.
size_t getIndex(dw::core::StringView const &identifier) const
The description of a parameter with a default value.
auto operator=(ParameterDescriptorWithDefault &&) -> ParameterDescriptorWithDefault &=delete
Move assignment operator.
void addDefault(nlohmann::ordered_json &object) const noexcept override
Add the default value to the passed JSON object.
~ParameterDescriptorWithDefault() override=default
Destructor.
auto operator=(ParameterDescriptorWithDefault const &) -> ParameterDescriptorWithDefault &=delete
Copy assignment operator.
ParameterDescriptorWithDefault(dw::core::StringView name, dw::core::StringView typeName, bool isIndex, size_t arraySize, DefaultType defaultValue)
Constructor.
ParameterDescriptorWithDefault(ParameterDescriptorWithDefault &&)=delete
Move constructor.
ParameterDescriptorWithDefault(ParameterDescriptorWithDefault const &)=delete
Copy constructor.
The description of a parameter.
dw::core::StringView const & getTypeName() const noexcept
Get the C++ type name of the parameter.
ParameterDescriptor & operator=(ParameterDescriptor const &) &=delete
Copy assignment operator.
virtual ~ParameterDescriptor()=default
Destructor.
ParameterDescriptor(dw::core::StringView const &name, dw::core::StringView const &typeName, const bool isIndex, size_t const arraySize) noexcept
Constructor.
ParameterDescriptor(ParameterDescriptor const &)=delete
Copy constructor.
dw::core::StringView const & getName() const noexcept
Get the parameter name, can be empty for unnamed parameters.
virtual void addDefault(nlohmann::ordered_json &object) const noexcept
Add the default value to the passed JSON object (only used by ParameterDescriptorWithDefault()).
ParameterDescriptor(ParameterDescriptor &&)=delete
Move constructor.
ParameterDescriptor & operator=(ParameterDescriptor &&) &=delete
Move assignment operator.
bool isIndex() const noexcept
Check if parameter is an index.
size_t getArraySize() const noexcept
Get the array size, 0 for non-array parameters.
static constexpr size_t PARAMETER_DEFAULT_VALUE
static ParameterCollectionDescriptor createParameterCollectionDescriptor()
Create a parameter collection descriptor for a give node.