Namespace Scine::Core::DerivedModule

namespace DerivedModule

Functions

template<typename MPLMap>
boost::any resolve(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 model

  • model: The model of interface to create

template<typename MPLMap>
bool has(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 for

  • model: 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, typename Predicate, typename Executable>
auto exec_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() if Predicate never matches, otherwise Executable(T) for the first T in Sequence that matches Predicate.

Template Parameters
  • Sequence: a boost::mpl compatible sequence type

  • Predicate: A type with a template<T> bool operator() (T* = 0) const member specifying whether to execute Executable for the type T in Sequence

  • 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 bool identifiersOverlap()
template<typename MPLVector, std::size_t... Inds>
constexpr bool identifierOverlapForwarder(std::index_sequence<Inds...>)