OMCompiler/SimulationRuntime/cpp/Core/DataExchange/Writer.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 dataexchange | ||
| 30 | |||
| 31 | * | ||
| 32 | * @{ | ||
| 33 | */ | ||
| 34 | |||
| 35 | /** | ||
| 36 | * Operator class to return value of output variable | ||
| 37 | */ | ||
| 38 | template<typename T> | ||
| 39 | struct WriteOutputVar | ||
| 40 | { | ||
| 41 | /** | ||
| 42 | return value of output variable | ||
| 43 | @param val pointer to output variable | ||
| 44 | @param negate if output variable is a negate alias variable | ||
| 45 | */ | ||
| 46 | const double operator()(const T* val, bool negate) | ||
| 47 | { | ||
| 48 | //if output variable is a negate alias variable, then negate output value | ||
| 49 |
4/8✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3325 times.
✓ Branch 4 taken 3457467 times.
✓ Branch 5 taken 21459814 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 206011 times.
|
25126617 | if(negate) |
| 50 | 3457467 | return -*val; | |
| 51 | else | ||
| 52 | 21669150 | return *val; | |
| 53 | } | ||
| 54 | }; | ||
| 55 | |||
| 56 | /** | ||
| 57 | * specialized bool Operator class to return value of a boolean variable | ||
| 58 | */ | ||
| 59 | template < > | ||
| 60 | struct WriteOutputVar<bool> | ||
| 61 | { | ||
| 62 | /** | ||
| 63 | return value of output variable | ||
| 64 | @param val pointer to output variable | ||
| 65 | @param negate if output variable is a negate alias variable | ||
| 66 | */ | ||
| 67 | const double operator()(const bool* val, bool negate) | ||
| 68 | { | ||
| 69 | //if output variable is a negate alias variable, then negate output value | ||
| 70 |
2/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 30092 times.
✓ Branch 3 taken 531067 times.
|
561159 | if (negate) |
| 71 | 30092 | return !*val; | |
| 72 | else | ||
| 73 | 531067 | return *val; | |
| 74 | } | ||
| 75 | }; | ||
| 76 | |||
| 77 | class Writer | ||
| 78 | { | ||
| 79 | public: | ||
| 80 | 40 | Writer() {} | |
| 81 | |||
| 82 | virtual ~Writer() {} | ||
| 83 | |||
| 84 | virtual void write(const all_vars_time_t& v_list,const neg_all_vars_t& neg_v_list ) = 0; | ||
| 85 | }; | ||
| 86 | /** @} */ // end of dataexchange | ||
| 87 |