From 6f6364f74a4c454d096b0525bdb7563783ee80b7 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 16 Feb 2017 17:57:56 +0000 Subject: Change way to iter over vector Change-Id: Ic06f1aaafb839d8d06c839b60ec440031bee89ed Signed-off-by: Romain Forlot --- src/can-signals.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/can-signals.cpp') diff --git a/src/can-signals.cpp b/src/can-signals.cpp index 1b0207c7..610a5a8d 100644 --- a/src/can-signals.cpp +++ b/src/can-signals.cpp @@ -29,9 +29,10 @@ std::map ::iterator subscribed_signals_i; /* Find one or many signals based on its name or id * passed through openxc_DynamicField. */ -std:vector find_can_signals(openxc_DynamicField *key) +#define MESSAGE_SET_ID 0 +std::vector find_can_signals(openxc_DynamicField &key) { - std:vector signals; + std::vector signals; int n_signals, i; n_signals = getSignalCount(); @@ -39,33 +40,35 @@ std:vector find_can_signals(openxc_DynamicField *key) switch(key->type): { case openxc_DynamicField_Type::openxc_DynamicField_Type_STRING: - for(i=0; i<=n_signals; i++) + for(const CanSignal& s : SIGNALS[MESSAGE_SET_ID]) { - if(fnmatch(key->string_value, SIGNALS[i]->genericName) == 0) - signals.push_back(&SIGNALS[i]); + if(fnmatch(key->string_value, s.genericName) == 0) + signals.push_back(s); } break; case openxc_DynamicField_Type::openxc_DynamicField_Type_NUM: - for(i=0; i<=n_signals; i++) + for(const CanSignal& s : SIGNALS[MESSAGE_SET_ID]) { - CanMessageDefinition *msg_def = SIGNALS[i]->message; + CanMessageDefinition *msg_def = s.message; if(msg_def->id == key->numeric_value) - signals.push_back(&SIGNALS[i]) + signals.push_back(s) } break; default: - ERROR(interface, "find_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); + ERROR(interface, "find_can_signals: wrong openxc_DynamicField specified. Use openxc_DynamicField_Type_NUM or openxc_DynamicField_Type_STRING type only."); return NULL; break; } + + return signals; } -CanSignal* getSignals() +std::vector& getSignals() { - return &SIGNALS; + return SIGNALS[MESSAGE_SET_ID]; } int getSignalCount() { - return SIGNALS.size(); + return SIGNALS[MESSAGE_SET_ID].size(); } \ No newline at end of file -- cgit 1.2.3-korg