| 642 | } |
| 643 | |
| 644 | boost::optional<unsigned> FanSystemModel_Impl::speedIndex(const FanSystemModelSpeed& t_speed) const { |
| 645 | boost::optional<unsigned> result; |
| 646 | |
| 647 | // We do it with extensibleGroups() (rather than speeds()) and getString to avoid overhead |
| 648 | // of manipulating actual model objects and speed up the routine |
| 649 | auto egs = castVector<WorkspaceExtensibleGroup>(extensibleGroups()); |
| 650 | auto flowFraction = toString(t_speed.flowFraction()); |
| 651 | auto it = std::find_if(egs.begin(), egs.end(), [&](const WorkspaceExtensibleGroup& eg) { |
| 652 | return (eg.getField(OS_Fan_SystemModelExtensibleFields::SpeedFlowFraction).get() == flowFraction); |
| 653 | }); |
| 654 | |
| 655 | // If found, we compute the index by using std::distance between the start of vector and the iterator returned by std::find_if |
| 656 | if (it != egs.end()) { |
| 657 | result = std::distance(egs.begin(), it); |
| 658 | } |
| 659 | |
| 660 | return result; |
| 661 | } |
| 662 | |
| 663 | std::vector<FanSystemModelSpeed> FanSystemModel_Impl::speeds() const { |
| 664 | |