Skip to content

Commit

Permalink
Added a filtered list for modify_and_get.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhjp01 committed Nov 16, 2024
1 parent 212f007 commit 4ec6c32
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/cosim/slave_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,34 @@ class set_variable_cache
if (!hasRunModifiers_) {
for (const auto& entry : modifiers_) {
const auto ref = entry.first;
if (!filter || filter && (*filter)(ref)) {
auto& arrayIndex = exposedVariables_.at(ref).arrayIndex;
if (arrayIndex < 0) {
arrayIndex = references_.size();
assert(references_.size() == values_.size());
references_.emplace_back(ref);
values_.emplace_back(exposedVariables_.at(ref).lastValue);
}
values_[arrayIndex] = entry.second(values_[arrayIndex], deltaT);
auto& arrayIndex = exposedVariables_.at(ref).arrayIndex;
if (arrayIndex < 0) {
arrayIndex = references_.size();
assert(references_.size() == values_.size());
references_.emplace_back(ref);
values_.emplace_back(exposedVariables_.at(ref).lastValue);
}
values_[arrayIndex] = entry.second(values_[arrayIndex], deltaT);
}
assert(references_.size() == values_.size());
hasRunModifiers_ = true;
}

if (filter) {
references_filtered_.clear();
values_filtered_.clear();

for (int i = 0; i < references_.size(); i++) {
auto& ref = references_.at(i);
if ((*filter)(ref)) {
references_filtered_.push_back(ref);
values_filtered_.push_back(values_.at(i));
}
}

return std::pair(gsl::make_span(references_filtered_), gsl::make_span(values_filtered_));
}

return std::pair(gsl::make_span(references_), gsl::make_span(values_));
}

Expand All @@ -248,6 +262,8 @@ class set_variable_cache
}
references_.clear();
values_.clear();
references_filtered_.clear();
values_filtered_.clear();
hasRunModifiers_ = false;
}

Expand All @@ -273,6 +289,10 @@ class set_variable_cache
// The references and values of the variables that will be set next.
std::vector<value_reference> references_;
boost::container::vector<T> values_;

// Filtered references and values of the values to be set next (if a filter is applied).
std::vector<value_reference> references_filtered_;
boost::container::vector<T> values_filtered_;
};


Expand Down

0 comments on commit 4ec6c32

Please sign in to comment.