Skip to content

Commit ed4da21

Browse files
committed
add a new overload of the getVariableOffset function
1 parent a36acd9 commit ed4da21

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

include/MGIS/Behaviour/Variable.hxx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ namespace mgis::behaviour {
119119
*/
120120
MGIS_EXPORT [[nodiscard]] size_type getVariableOffset(
121121
const std::vector<Variable> &, const std::string_view, const Hypothesis);
122+
/*!
123+
* \return the offset of the given variable for the given hypothesis
124+
*
125+
* \param[in] ctx: execution context
126+
* \param[in] vs: variables
127+
* \param[in] n: variable name
128+
* \param[in] h: modelling hypothesis
129+
*/
130+
MGIS_EXPORT [[nodiscard]] std::optional<size_type> getVariableOffset(
131+
Context &,
132+
const std::vector<Variable> &,
133+
const std::string_view,
134+
const Hypothesis) noexcept;
122135
/*!
123136
* \return the type of the given variable as a string
124137
* \param[in] v: variable

src/Variable.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ namespace mgis::behaviour {
364364
raise("getVariableOffset: no variable named '" + std::string(n) + "'");
365365
} // end of getVariableOffset
366366

367+
std::optional<size_type> getVariableOffset(Context &ctx,
368+
const std::vector<Variable> &vs,
369+
const std::string_view n,
370+
const Hypothesis h) noexcept {
371+
auto o = size_type{};
372+
for (const auto &v : vs) {
373+
if (v.name == n) {
374+
return o;
375+
}
376+
o += getVariableSize(v, h);
377+
}
378+
return ctx.registerErrorMessage("getVariableOffset: no variable named '" +
379+
std::string(n) + "'");
380+
} // end of getVariableOffset
381+
367382
std::string getVariableTypeSymbolicRepresentation(const int id) {
368383
auto t = id;
369384
const auto s = internals::getVariableTypeSymbolicRepresentation(t);

0 commit comments

Comments
 (0)