summaryrefslogtreecommitdiffstats
path: root/utils.cpp
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-10-13 13:51:06 -0700
committerPatrick Venture <venture@google.com>2018-10-17 23:18:55 +0000
commit2e63352fe8893a65e45690402d8681644b572e12 (patch)
tree8c0ca39736b4385dbd0ae6af34981c753425dadf /utils.cpp
parent64678b853377d60b2ff3129d087ad68df8e2bce7 (diff)
downloadphosphor-host-ipmid-2e63352fe8893a65e45690402d8681644b572e12.tar.gz
phosphor-host-ipmid-2e63352fe8893a65e45690402d8681644b572e12.zip
cleanup: transition to find_if
[utils.cpp:81]: (style) Consider using std::find_if algorithm instead of a raw loop. [storageaddsel.cpp:170]: (style) Consider using std::find_if algorithm instead of a raw loop. Change-Id: I7ebbb6428fbbae9196912837d2ac9820420b77df Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'utils.cpp')
-rw-r--r--utils.cpp22
1 files changed, 9 insertions, 13 deletions
diff --git a/utils.cpp b/utils.cpp
index 225b1cc..06c26e8 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -4,6 +4,7 @@
#include <dirent.h>
#include <net/if.h>
+#include <algorithm>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/log.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -74,25 +75,20 @@ DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus,
}
// else search the match string in the object path
- auto objectFound = false;
- for (auto& object : objectTree)
- {
- if (object.first.find(match) != std::string::npos)
- {
- objectFound = true;
- objectInfo = make_pair(object.first,
- std::move(object.second.begin()->first));
- break;
- }
- }
+ auto found = std::find_if(
+ objectTree.begin(), objectTree.end(), [&match](const auto& object) {
+ return (object.first.find(match) != std::string::npos);
+ });
- if (!objectFound)
+ if (found == objectTree.end())
{
log<level::ERR>("Failed to find object which matches",
entry("MATCH=%s", match.c_str()));
elog<InternalFailure>();
+ // elog<> throws an exception.
}
- return objectInfo;
+
+ return make_pair(found->first, std::move(found->second.begin()->first));
}
DbusObjectInfo getIPObject(sdbusplus::bus::bus& bus,
OpenPOWER on IntegriCloud