Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 67.1% 47 / 0 / 70
Functions: 80.0% 8 / 1 / 11
Branches: 19.9% 31 / 0 / 156

OMCompiler/SimulationRuntime/cpp/SimCoreFactory/Policies/SimObjectOMCFactory.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 SimObjectOMCFactory : public ObjectFactory<CreationPolicy>
39 {
40
41 public:
42 40 SimObjectOMCFactory(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
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 _simobject_type_map = new type_map();
46 #ifndef RUNTIME_STATIC_LINKING
47
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);
48 #endif
49 40 }
50
51 40 virtual ~SimObjectOMCFactory()
52 {
53 40 delete _simobject_type_map;
54 40 ObjectFactory<CreationPolicy>::_factory->UnloadAllLibs();
55 80 }
56
57 40 virtual shared_ptr<IAlgLoopSolverFactory> createAlgLoopSolverFactory(IGlobalSettings* globalSettings)
58 {
59 std::map<std::string, factory<IAlgLoopSolverFactory,IGlobalSettings*,PATH,PATH> >::iterator iter;
60 40 std::map<std::string, factory<IAlgLoopSolverFactory,IGlobalSettings*,PATH,PATH> >& algloopsolver_factory(_simobject_type_map->get());
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
80 iter = algloopsolver_factory.find("AlgLoopSolverFactory");
62
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (iter ==algloopsolver_factory.end())
63 {
64 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No AlgLoopSolverFactory found");
65 }
66
2/5
✓ Branch 2 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
120 shared_ptr<IAlgLoopSolverFactory> algloopsolverfactory = shared_ptr<IAlgLoopSolverFactory>(iter->second.create(globalSettings,ObjectFactory<CreationPolicy>::_library_path,ObjectFactory<CreationPolicy>::_modelicasystem_path));
67
68 40 return algloopsolverfactory;
69 }
70
71 40 virtual shared_ptr<ISimData> createSimData()
72 {
73 std::map<std::string, factory<ISimData> >::iterator simdata_iter;
74 40 std::map<std::string, factory<ISimData > >& simdata_factory(_simobject_type_map->get());
75
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
80 simdata_iter = simdata_factory.find("SimData");
76
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (simdata_iter == simdata_factory.end())
77 {
78 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No simdata found");
79 }
80 shared_ptr<ISimData> simData(simdata_iter->second.create());
81 40 return simData;
82
83 }
84
85 40 virtual shared_ptr<ISimVars> createSimVars(size_t dim_real,size_t dim_int,size_t dim_bool,size_t dim_string,size_t dim_pre_vars,size_t dim_z,size_t z_i)
86 {
87 std::map<std::string, factory<ISimVars,size_t,size_t,size_t,size_t,size_t,size_t,size_t > >::iterator simvars_iter;
88 40 std::map<std::string, factory<ISimVars,size_t,size_t,size_t,size_t,size_t,size_t,size_t > >& simvars_factory(_simobject_type_map->get());
89
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
80 simvars_iter = simvars_factory.find("SimVars");
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (simvars_iter == simvars_factory.end())
91 {
92 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No simvars found");
93 }
94 shared_ptr<ISimVars> simVars(simvars_iter->second.create(dim_real,dim_int,dim_bool,dim_string,dim_pre_vars,dim_z,z_i));
95 40 return simVars;
96
97 }
98 38 shared_ptr<IHistory> createMatFileWriter(IGlobalSettings* settings,size_t dim)
99 {
100 std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >::iterator writer_iter;
101 38 std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >& writer_factory(_simobject_type_map->get());
102
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
76 writer_iter = writer_factory.find("MatFileWriter");
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
38 if (writer_iter == writer_factory.end())
104 {
105 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No MatfileWriter found");
106 }
107 shared_ptr<IHistory> writer(writer_iter->second.create(*settings,dim));
108 38 return writer;
109
110 }
111 2 shared_ptr<IHistory> createTextFileWriter(IGlobalSettings* settings,size_t dim)
112 {
113 std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >::iterator writer_iter;
114 2 std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >& writer_factory(_simobject_type_map->get());
115
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
4 writer_iter = writer_factory.find("TextFileWriter");
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (writer_iter == writer_factory.end())
117 {
118 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No MatfileWriter found");
119 }
120 shared_ptr<IHistory> writer(writer_iter->second.create(*settings,dim));
121 2 return writer;
122
123 }
124 ✗ shared_ptr<IHistory> createBufferReaderWriter(IGlobalSettings* settings,size_t dim)
125 {
126 std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >::iterator writer_iter;
127 ✗ std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >& writer_factory(_simobject_type_map->get());
128 ✗ writer_iter = writer_factory.find("BufferReaderWriter");
129 ✗ if (writer_iter == writer_factory.end())
130 {
131 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No MatfileWriter found");
132 }
133 shared_ptr<IHistory> writer(writer_iter->second.create(*settings,dim));
134 ✗ return writer;
135
136 }
137 ✗ shared_ptr<IHistory> createDefaultWriter(IGlobalSettings* settings,size_t dim)
138 {
139
140 std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >::iterator writer_iter;
141 ✗ std::map<std::string, factory<IHistory,IGlobalSettings&,size_t > >& writer_factory(_simobject_type_map->get());
142 ✗ writer_iter = writer_factory.find("DefaultWriter");
143 ✗ if (writer_iter == writer_factory.end())
144 {
145 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"No MatfileWriter found");
146 }
147 shared_ptr<IHistory> writer(writer_iter->second.create(*settings,dim));
148 ✗ return writer;
149
150 }
151
152
153 protected:
154 40 virtual void initializeLibraries(PATH library_path,PATH modelicasystem_path,PATH config_path)
155 {
156 40 fs::path systemfactory_path = ObjectFactory<CreationPolicy>::_library_path;
157
1/1
✓ Branch 1 taken 40 times.
40 fs::path system_name(SYSTEM_LIB);
158
1/1
✓ Branch 1 taken 40 times.
40 systemfactory_path/=system_name;
159
160
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 LOADERRESULT result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(systemfactory_path.string(), *_simobject_type_map);
161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
162 {
163 ✗ std::stringstream tmp;
164 ✗ tmp << "Failed loading System library!" << std::endl << systemfactory_path.string();
165 ✗ throw ModelicaSimulationError(MODEL_FACTORY,tmp.str());
166 ✗ }
167
168
1/1
✓ Branch 1 taken 40 times.
40 fs::path dataexchange_path = ObjectFactory<CreationPolicy>::_library_path;
169
1/1
✓ Branch 1 taken 40 times.
40 fs::path dataexchange_name(DATAEXCHANGE_LIB);
170
1/1
✓ Branch 1 taken 40 times.
40 dataexchange_path/=dataexchange_name;
171
172
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
80 result = ObjectFactory<CreationPolicy>::_factory->LoadLibrary(dataexchange_path.string(), *_simobject_type_map);
173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (result != LOADER_SUCCESS)
174 {
175 ✗ throw ModelicaSimulationError(MODEL_FACTORY,"Failed loading Dataexchange library!");
176 }
177 40 }
178
179
180 type_map* _simobject_type_map;
181 };
182 /** @} */ // end of simcorefactoriesPolicies
183