Skip to content

Commit

Permalink
update Factory to allow for chained inheritance (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
baperry2 authored May 15, 2024
1 parent 1bea1bf commit 37cb002
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Source/Factory.H
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ struct Factory
}

//! Class to handle registration of subclass for runtime selection
template <class T>
struct Register : public Base
template <class T, class DeriveFrom = Base>
struct Register : public DeriveFrom
{
friend T;
static bool registered;

static_assert(std::is_base_of_v<Base, DeriveFrom> == true);

static bool add_sub_type()
{
// TODO: Add checks against multiple registration
Expand Down Expand Up @@ -155,9 +157,9 @@ private:
};

template <class Base, class... Args>
template <class T>
bool Factory<Base, Args...>::Register<T>::registered =
Factory<Base, Args...>::Register<T>::add_sub_type();
template <class T, class DeriveFrom>
bool Factory<Base, Args...>::Register<T, DeriveFrom>::registered =
Factory<Base, Args...>::Register<T, DeriveFrom>::add_sub_type();

} // namespace pele::physics
#endif /* FACTORY_H */

0 comments on commit 37cb002

Please sign in to comment.