Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 7 / 0 / 7
Functions: 100.0% 1 / 0 / 1
Branches: 50.0% 2 / 0 / 4

OMCompiler/SimulationRuntime/cpp/Core/Utils/extension/convenience.hpp
Line Branch Exec Source
1 /*
2 * Boost.Extension / convenience functions:
3 * for now only one to load a library and register it in the factory
4 * map.
5 *
6 * (C) Copyright Jeremy Pack 2008
7 * Distributed under the Boost Software License, Version 1.0. (See
8 * accompanying file LICENSE_1_0.txt or copy at
9 * http://www.boost.org/LICENSE_1_0.txt)
10 *
11 * See http://www.boost.org/ for latest version.
12 */
13
14 #ifndef BOOST_EXTENSION_CONVENIENCE_HPP
15 #define BOOST_EXTENSION_CONVENIENCE_HPP
16
17 #include <Core/Utils/extension/factory_map.hpp>
18 #include <Core/Utils/extension/type_map.hpp>
19
20 namespace boost {
21 namespace extensions {
22 /** \brief Load factories from the given library and function.
23 *
24 * Add any exported factories from the given library with the
25 * given function name. This uses shared_library::get internally.
26 * The function must have the signature void (factory_map&).
27 * For more general loading of shared libraries, use the shared_library
28 * class directly.
29 * If the function is not found, false is returned.
30 *
31 * \param current_factory_map The factory map to load classes into. It is
32 * not required to be empty.
33 * \param library_path The relative or absolute path to the library to load.
34 * \param external_function_name The name of an exported function in the library
35 * with the signature void (factory_map&).
36 * \return True on success.
37 * \pre None.
38 * \post None.
39 */
40 inline bool load_single_library(factory_map& current_factory_map,
41 const std::string& library_path,
42 const std::string& external_function_name) {
43 shared_library lib(library_path);
44 if (!lib.open()) {
45 return false;
46 }
47 void (*func)(factory_map&) =
48 lib.shared_library::get<void, factory_map &>(external_function_name);
49 if (!func) {
50 return false;
51 }
52 (*func)(current_factory_map);
53 return true;
54 }
55
56 inline bool load_single_library(factory_map& current_factory_map,
57 const std::string& library_path,
58 const std::string& external_function_name,
59 shared_library& lib) {
60 lib = shared_library(library_path);
61 if (!lib.open()) {
62 return false;
63 }
64 void (*func)(factory_map&) =
65 lib.shared_library::get<void, factory_map &>(external_function_name);
66 if (!func) {
67 return false;
68 }
69 (*func)(current_factory_map);
70 return true;
71 }
72
73
74 558 inline bool load_single_library(type_map& current_type_map,
75 const std::string& library_path,
76 shared_library& lib
77 ) {
78 558 lib = shared_library(library_path);
79
1/2
✓ Branch 1 taken 558 times.
✗ Branch 2 not taken.
558 if (!lib.open()) {
80 return false;
81 }
82 void (*func)(type_map&) =
83 lib.shared_library::get<void, type_map&>
84 558 ("boost_extension_exported_type_map_function");
85
1/2
✓ Branch 0 taken 558 times.
✗ Branch 1 not taken.
558 if (!func) {
86 return false;
87 }
88 558 (*func)(current_type_map);
89
90 558 return true;
91 }
92 } // namespace extensions
93 } // namespace boost
94
95
96
97 #endif
98