Skip to content
Snippets Groups Projects
Commit ba4f14bc authored by Maxence Naud's avatar Maxence Naud
Browse files

[Fix] add getAttr function for const ref to Operator

parent b0a7acb8
No related branches found
No related tags found
2 merge requests!46Remove Operator reference to Tensor,!20Draft: Introduction of Tiling
Pipeline #33145 passed
......@@ -22,8 +22,8 @@
namespace Aidge {
/**
* @brief This class is designed to handle static attributes (i.e. known at compile-time)
* with named accessors, with minimal overhead (the name strings are not stored in each object
* @brief This class is designed to handle static attributes (i.e. known at compile-time)
* with named accessors, with minimal overhead (the name strings are not stored in each object
* instance and it remains possible to access attribute without overhead at compile-time).
*/
template <class ATTRS_ENUM, class ...T>
......@@ -97,6 +97,17 @@ public:
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute \"%s\" not found", name);
}
template <typename R>
const R& getAttr(const char* name) const {
for (std::size_t i = 0; i < size(EnumStrings<ATTRS_ENUM>::data); ++i) {
if (strcmp(EnumStrings<ATTRS_ENUM>::data[i], name) == 0) {
return getAttr<R>(i);
}
}
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute \"%s\" not found", name);
}
template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
typename std::enable_if<(SIZE > 0), R&>::type getAttr(std::size_t i) {
if (i == SIZE-1) {
......@@ -117,6 +128,26 @@ public:
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute not found");
}
template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
typename std::enable_if<(SIZE > 0), const R&>::type getAttr(std::size_t i) const {
if (i == SIZE-1) {
if (std::is_same<R, typename std::tuple_element<SIZE-1,std::tuple<T...>>::type>::value) {
return reinterpret_cast<const R&>(std::get<SIZE-1>(mAttrs));
}
else {
AIDGE_THROW_OR_ABORT(std::runtime_error, "wrong type for attribute with index %lu", i);
}
}
else {
return getAttr<R, SIZE-1>(i);
}
}
template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
[[noreturn]] typename std::enable_if<(SIZE == 0), const R&>::type getAttr(std::size_t /*i*/) const {
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute not found");
}
template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
constexpr typename std::enable_if<(SIZE > 0), const std::type_info&>::type getAttrType(std::size_t i) const {
if (i == SIZE-1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment