Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 63.5% 33 / 0 / 52
Functions: 66.7% 4 / 0 / 6
Branches: 23.9% 27 / 0 / 113

OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/SystemOMCFactory.h
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28 #pragma once
29 /** @addtogroup simcorefactoriesPolicies
30 *
31 * @{
32 */
33
34 /*
35 Policy class to create a OMC-, Modelica- system or AlgLoopSolver
36 */
37 template <class CreationPolicy>
38 struct SystemOMCFactory : public ObjectFactory<CreationPolicy>
39 {
40
41 public:
42 40 SystemOMCFactory(PATH library_path,PATH modelicasystem_path,PATH config_path)
43
3/9
✓ Branch 2 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 40 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
160 :ObjectFactory<CreationPolicy>(library_path,modelicasystem_path,config_path)
44 {
45 40 _use_modelica_compiler = false;
46
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 _system_type_map = new type_map();
47 #ifndef RUNTIME_STATIC_LINKING
48
3/9
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 40 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
120 initializeLibraries(library_path, modelicasystem_path, config_path);
49 #endif
50 40 }
51
52 40 virtual ~SystemOMCFactory()
53 {
54 40 delete _system_type_map;
55 40 ObjectFactory<CreationPolicy>::_factory->UnloadAllLibs();
56 80 }
57
58 ✗ virtual shared_ptr<IAlgLoopSolverFactory> createAlgLoopSolverFactory(IGlobalSettings* globalSettings)
59 {
60 std::map<std::string, factory<IAlgLoopSolverFactory,IGlobalSettings*,PATH,PATH> >::iterator iter;
61 ✗ std::map<std::string, factory<IAlgLoopSolverFactory,IGlobalSettings*,PATH,PATH> >& algloopsolver_factory(_system_type_map->get());
62 ✗ iter = algloopsolver_factory.find("AlgLoopSolverFactory");
63 ✗ if (iter ==algloopsolver_factory.end())
64 {
65 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No AlgLoopSolverFactory found");
66 }
67 ✗ shared_ptr<IAlgLoopSolverFactory> algloopsolverfactory = shared_ptr<IAlgLoopSolverFactory>(iter->second.create(globalSettings,ObjectFactory<CreationPolicy>::_library_path,ObjectFactory<CreationPolicy>::_modelicasystem_path));
68
69 ✗ return algloopsolverfactory;
70 }
71
72
73
74
75
76 40 virtual shared_ptr<IMixedSystem> createSystem(string modelLib,string modelKey,IGlobalSettings* globalSettings,shared_ptr<ISimObjects> simObjects)
77 {
78 40 fs::path modelica_path = ObjectFactory<CreationPolicy>::_modelicasystem_path;
79
1/1
✓ Branch 1 taken 40 times.
40 fs::path modelica_name(modelLib);
80
1/1
✓ Branch 1 taken 40 times.
40 modelica_path/=modelica_name;
81
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(modelica_path.string(),*_system_type_map);
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
83 {
84 ✗ std::stringstream tmp;
85 ✗ tmp << "Failed loading System library!" << std::endl << modelica_path.string();
86 ✗ throw ModelicaSimulationError(MODEL_FACTORY,tmp.str());
87 ✗ }
88
89 std::map<std::string, factory<IMixedSystem, IGlobalSettings*, shared_ptr<ISimObjects> > >::iterator system_iter;
90
1/1
✓ Branch 1 taken 40 times.
40 std::map<std::string, factory<IMixedSystem, IGlobalSettings*, shared_ptr<ISimObjects> > >& factories(_system_type_map->get());
91 system_iter = factories.find(modelKey);
92
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (system_iter == factories.end())
93 {
94 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No system found");
95 }
96
97
1/1
✓ Branch 2 taken 40 times.
40 shared_ptr<IMixedSystem> system(system_iter->second.create(globalSettings,simObjects));
98 40 return system;
99 40 }
100
101 ✗ shared_ptr<IMixedSystem> createModelicaSystem(PATH modelica_path, string modelKey, IGlobalSettings* globalSettings, shared_ptr<ISimObjects>)
102 {
103 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Modelica is not supported");
104 }
105
106 protected:
107 40 virtual void initializeLibraries(PATH library_path,PATH modelicasystem_path,PATH config_path)
108 {
109 40 fs::path systemfactory_path = ObjectFactory<CreationPolicy>::_library_path;
110
1/1
✓ Branch 1 taken 40 times.
40 fs::path system_name(SYSTEM_LIB);
111
1/1
✓ Branch 1 taken 40 times.
40 systemfactory_path/=system_name;
112
113
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(systemfactory_path.string(), *_system_type_map);
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
115 {
116 ✗ std::stringstream tmp;
117 ✗ tmp << "Failed loading System library!" << std::endl << systemfactory_path.string();
118 ✗ throw ModelicaSimulationError(MODEL_FACTORY,tmp.str());
119 ✗ }
120
121
1/1
✓ Branch 1 taken 40 times.
40 fs::path dataexchange_path = ObjectFactory<CreationPolicy>::_library_path;
122
1/1
✓ Branch 1 taken 40 times.
40 fs::path dataexchange_name(DATAEXCHANGE_LIB);
123
1/1
✓ Branch 1 taken 40 times.
40 dataexchange_path/=dataexchange_name;
124
125
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(dataexchange_path.string(), *_system_type_map);
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
127 {
128 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading Dataexchange library!");
129 }
130 40 }
131
132 bool _use_modelica_compiler;
133 type_map* _system_type_map;
134 };
135 /** @} */ // end of simcorefactoriesPolicies
136