From 3e9bdee2ed5523ad57b6b0eb631a9f4b07658460 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 27 Dec 2014 16:13:51 +0100 Subject: [PATCH] added bool completeMatch to MessageMap::findAll --- src/lib/ebus/message.cpp | 16 +++++++++++----- src/lib/ebus/message.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/ebus/message.cpp b/src/lib/ebus/message.cpp index 512ad234..ca25113f 100644 --- a/src/lib/ebus/message.cpp +++ b/src/lib/ebus/message.cpp @@ -421,7 +421,7 @@ Message* MessageMap::find(const string& clazz, const string& name, const bool is return NULL; } -deque MessageMap::findAll(const string& clazz, const string& name, const short pb) +deque MessageMap::findAll(const string& clazz, const string& name, const short pb, const bool completeMatch) { deque ret; @@ -432,10 +432,16 @@ deque MessageMap::findAll(const string& clazz, const string& name, con if (it->first[0] == '-') // avoid duplicates: instances stored multiple times have a key starting with "-" continue; Message* message = it->second; - if (checkClass == true && message->getClass() != clazz) - continue; - if (checkName == true && message->getName() != name) - continue; + if (checkClass == true) { + string check = message->getClass(); + if (completeMatch ? (check != clazz) : (check.find(clazz) == check.npos)) + continue; + } + if (checkName == true) { + string check = message->getName(); + if (completeMatch ? (check != name) : (check.find(name) == check.npos)) + continue; + } if (checkPb == true && message->getId()[0] != pb) continue; ret.push_back(message); diff --git a/src/lib/ebus/message.h b/src/lib/ebus/message.h index 9fec78ef..938ca4d0 100644 --- a/src/lib/ebus/message.h +++ b/src/lib/ebus/message.h @@ -326,10 +326,11 @@ public: * @param clazz the device class, or empty for any. * @param name the message name, or empty for any. * @param pb the primary ID byte, or -1 for any. + * @param completeMatch false to also include messages where the class and name matches only a part of the given class and name. * @return the found @a Message instances. * Note: the caller may not free the returned instances. */ - deque findAll(const string& clazz, const string& name, const short pb); + deque findAll(const string& clazz, const string& name, const short pb, const bool completeMatch=true); /** * @brief Find the @a Message instance for the specified master data.