Skip to content
Snippets Groups Projects

Unified interface for attributes

Merged Olivier BICHLER requested to merge unified_params into main
4 files
+ 95
10
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -18,6 +18,7 @@
#include <typeinfo>
#include "aidge/utils/Attributes.hpp"
#include "aidge/utils/Utils.hpp"
namespace Aidge {
/**
@@ -93,7 +94,7 @@ public:
}
}
assert(false && "attribute not found");
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>
@@ -103,7 +104,7 @@ public:
return reinterpret_cast<R&>(std::get<SIZE-1>(mAttrs));
}
else {
assert(false && "wrong attribute type");
AIDGE_THROW_OR_ABORT(std::runtime_error, "wrong type for attribute with index %lu", i);
}
}
else {
@@ -113,7 +114,7 @@ public:
template <typename R, std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
[[noreturn]] constexpr typename std::enable_if<(SIZE == 0), R&>::type getAttr(std::size_t /*i*/) {
assert(false && "attribute not found");
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute not found");
}
template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
@@ -127,10 +128,8 @@ public:
}
template <std::size_t SIZE = std::tuple_size<std::tuple<T...>>::value>
/*[[noreturn]]*/ constexpr typename std::enable_if<(SIZE == 0), const std::type_info&>::type getAttrType(std::size_t /*i*/) const {
assert(false && "attribute not found");
return typeid(void); // avoid MSVC error C4716: "must return a value", despite [[noreturn]] attribute
// [[noreturn]] attribute is removed otherwise GCC complains because there is a return.
[[noreturn]] constexpr typename std::enable_if<(SIZE == 0), const std::type_info&>::type getAttrType(std::size_t /*i*/) const {
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute not found");
}
constexpr const std::tuple<T...>& getStaticAttributes() const {
@@ -159,7 +158,7 @@ public:
}
}
assert(false && "attribute not found");
AIDGE_THROW_OR_ABORT(std::runtime_error, "attribute \"%s\" not found", name.c_str());
}
std::set<std::string> getAttrsName() const override final {
@@ -179,7 +178,8 @@ public:
return py::detail::accessor_policies::tuple_item::get(py::cast(mAttrs), static_cast<py::size_t>(i));
}
}
throw py::value_error("Attribute : " + name + " does not exist." );
AIDGE_THROW_OR_ABORT(py::value_error, "attribute \"%s\" not found", name.c_str());
};
#endif
Loading