File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments