From 059b689d9fd50913116bda28b378d162f3b508b1 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Thu, 27 May 2021 00:49:05 +0200 Subject: [PATCH] Apply readability-container-size-empty --- fairmq/DeviceRunner.cxx | 4 ++-- fairmq/FairMQChannel.cxx | 8 ++++---- fairmq/FairMQDevice.cxx | 8 ++++---- fairmq/FairMQDevice.h | 2 +- fairmq/FairMQTransportFactory.cxx | 2 +- fairmq/JSONParser.cxx | 2 +- fairmq/ProgOptions.cxx | 6 +++--- fairmq/Properties.h | 2 +- fairmq/SuboptParser.cxx | 2 +- fairmq/plugins/config/Config.cxx | 2 +- fairmq/sdk/DDSTopology.cxx | 2 +- fairmq/sdk/Topology.h | 4 ++-- fairmq/sdk/runDDSCommandUI.cxx | 34 +++++++++++++++---------------- fairmq/shmem/Monitor.cxx | 2 +- fairmq/shmem/Region.h | 2 +- fairmq/shmem/Socket.h | 2 +- fairmq/zeromq/Socket.h | 2 +- 17 files changed, 43 insertions(+), 43 deletions(-) diff --git a/fairmq/DeviceRunner.cxx b/fairmq/DeviceRunner.cxx index ebf91e48..97d43f34 100644 --- a/fairmq/DeviceRunner.cxx +++ b/fairmq/DeviceRunner.cxx @@ -49,7 +49,7 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo string verbosity = config.GetProperty("verbosity"); fair::Logger::SetVerbosity(verbosity); - if (logFile != "") { + if (!logFile.empty()) { fair::Logger::InitFileSink(logFileSeverity, logFile); fair::Logger::SetConsoleSeverity("nolog"); } else { @@ -58,7 +58,7 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo if (envFairMQSeverity) { severity = envFairMQSeverity; } - if (severity != "") { + if (!severity.empty()) { fair::Logger::SetConsoleSeverity(severity); } } diff --git a/fairmq/FairMQChannel.cxx b/fairmq/FairMQChannel.cxx index 71278edf..03524f3c 100644 --- a/fairmq/FairMQChannel.cxx +++ b/fairmq/FairMQChannel.cxx @@ -190,7 +190,7 @@ try { } // validate socket address - if (fAddress == "unspecified" || fAddress == "") { + if (fAddress == "unspecified" || fAddress.empty()) { ss << "INVALID"; LOG(debug) << ss.str(); LOG(debug) << "invalid channel address: '" << fAddress << "'"; @@ -226,7 +226,7 @@ try { } else if (address.compare(0, 6, "ipc://") == 0) { // check if IPC address is not empty string addressString = address.substr(6); - if (addressString == "") { + if (addressString.empty()) { ss << "INVALID"; LOG(debug) << ss.str(); LOG(error) << "invalid channel address: '" << address << "' (empty IPC address?)"; @@ -235,7 +235,7 @@ try { } else if (address.compare(0, 9, "inproc://") == 0) { // check if IPC address is not empty string addressString = address.substr(9); - if (addressString == "") { + if (addressString.empty()) { ss << "INVALID"; LOG(debug) << ss.str(); LOG(error) << "invalid channel address: '" << address << "' (empty inproc address?)"; @@ -244,7 +244,7 @@ try { } else if (address.compare(0, 8, "verbs://") == 0) { // check if IPC address is not empty string addressString = address.substr(8); - if (addressString == "") { + if (addressString.empty()) { ss << "INVALID"; LOG(debug) << ss.str(); LOG(error) << "invalid channel address: '" << address << "' (empty verbs address?)"; diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index 9c6b8550..d6b2d5cd 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -246,7 +246,7 @@ void FairMQDevice::InitWrapper() if (subChannel.fMethod == "bind") { // if binding address is not specified, try getting it from the configured network interface - if (subChannel.fAddress == "unspecified" || subChannel.fAddress == "") { + if (subChannel.fAddress == "unspecified" || subChannel.fAddress.empty()) { // if the configured network interface is default, get its name from the default route try { if (networkInterface == "default") { @@ -381,7 +381,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& chan) if (!(bind && hostPart == "*")) { string portPart = addressString.substr(pos + 1); string resolvedHost = tools::getIpFromHostname(hostPart); - if (resolvedHost == "") { + if (resolvedHost.empty()) { return false; } address.assign("tcp://" + resolvedHost + ":" + portPart); @@ -490,11 +490,11 @@ void FairMQDevice::HandleSingleChannelInput() { bool proceed = true; - if (fMsgInputs.size() > 0) { + if (!fMsgInputs.empty()) { while (!NewStatePending() && proceed) { proceed = HandleMsgInput(fInputChannelKeys.at(0), fMsgInputs.begin()->second, 0); } - } else if (fMultipartInputs.size() > 0) { + } else if (!fMultipartInputs.empty()) { while (!NewStatePending() && proceed) { proceed = HandleMultipartInput(fInputChannelKeys.at(0), fMultipartInputs.begin()->second, 0); } diff --git a/fairmq/FairMQDevice.h b/fairmq/FairMQDevice.h index fa9c5912..6e6e205a 100644 --- a/fairmq/FairMQDevice.h +++ b/fairmq/FairMQDevice.h @@ -324,7 +324,7 @@ class FairMQDevice void PrintRegisteredChannels() { - if (fChannelRegistry.size() < 1) { + if (fChannelRegistry.empty()) { LOGV(info, verylow) << "no channels registered."; } else { for (const auto& c : fChannelRegistry) { diff --git a/fairmq/FairMQTransportFactory.cxx b/fairmq/FairMQTransportFactory.cxx index 073a894b..97a21027 100644 --- a/fairmq/FairMQTransportFactory.cxx +++ b/fairmq/FairMQTransportFactory.cxx @@ -35,7 +35,7 @@ auto FairMQTransportFactory::CreateTransportFactory(const string& type, auto finalId = id; // Generate uuid if empty - if (finalId == "") { + if (finalId.empty()) { finalId = fair::mq::tools::Uuid(); } diff --git a/fairmq/JSONParser.cxx b/fairmq/JSONParser.cxx index 5c945d25..94e42e07 100644 --- a/fairmq/JSONParser.cxx +++ b/fairmq/JSONParser.cxx @@ -35,7 +35,7 @@ namespace fair::mq fair::mq::Properties PtreeParser(const ptree& pt, const string& id) { - if (id == "") { + if (id.empty()) { throw ParserError("no device ID provided. Provide with `--id` cmd option"); } diff --git a/fairmq/ProgOptions.cxx b/fairmq/ProgOptions.cxx index 0c907e6c..31fd3b59 100644 --- a/fairmq/ProgOptions.cxx +++ b/fairmq/ProgOptions.cxx @@ -242,7 +242,7 @@ Properties ProgOptions::GetProperties(const string& q) const } } - if (properties.size() == 0) { + if (properties.empty()) { LOG(warn) << "could not find anything with \"" << q << "\""; } @@ -277,7 +277,7 @@ map ProgOptions::GetPropertiesAsString(const string& q) const } } - if (properties.size() == 0) { + if (properties.empty()) { LOG(warn) << "could not find anything with \"" << q << "\""; } @@ -439,7 +439,7 @@ void ProgOptions::PrintOptionsRaw() const replace(description.begin(), description.end(), '\n', ' '); - cout << o->long_name() << ":" << value.value << ":" << (value.type == "" ? "" : value.type) << ":" << description << endl; + cout << o->long_name() << ":" << value.value << ":" << (value.type.empty() ? "" : value.type) << ":" << description << endl; } } diff --git a/fairmq/Properties.h b/fairmq/Properties.h index b2b6b802..db3b069e 100644 --- a/fairmq/Properties.h +++ b/fairmq/Properties.h @@ -37,7 +37,7 @@ class PropertyHelper template static void AddType(std::string label = "") { - if (label == "") { + if (label.empty()) { label = boost::core::demangle(typeid(T).name()); } fTypeInfos[std::type_index(typeid(T))] = [label](const Property& p) { diff --git a/fairmq/SuboptParser.cxx b/fairmq/SuboptParser.cxx index 959b8541..ff47ee7d 100644 --- a/fairmq/SuboptParser.cxx +++ b/fairmq/SuboptParser.cxx @@ -109,7 +109,7 @@ Properties SuboptParser(const vector& channelConfig, const string& devic } } - if (channelName != "") { + if (!channelName.empty()) { channelProperties.add_child("sockets", socketsArray); } else { // TODO: what is the error policy here, should we abort? diff --git a/fairmq/plugins/config/Config.cxx b/fairmq/plugins/config/Config.cxx index df681d76..a09a571a 100644 --- a/fairmq/plugins/config/Config.cxx +++ b/fairmq/plugins/config/Config.cxx @@ -31,7 +31,7 @@ Config::Config(const string& name, const Plugin::Version version, const string& idForParser = GetProperty("id"); } - if (idForParser != "") { + if (!idForParser.empty()) { try { if (PropertyExists("mq-config")) { LOG(debug) << "mq-config: Using default JSON parser"; diff --git a/fairmq/sdk/DDSTopology.cxx b/fairmq/sdk/DDSTopology.cxx index 09adfd9f..c62e6050 100644 --- a/fairmq/sdk/DDSTopology.cxx +++ b/fairmq/sdk/DDSTopology.cxx @@ -67,7 +67,7 @@ auto DDSTopology::GetTasks(const std::string& path /* = "" */) const -> std::vec std::vector list; dds::topology_api::STopoRuntimeTask::FilterIteratorPair_t itPair; - if (path == "") { + if (path.empty()) { itPair = fImpl->fTopo.getRuntimeTaskIterator(nullptr); // passing nullptr will get all tasks } else { itPair = fImpl->fTopo.getRuntimeTaskIteratorMatchingPath(path); diff --git a/fairmq/sdk/Topology.h b/fairmq/sdk/Topology.h index 234f9d7f..f55ff21a 100644 --- a/fairmq/sdk/Topology.h +++ b/fairmq/sdk/Topology.h @@ -1066,7 +1066,7 @@ class BasicTopology : public AsioBase { if (!fOp.IsCompleted() && fCount == fExpectedCount) { fTimer.cancel(); - if (fResult.failed.size() > 0) { + if (!fResult.failed.empty()) { fOp.Complete(MakeErrorCode(ErrorCode::DeviceGetPropertiesFailed), std::move(fResult)); } else { fOp.Complete(std::move(fResult)); @@ -1221,7 +1221,7 @@ class BasicTopology : public AsioBase { if (!fOp.IsCompleted() && fCount == fExpectedCount) { fTimer.cancel(); - if (fFailedDevices.size() > 0) { + if (!fFailedDevices.empty()) { fOp.Complete(MakeErrorCode(ErrorCode::DeviceSetPropertiesFailed), fFailedDevices); } else { fOp.Complete(fFailedDevices); diff --git a/fairmq/sdk/runDDSCommandUI.cxx b/fairmq/sdk/runDDSCommandUI.cxx index f0d3dffb..006e2387 100644 --- a/fairmq/sdk/runDDSCommandUI.cxx +++ b/fairmq/sdk/runDDSCommandUI.cxx @@ -76,7 +76,7 @@ void handleCommand(const string& command, const string& path, unsigned int timeo } return; } else if (command == "o") { - cout << "> dumping config of " << (path == "" ? "all" : path) << endl; + cout << "> dumping config of " << (path.empty() ? "all" : path) << endl; // TODO: extend this regex to return all properties, once command size limitation is removed. auto const result = topo.GetProperties("^(session|id)$", path, std::chrono::milliseconds(timeout)); if (result.first != std::error_code()) { @@ -90,12 +90,12 @@ void handleCommand(const string& command, const string& path, unsigned int timeo } return; } else if (command == "p") { - if (pKey == "" || pVal == "") { + if (pKey.empty() || pVal.empty()) { cout << "cannot send property with empty key and/or value! given key: '" << pKey << "', value: '" << pVal << "'." << endl; throw runtime_error(tools::ToString("cannot send property with empty key and/or value! given key: '", pKey, "', value: '", pVal, "'.")); } const DeviceProperties props{{pKey, pVal}}; - cout << "> setting properties --> " << (path == "" ? "all" : path) << endl; + cout << "> setting properties --> " << (path.empty() ? "all" : path) << endl; auto const result = topo.SetProperties(props, path); if (result.first != std::error_code()) { cout << "ERROR: SetProperties failed for '" << path << "': " << result.first.message() << endl; @@ -105,34 +105,34 @@ void handleCommand(const string& command, const string& path, unsigned int timeo this_thread::sleep_for(chrono::milliseconds(100)); return; } else if (command == "i") { - cout << "> initiating InitDevice transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating InitDevice transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::InitDevice, path, std::chrono::milliseconds(timeout)); } else if (command == "k") { - cout << "> initiating CompleteInit transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating CompleteInit transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::CompleteInit, path, std::chrono::milliseconds(timeout)); } else if (command == "b") { - cout << "> initiating Bind transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating Bind transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::Bind, path, std::chrono::milliseconds(timeout)); } else if (command == "x") { - cout << "> initiating Connect transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating Connect transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::Connect, path, std::chrono::milliseconds(timeout)); } else if (command == "j") { - cout << "> initiating InitTask transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating InitTask transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::InitTask, path, std::chrono::milliseconds(timeout)); } else if (command == "r") { - cout << "> initiating Run transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating Run transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::Run, path, std::chrono::milliseconds(timeout)); } else if (command == "s") { - cout << "> initiating Stop transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating Stop transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::Stop, path, std::chrono::milliseconds(timeout)); } else if (command == "t") { - cout << "> initiating ResetTask transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating ResetTask transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::ResetTask, path, std::chrono::milliseconds(timeout)); } else if (command == "d") { - cout << "> initiating ResetDevice transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating ResetDevice transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::ResetDevice, path, std::chrono::milliseconds(timeout)); } else if (command == "q") { - cout << "> initiating End transition --> " << (path == "" ? "all" : path) << endl; + cout << "> initiating End transition --> " << (path.empty() ? "all" : path) << endl; changeStateResult = topo.ChangeState(TopologyTransition::End, path, std::chrono::milliseconds(timeout)); } else if (command == "h") { cout << "> help" << endl; @@ -151,7 +151,7 @@ void handleCommand(const string& command, const string& path, unsigned int timeo void sendCommand(const string& commandIn, const string& path, unsigned int timeout, Topology& topo, const string& pKey, const string& pVal) { - if (commandIn != "") { + if (!commandIn.empty()) { handleCommand(commandIn, path, timeout, topo, pKey, pVal); return; } @@ -232,12 +232,12 @@ try { Topology topo(ddsTopo, session, true); - if (targetState != "") { - if (command != "") { + if (!targetState.empty()) { + if (!command.empty()) { sendCommand(command, path, timeout, topo, pKey, pVal); } size_t pos = targetState.find("->"); - cout << "> waiting for " << (path == "" ? "all" : path) << " to reach " << targetState << endl; + cout << "> waiting for " << (path.empty() ? "all" : path) << " to reach " << targetState << endl; if (pos == string::npos) { /* auto ec = */topo.WaitForState(GetState(targetState), path, std::chrono::milliseconds(timeout)); // cout << "WaitForState(" << targetState << ") result: " << ec.message() << endl; diff --git a/fairmq/shmem/Monitor.cxx b/fairmq/shmem/Monitor.cxx index 12d8b6d0..f9efdc81 100644 --- a/fairmq/shmem/Monitor.cxx +++ b/fairmq/shmem/Monitor.cxx @@ -575,7 +575,7 @@ std::vector> Monitor::Cleanup(const ShmId& shmId, b if (verbose) { LOG(info) << "Found RegionInfo with path: '" << path << "', flags: " << flags << ", fDestroyed: " << ri.fDestroyed << "."; } - if (path != "") { + if (!path.empty()) { result.emplace_back(RunRemoval(Monitor::RemoveFileMapping, path + "fmq_" + shmId.shmId + "_rg_" + to_string(i), verbose)); } else { result.emplace_back(RunRemoval(Monitor::RemoveObject, "fmq_" + shmId.shmId + "_rg_" + to_string(i), verbose)); diff --git a/fairmq/shmem/Region.h b/fairmq/shmem/Region.h index d4972926..32b1cf9b 100644 --- a/fairmq/shmem/Region.h +++ b/fairmq/shmem/Region.h @@ -59,7 +59,7 @@ struct Region { using namespace boost::interprocess; - if (path != "") { + if (!path.empty()) { fName = std::string(path + fName); if (!fRemote) { diff --git a/fairmq/shmem/Socket.h b/fairmq/shmem/Socket.h index 228836be..53297fa0 100644 --- a/fairmq/shmem/Socket.h +++ b/fairmq/shmem/Socket.h @@ -469,7 +469,7 @@ class Socket final : public fair::mq::Socket static int GetConstant(const std::string& constant) { - if (constant == "") return 0; + if (constant.empty()) return 0; if (constant == "sub") return ZMQ_SUB; if (constant == "pub") return ZMQ_PUB; if (constant == "xsub") return ZMQ_XSUB; diff --git a/fairmq/zeromq/Socket.h b/fairmq/zeromq/Socket.h index 10bc30cd..2e0e4a90 100644 --- a/fairmq/zeromq/Socket.h +++ b/fairmq/zeromq/Socket.h @@ -421,7 +421,7 @@ class Socket final : public fair::mq::Socket static int GetConstant(const std::string& constant) { - if (constant == "") return 0; + if (constant.empty()) return 0; if (constant == "sub") return ZMQ_SUB; if (constant == "pub") return ZMQ_PUB; if (constant == "xsub") return ZMQ_XSUB;