Skip to content

Commit 691ddf3

Browse files
authored
Remove read write from scalar_variable (#108)
1 parent ba5c6d0 commit 691ddf3

File tree

3 files changed

+13
-82
lines changed

3 files changed

+13
-82
lines changed

examples/multiple_fmus.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,19 @@ int main()
3333
slave2->step(1E-4);
3434

3535
double ref;
36-
auto var = md1->get_variable_by_name("MotorDiskRev").as_real();
37-
assert(var.valueReference() == 105);
38-
var.read(*slave1, ref);
39-
std::cout << "MotorDiskRev=" << ref << std::endl;
40-
41-
auto vr = md2->get_value_reference("Temperature_Room");
42-
assert(vr == 47);
43-
slave2->read_real(vr, ref);
44-
std::cout << "Temperature_Room=" << ref << std::endl;
36+
{
37+
auto vr = md1->get_variable_by_name("MotorDiskRev").value_reference;
38+
assert(vr == 105);
39+
slave1->read_real(vr, ref);
40+
std::cout << "MotorDiskRev=" << ref << std::endl;
41+
}
42+
43+
{
44+
auto vr = md2->get_value_reference("Temperature_Room");
45+
assert(vr == 47);
46+
slave2->read_real(vr, ref);
47+
std::cout << "Temperature_Room=" << ref << std::endl;
48+
}
4549

4650
slave1->terminate();
4751
slave2->terminate();

include/fmi4cpp/fmi2/xml/typed_scalar_variable.hpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ class typed_scalar_variable
101101
return attribute_;
102102
}
103103

104-
virtual bool read(fmu_reader& reader, T& ref) = 0;
105-
106-
virtual bool write(fmu_writer& writer, T value) = 0;
107104
};
108105

109106
template<typename T, typename U>
@@ -138,9 +135,6 @@ class integer_variable : public bounded_scalar_variable<int, integer_attribute>
138135
integer_variable(
139136
const scalar_variable& variable,
140137
const integer_attribute& attribute);
141-
142-
bool read(fmu_reader& reader, int& ref) override;
143-
bool write(fmu_writer& writer, int value) override;
144138
};
145139

146140
class real_variable : public bounded_scalar_variable<double, real_attribute>
@@ -159,9 +153,6 @@ class real_variable : public bounded_scalar_variable<double, real_attribute>
159153
[[nodiscard]] std::optional<unsigned int> derivative() const;
160154
[[nodiscard]] std::optional<std::string> unit() const;
161155
[[nodiscard]] std::optional<std::string> displayUnit() const;
162-
163-
bool read(fmu_reader& reader, double& ref) override;
164-
bool write(fmu_writer& writer, double value) override;
165156
};
166157

167158

@@ -172,9 +163,6 @@ class string_variable : public typed_scalar_variable<std::string, string_attribu
172163
string_variable(
173164
const scalar_variable& variable,
174165
const string_attribute& attribute);
175-
176-
bool read(fmu_reader& reader, std::string& ref) override;
177-
bool write(fmu_writer& writer, std::string value) override;
178166
};
179167

180168
class boolean_variable : public typed_scalar_variable<bool, boolean_attribute>
@@ -184,9 +172,6 @@ class boolean_variable : public typed_scalar_variable<bool, boolean_attribute>
184172
boolean_variable(
185173
const scalar_variable& variable,
186174
const boolean_attribute& attribute);
187-
188-
bool read(fmu_reader& reader, bool& ref) override;
189-
bool write(fmu_writer& writer, bool value) override;
190175
};
191176

192177
class enumeration_variable : public typed_scalar_variable<int, enumeration_attribute>
@@ -196,9 +181,6 @@ class enumeration_variable : public typed_scalar_variable<int, enumeration_attri
196181
enumeration_variable(
197182
const scalar_variable& variable,
198183
const enumeration_attribute& attribute);
199-
200-
bool read(fmu_reader& reader, int& ref) override;
201-
bool write(fmu_writer& writer, int value) override;
202184
};
203185

204186

src/fmi4cpp/fmi2/xml/scalar_variable.cpp

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,6 @@ integer_variable::integer_variable(
138138
: bounded_scalar_variable(variable, attribute)
139139
{}
140140

141-
bool integer_variable::read(fmu_reader& reader, int& ref)
142-
{
143-
return reader.read_integer(valueReference(), ref);
144-
}
145-
146-
bool integer_variable::write(fmu_writer& writer, int value)
147-
{
148-
return writer.write_integer(valueReference(), value);
149-
}
150141

151142
real_variable::real_variable(
152143
const scalar_variable& variable,
@@ -189,73 +180,27 @@ bool real_variable::reinit() const
189180
return attribute_.reinit;
190181
}
191182

192-
bool real_variable::read(fmu_reader& reader, double& ref)
193-
{
194-
return reader.read_real(valueReference(), ref);
195-
}
196-
197-
bool real_variable::write(fmu_writer& writer, double value)
198-
{
199-
return writer.write_real(valueReference(), value);
200-
}
201-
202183

203184
string_variable::string_variable(
204185
const scalar_variable& variable,
205186
const string_attribute& attribute)
206187
: typed_scalar_variable(variable, attribute)
207188
{}
208189

209-
bool string_variable::read(fmu_reader& reader, std::string& ref)
210-
{
211-
fmi2String str;
212-
auto status = reader.read_string(valueReference(), str);
213-
ref = str;
214-
return status;
215-
}
216-
217-
bool string_variable::write(fmu_writer& writer, std::string value)
218-
{
219-
return writer.write_string(valueReference(), value.c_str());
220-
}
221-
222190

223191
boolean_variable::boolean_variable(
224192
const scalar_variable& variable,
225193
const boolean_attribute& attribute)
226194
: typed_scalar_variable(variable, attribute)
227195
{}
228196

229-
bool boolean_variable::read(fmu_reader& reader, bool& ref)
230-
{
231-
fmi2Boolean _ref;
232-
auto status = reader.read_boolean(valueReference(), _ref);
233-
ref = _ref != 0;
234-
return status;
235-
}
236-
237-
bool boolean_variable::write(fmu_writer& writer, bool value)
238-
{
239-
return writer.write_boolean(valueReference(), value);
240-
}
241-
242197

243198
enumeration_variable::enumeration_variable(
244199
const scalar_variable& variable,
245200
const enumeration_attribute& attribute)
246201
: typed_scalar_variable(variable, attribute)
247202
{}
248203

249-
bool enumeration_variable::read(fmu_reader& reader, int& ref)
250-
{
251-
return reader.read_integer(valueReference(), ref);
252-
}
253-
254-
bool enumeration_variable::write(fmu_writer& writer, int value)
255-
{
256-
return writer.write_integer(valueReference(), value);
257-
}
258-
259204

260205
integer_attribute::integer_attribute(const bounded_scalar_variable_attribute<int>& attributes)
261206
: bounded_scalar_variable_attribute<int>(attributes)

0 commit comments

Comments
 (0)