Scine::Core  3.0.0
Module management and core interface definitions
 All Classes Files Functions Variables Typedefs Pages
SampleModule.h
Go to the documentation of this file.
1 
16 #ifndef SAMPLE_MODULE_H
17 #define SAMPLE_MODULE_H
18 
19 #include <Core/Module.h>
20 #include <boost/dll/alias.hpp>
21 #include <memory>
22 
23 namespace sample_namespace {
24 
29  public:
30  std::string name() const noexcept final;
31 
32  boost::any get(const std::string& interface, const std::string& model) const final;
33 
34  bool has(const std::string& interface, const std::string& model) const noexcept final;
35 
36  std::vector<std::string> announceInterfaces() const noexcept final;
37 
38  std::vector<std::string> announceModels(const std::string& interface) const noexcept final;
39 
40  static std::shared_ptr<Scine::Core::Module> make();
41 };
42 
43 // Shared library entry point creating pointers to all contained modules
44 std::vector<std::shared_ptr<Scine::Core::Module>> moduleFactory();
45 
46 } // namespace sample_namespace
47 
48 #ifdef __MINGW32__
49 /* MinGW builds are problematic. We build with default visibility, and adding
50  * an attribute __dllexport__ specifically for this singular symbol leads to the
51  * loss of all other weak symbols. Essentially, here we have just expanded the
52  * BOOST_DLL_ALIAS macro in order to declare the type-erased const void*
53  * 'moduleFactory' without any symbol visibility attribute additions that could
54  * confuse the MinGW linker, which per Boost DLL documentation is unable to mix
55  * weak attributes and __dllexport__ correctly.
56  *
57  * If ever the default visibility for this translation unit is changed, we
58  * will have to revisit this bit of code for the MinGW platform again.
59  *
60  * Additionally, more recent Boost releases may have fixed this problem.
61  * See the macro BOOST_DLL_FORCE_ALIAS_INSTANTIATIONS as used in the library's
62  * example files.
63  */
64 extern "C" {
65 const void* moduleFactory = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(&sample_namespace::moduleFactory));
66 }
67 #else
68 BOOST_DLL_ALIAS(sample_namespace::moduleFactory, moduleFactory);
69 #endif
70 
71 #endif /* SAMPLE_MODULE */
std::vector< std::string > announceInterfaces() const noexceptfinal
Announces all interfaces of which the module provides at least one model.
Definition: SampleModule.cpp:80
bool has(const std::string &interface, const std::string &model) const noexceptfinal
Checks if this module supplies a particular model of an interface.
Definition: SampleModule.cpp:76
Abstract base class for a module, which flexibly provides consumers with common interface derived cla...
Definition: Module.h:68
std::string name() const noexceptfinal
Creates a type-erased wrapper around a shared_ptr to a model of a interface.
Definition: SampleModule.cpp:61
Your module class definition.
Definition: SampleModule.h:28
std::vector< std::string > announceModels(const std::string &interface) const noexceptfinal
Definition: SampleModule.cpp:84