Initial Commit
This commit is contained in:
31
examples/concepts/policies.hpp
Normal file
31
examples/concepts/policies.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <type_traits>
|
||||
|
||||
namespace gridfire::policy {
|
||||
struct ReactionChainPolicy {};
|
||||
struct NetworkPolicy {};
|
||||
}
|
||||
namespace py {
|
||||
template<class T, class BaseT> struct class_ {
|
||||
template<class F> class_& def(const char*, F) { return *this; }
|
||||
};
|
||||
}
|
||||
namespace bindings::detail {
|
||||
template<typename T>
|
||||
concept IsReactionChainPolicy = std::is_base_of_v<gridfire::policy::ReactionChainPolicy, T>;
|
||||
template<typename T>
|
||||
concept IsNetworkPolicy = std::is_base_of_v<gridfire::policy::NetworkPolicy, T>;
|
||||
|
||||
template<IsReactionChainPolicy T, IsReactionChainPolicy BaseT>
|
||||
void registerReactionChainPolicyDefs(py::class_<T, BaseT>& pyClass) {
|
||||
pyClass.def("name", &T::name)
|
||||
.def("hash", [](const T& self) { return self.hash(0); });
|
||||
}
|
||||
|
||||
template<IsNetworkPolicy T, IsNetworkPolicy BaseT>
|
||||
void registerNetworkPolicyDefs(py::class_<T, BaseT> pyClass) {
|
||||
pyClass.def("name", &T::name)
|
||||
.def("construct", [](const T& self) { return self.construct(); });
|
||||
}
|
||||
static_assert(IsNetworkPolicy<gridfire::policy::NetworkPolicy>);
|
||||
}
|
||||
Reference in New Issue
Block a user