File DerivedModule.h¶
Provides helpers for the general implementation of classes deriving from Module.
- Copyright
This code is licensed under the 3-clause BSD license.
Copyright ETH Zurich, Laboratory for Physical Chemistry, Reiher Group.
See LICENSE.txt for details.
-
namespace
Scine
-
namespace
Core
-
namespace
DerivedModule
¶ Functions
-
template<typename
MPLMap
>
boost::anyresolve
(const std::string &interface, const std::string &model)¶ Creates an InterfaceType shared_ptr of a matching model to an interface.
Helper function to implement a derived module’s get function:
// Transforms this: boost::any Derived::get(const std::string& interface, const std::string& model) const { if(interface == Calculator::interface) { if(model == PlusCalculator::model) { return static_cast<Calculator>(std::make_shared<PlusCalculator>()); } if(model == MinusCalculator::model) { return static_cast<Calculator>(std::make_shared<MinusCalculator>()); } ... } if(interface == Printer::interface) { if(model == SlowPrinter::model) { return static_cast<Printer>(std::make_shared<SlowPrinter>()); } if(model == EvenSlowerPrinter::model) { return static_cast<Printer>(std::make_shared<EvenSlowerPrinter>()); } ... } ... throw Core::ClassNotImplementedError(); } // Into this: boost::any Derived::get(const std::string& interface, const std::string& model) const { // NOTE: Same map for has, announceInterfaces, anounceModels using Map = boost::mpl::map< boost::mpl::pair<Calculator, boost::mpl::vector<PlusCalculator, MinusCalculator>>, boost::mpl::pair<Printer, boost::mpl::vector<SlowPrinter, EvenSlowerPrinter>> >; boost::any resolved = DerivedModule::resolve<Map>(interface, model); if(resolved.empty()) { throw Core::ClassNotImplementedError {}; } return resolved; }
- Return
a boost any containing a shared_ptr to the InterfaceType of the matched model, an empty boost::any otherwise.
- Template Parameters
MPLMap
: An mpl::map of InterfaceType -> mpl::vector<ModelType> InterfaceType::interface and ModelType::Model must be valid expressions
- Parameters
interface
: The interface to modelmodel
: The model ofinterface
to create
-
template<typename
MPLMap
>
boolhas
(const std::string &interface, const std::string &model)¶ Checks whether a module has a particular model for a particular interface.
- Return
whether the module has a model for the interface
- Template Parameters
MPLMap
: An mpl::map of InterfaceType -> mpl::vector<ModelType> InterfaceType::interface and ModelType::Model must be valid expressions
- Parameters
interface
: The interface to check formodel
: The model to check for
-
template<typename
MPLMap
>
std::vector<std::string>announceInterfaces
()¶ Announces all interface names.
- Return
A list of all interface names
- Template Parameters
MPLMap
: An mpl::map of InterfaceType -> mpl::vector<ModelType> InterfaceType::interface and ModelType::Model must be valid expressions
-
template<typename
MPLMap
>
std::vector<std::string>announceModels
(const std::string &interface)¶ Announces all model names for a particular interface.
- Return
The list of model names for a particular interface, or an empty list if no models exist for that interface.
- Template Parameters
MPLMap
: An mpl::map of InterfaceType -> mpl::vector<ModelType> InterfaceType::interface and ModelType::Model must be valid expressions
- Parameters
interface
: The interface for which to list model identifiers
-
namespace
detail
¶ Functions
-
bool
caseInsensitiveEqual
(const std::string &a, const std::string &b)¶
-
template<typename
Sequence
, typenamePredicate
, typenameExecutable
>
autoexec_if
(const Predicate &p, const Executable &e, Sequence * = 0)¶ Run-time “iteration” through type list, if predicate matches, call another function, otherwise return its none.
- Return
Executable::none()
ifPredicate
never matches, otherwiseExecutable(T)
for the first T inSequence
that matches Predicate.- Template Parameters
Sequence
: a boost::mpl compatible sequence typePredicate
: A type with a template<T> bool operator() (T* = 0) const member specifying whether to executeExecutable
for the type T inSequence
Executable
: A type fulfilling the following requirements:Has a ResultType typedef
Has a template<T> ResultType operator() (T* = 0) const member which is executed if returns true for a type in
Sequence
Has a static ResultType none() const member returning the base case
-
constexpr bool
strEqual
(const char *a, const char *b)¶
-
template<typename ...
ModelTypes
>
constexpr boolidentifiersOverlap
()¶
-
template<bool
done
= true>
structexec_if_impl
¶
-
template<>
structexec_if_impl
<false>¶
-
struct
MapPairInterfaceIdentifierMatches
¶ Public Functions
-
MapPairInterfaceIdentifierMatches
(std::string id)¶
Public Members
-
std::string
identifier
¶
-
-
struct
ModelTypeIdentifierMatches
¶ Public Functions
-
ModelTypeIdentifierMatches
(std::string id)¶
Public Members
-
std::string
identifier
¶
-
-
template<typename
InterfaceType
>
structCreateInterfacePointer
¶ Public Types
-
template<>
usingInterfaceTypePtr
= std::shared_ptr<InterfaceType>¶
Public Static Functions
-
static ResultType
none
()¶
-
template<>
-
struct
ResolveModel
¶ -
Public Functions
-
ResolveModel
(std::string id)¶
Public Members
-
std::string
identifier
¶
Public Static Functions
-
static ResultType
none
()¶
-
-
struct
MatchFoundExecutor
¶ Public Types
-
using
ResultType
= bool¶
Public Functions
-
template<typename
T
>
ResultTypeoperator()
(T * = 0) const¶
Public Static Functions
-
static ResultType
none
()¶
-
using
-
struct
ModelExists
¶ Public Types
-
using
ResultType
= bool¶
Public Functions
-
ModelExists
(std::string id)¶
-
template<typename
PairType
>
ResultTypeoperator()
(PairType * = 0) const¶
Public Members
-
std::string
identifier
¶
Public Static Functions
-
static ResultType
none
()¶
-
using
-
struct
ListModels
¶ Public Types
-
using
ResultType
= std::vector<std::string>¶
Public Functions
-
template<typename
PairType
>
ResultTypeoperator()
(PairType * = 0) const¶
Public Static Functions
-
static ResultType
none
()¶
-
using
-
bool
-
template<typename
-
namespace
-
namespace