Apply readability-container-size-empty

This commit is contained in:
Alexey Rybalchenko 2021-05-27 00:49:05 +02:00 committed by Dennis Klein
parent f25cca2073
commit c847a7ca02
17 changed files with 43 additions and 43 deletions

View File

@ -49,7 +49,7 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo
string verbosity = config.GetProperty<string>("verbosity"); string verbosity = config.GetProperty<string>("verbosity");
fair::Logger::SetVerbosity(verbosity); fair::Logger::SetVerbosity(verbosity);
if (logFile != "") { if (!logFile.empty()) {
fair::Logger::InitFileSink(logFileSeverity, logFile); fair::Logger::InitFileSink(logFileSeverity, logFile);
fair::Logger::SetConsoleSeverity("nolog"); fair::Logger::SetConsoleSeverity("nolog");
} else { } else {
@ -58,7 +58,7 @@ bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, boo
if (envFairMQSeverity) { if (envFairMQSeverity) {
severity = envFairMQSeverity; severity = envFairMQSeverity;
} }
if (severity != "") { if (!severity.empty()) {
fair::Logger::SetConsoleSeverity(severity); fair::Logger::SetConsoleSeverity(severity);
} }
} }

View File

@ -190,7 +190,7 @@ try {
} }
// validate socket address // validate socket address
if (fAddress == "unspecified" || fAddress == "") { if (fAddress == "unspecified" || fAddress.empty()) {
ss << "INVALID"; ss << "INVALID";
LOG(debug) << ss.str(); LOG(debug) << ss.str();
LOG(debug) << "invalid channel address: '" << fAddress << "'"; LOG(debug) << "invalid channel address: '" << fAddress << "'";
@ -226,7 +226,7 @@ try {
} else if (address.compare(0, 6, "ipc://") == 0) { } else if (address.compare(0, 6, "ipc://") == 0) {
// check if IPC address is not empty // check if IPC address is not empty
string addressString = address.substr(6); string addressString = address.substr(6);
if (addressString == "") { if (addressString.empty()) {
ss << "INVALID"; ss << "INVALID";
LOG(debug) << ss.str(); LOG(debug) << ss.str();
LOG(error) << "invalid channel address: '" << address << "' (empty IPC address?)"; LOG(error) << "invalid channel address: '" << address << "' (empty IPC address?)";
@ -235,7 +235,7 @@ try {
} else if (address.compare(0, 9, "inproc://") == 0) { } else if (address.compare(0, 9, "inproc://") == 0) {
// check if IPC address is not empty // check if IPC address is not empty
string addressString = address.substr(9); string addressString = address.substr(9);
if (addressString == "") { if (addressString.empty()) {
ss << "INVALID"; ss << "INVALID";
LOG(debug) << ss.str(); LOG(debug) << ss.str();
LOG(error) << "invalid channel address: '" << address << "' (empty inproc address?)"; LOG(error) << "invalid channel address: '" << address << "' (empty inproc address?)";
@ -244,7 +244,7 @@ try {
} else if (address.compare(0, 8, "verbs://") == 0) { } else if (address.compare(0, 8, "verbs://") == 0) {
// check if IPC address is not empty // check if IPC address is not empty
string addressString = address.substr(8); string addressString = address.substr(8);
if (addressString == "") { if (addressString.empty()) {
ss << "INVALID"; ss << "INVALID";
LOG(debug) << ss.str(); LOG(debug) << ss.str();
LOG(error) << "invalid channel address: '" << address << "' (empty verbs address?)"; LOG(error) << "invalid channel address: '" << address << "' (empty verbs address?)";

View File

@ -246,7 +246,7 @@ void FairMQDevice::InitWrapper()
if (subChannel.fMethod == "bind") { if (subChannel.fMethod == "bind") {
// if binding address is not specified, try getting it from the configured network interface // 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 // if the configured network interface is default, get its name from the default route
try { try {
if (networkInterface == "default") { if (networkInterface == "default") {
@ -381,7 +381,7 @@ bool FairMQDevice::AttachChannel(FairMQChannel& chan)
if (!(bind && hostPart == "*")) { if (!(bind && hostPart == "*")) {
string portPart = addressString.substr(pos + 1); string portPart = addressString.substr(pos + 1);
string resolvedHost = tools::getIpFromHostname(hostPart); string resolvedHost = tools::getIpFromHostname(hostPart);
if (resolvedHost == "") { if (resolvedHost.empty()) {
return false; return false;
} }
address.assign("tcp://" + resolvedHost + ":" + portPart); address.assign("tcp://" + resolvedHost + ":" + portPart);
@ -490,11 +490,11 @@ void FairMQDevice::HandleSingleChannelInput()
{ {
bool proceed = true; bool proceed = true;
if (fMsgInputs.size() > 0) { if (!fMsgInputs.empty()) {
while (!NewStatePending() && proceed) { while (!NewStatePending() && proceed) {
proceed = HandleMsgInput(fInputChannelKeys.at(0), fMsgInputs.begin()->second, 0); proceed = HandleMsgInput(fInputChannelKeys.at(0), fMsgInputs.begin()->second, 0);
} }
} else if (fMultipartInputs.size() > 0) { } else if (!fMultipartInputs.empty()) {
while (!NewStatePending() && proceed) { while (!NewStatePending() && proceed) {
proceed = HandleMultipartInput(fInputChannelKeys.at(0), fMultipartInputs.begin()->second, 0); proceed = HandleMultipartInput(fInputChannelKeys.at(0), fMultipartInputs.begin()->second, 0);
} }

View File

@ -324,7 +324,7 @@ class FairMQDevice
void PrintRegisteredChannels() void PrintRegisteredChannels()
{ {
if (fChannelRegistry.size() < 1) { if (fChannelRegistry.empty()) {
LOGV(info, verylow) << "no channels registered."; LOGV(info, verylow) << "no channels registered.";
} else { } else {
for (const auto& c : fChannelRegistry) { for (const auto& c : fChannelRegistry) {

View File

@ -35,7 +35,7 @@ auto FairMQTransportFactory::CreateTransportFactory(const string& type,
auto finalId = id; auto finalId = id;
// Generate uuid if empty // Generate uuid if empty
if (finalId == "") { if (finalId.empty()) {
finalId = fair::mq::tools::Uuid(); finalId = fair::mq::tools::Uuid();
} }

View File

@ -35,7 +35,7 @@ namespace fair::mq
fair::mq::Properties PtreeParser(const ptree& pt, const string& id) 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"); throw ParserError("no device ID provided. Provide with `--id` cmd option");
} }

View File

@ -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 << "\""; LOG(warn) << "could not find anything with \"" << q << "\"";
} }
@ -277,7 +277,7 @@ map<string, string> ProgOptions::GetPropertiesAsString(const string& q) const
} }
} }
if (properties.size() == 0) { if (properties.empty()) {
LOG(warn) << "could not find anything with \"" << q << "\""; LOG(warn) << "could not find anything with \"" << q << "\"";
} }
@ -439,7 +439,7 @@ void ProgOptions::PrintOptionsRaw() const
replace(description.begin(), description.end(), '\n', ' '); replace(description.begin(), description.end(), '\n', ' ');
cout << o->long_name() << ":" << value.value << ":" << (value.type == "" ? "<unknown>" : value.type) << ":" << description << endl; cout << o->long_name() << ":" << value.value << ":" << (value.type.empty() ? "<unknown>" : value.type) << ":" << description << endl;
} }
} }

View File

@ -37,7 +37,7 @@ class PropertyHelper
template<typename T> template<typename T>
static void AddType(std::string label = "") static void AddType(std::string label = "")
{ {
if (label == "") { if (label.empty()) {
label = boost::core::demangle(typeid(T).name()); label = boost::core::demangle(typeid(T).name());
} }
fTypeInfos[std::type_index(typeid(T))] = [label](const Property& p) { fTypeInfos[std::type_index(typeid(T))] = [label](const Property& p) {

View File

@ -109,7 +109,7 @@ Properties SuboptParser(const vector<string>& channelConfig, const string& devic
} }
} }
if (channelName != "") { if (!channelName.empty()) {
channelProperties.add_child("sockets", socketsArray); channelProperties.add_child("sockets", socketsArray);
} else { } else {
// TODO: what is the error policy here, should we abort? // TODO: what is the error policy here, should we abort?

View File

@ -31,7 +31,7 @@ Config::Config(const string& name, const Plugin::Version version, const string&
idForParser = GetProperty<string>("id"); idForParser = GetProperty<string>("id");
} }
if (idForParser != "") { if (!idForParser.empty()) {
try { try {
if (PropertyExists("mq-config")) { if (PropertyExists("mq-config")) {
LOG(debug) << "mq-config: Using default JSON parser"; LOG(debug) << "mq-config: Using default JSON parser";

View File

@ -67,7 +67,7 @@ auto DDSTopology::GetTasks(const std::string& path /* = "" */) const -> std::vec
std::vector<DDSTask> list; std::vector<DDSTask> list;
dds::topology_api::STopoRuntimeTask::FilterIteratorPair_t itPair; dds::topology_api::STopoRuntimeTask::FilterIteratorPair_t itPair;
if (path == "") { if (path.empty()) {
itPair = fImpl->fTopo.getRuntimeTaskIterator(nullptr); // passing nullptr will get all tasks itPair = fImpl->fTopo.getRuntimeTaskIterator(nullptr); // passing nullptr will get all tasks
} else { } else {
itPair = fImpl->fTopo.getRuntimeTaskIteratorMatchingPath(path); itPair = fImpl->fTopo.getRuntimeTaskIteratorMatchingPath(path);

View File

@ -1066,7 +1066,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
{ {
if (!fOp.IsCompleted() && fCount == fExpectedCount) { if (!fOp.IsCompleted() && fCount == fExpectedCount) {
fTimer.cancel(); fTimer.cancel();
if (fResult.failed.size() > 0) { if (!fResult.failed.empty()) {
fOp.Complete(MakeErrorCode(ErrorCode::DeviceGetPropertiesFailed), std::move(fResult)); fOp.Complete(MakeErrorCode(ErrorCode::DeviceGetPropertiesFailed), std::move(fResult));
} else { } else {
fOp.Complete(std::move(fResult)); fOp.Complete(std::move(fResult));
@ -1221,7 +1221,7 @@ class BasicTopology : public AsioBase<Executor, Allocator>
{ {
if (!fOp.IsCompleted() && fCount == fExpectedCount) { if (!fOp.IsCompleted() && fCount == fExpectedCount) {
fTimer.cancel(); fTimer.cancel();
if (fFailedDevices.size() > 0) { if (!fFailedDevices.empty()) {
fOp.Complete(MakeErrorCode(ErrorCode::DeviceSetPropertiesFailed), fFailedDevices); fOp.Complete(MakeErrorCode(ErrorCode::DeviceSetPropertiesFailed), fFailedDevices);
} else { } else {
fOp.Complete(fFailedDevices); fOp.Complete(fFailedDevices);

View File

@ -76,7 +76,7 @@ void handleCommand(const string& command, const string& path, unsigned int timeo
} }
return; return;
} else if (command == "o") { } 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. // 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)); auto const result = topo.GetProperties("^(session|id)$", path, std::chrono::milliseconds(timeout));
if (result.first != std::error_code()) { if (result.first != std::error_code()) {
@ -90,12 +90,12 @@ void handleCommand(const string& command, const string& path, unsigned int timeo
} }
return; return;
} else if (command == "p") { } 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; 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, "'.")); throw runtime_error(tools::ToString("cannot send property with empty key and/or value! given key: '", pKey, "', value: '", pVal, "'."));
} }
const DeviceProperties props{{pKey, 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); auto const result = topo.SetProperties(props, path);
if (result.first != std::error_code()) { if (result.first != std::error_code()) {
cout << "ERROR: SetProperties failed for '" << path << "': " << result.first.message() << endl; 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)); this_thread::sleep_for(chrono::milliseconds(100));
return; return;
} else if (command == "i") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::InitDevice, path, std::chrono::milliseconds(timeout));
} else if (command == "k") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::CompleteInit, path, std::chrono::milliseconds(timeout));
} else if (command == "b") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::Bind, path, std::chrono::milliseconds(timeout));
} else if (command == "x") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::Connect, path, std::chrono::milliseconds(timeout));
} else if (command == "j") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::InitTask, path, std::chrono::milliseconds(timeout));
} else if (command == "r") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::Run, path, std::chrono::milliseconds(timeout));
} else if (command == "s") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::Stop, path, std::chrono::milliseconds(timeout));
} else if (command == "t") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::ResetTask, path, std::chrono::milliseconds(timeout));
} else if (command == "d") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::ResetDevice, path, std::chrono::milliseconds(timeout));
} else if (command == "q") { } 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)); changeStateResult = topo.ChangeState(TopologyTransition::End, path, std::chrono::milliseconds(timeout));
} else if (command == "h") { } else if (command == "h") {
cout << "> help" << endl; 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) 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); handleCommand(commandIn, path, timeout, topo, pKey, pVal);
return; return;
} }
@ -232,12 +232,12 @@ try {
Topology topo(ddsTopo, session, true); Topology topo(ddsTopo, session, true);
if (targetState != "") { if (!targetState.empty()) {
if (command != "") { if (!command.empty()) {
sendCommand(command, path, timeout, topo, pKey, pVal); sendCommand(command, path, timeout, topo, pKey, pVal);
} }
size_t pos = targetState.find("->"); 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) { if (pos == string::npos) {
/* auto ec = */topo.WaitForState(GetState(targetState), path, std::chrono::milliseconds(timeout)); /* auto ec = */topo.WaitForState(GetState(targetState), path, std::chrono::milliseconds(timeout));
// cout << "WaitForState(" << targetState << ") result: " << ec.message() << endl; // cout << "WaitForState(" << targetState << ") result: " << ec.message() << endl;

View File

@ -575,7 +575,7 @@ std::vector<std::pair<std::string, bool>> Monitor::Cleanup(const ShmId& shmId, b
if (verbose) { if (verbose) {
LOG(info) << "Found RegionInfo with path: '" << path << "', flags: " << flags << ", fDestroyed: " << ri.fDestroyed << "."; 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)); result.emplace_back(RunRemoval(Monitor::RemoveFileMapping, path + "fmq_" + shmId.shmId + "_rg_" + to_string(i), verbose));
} else { } else {
result.emplace_back(RunRemoval(Monitor::RemoveObject, "fmq_" + shmId.shmId + "_rg_" + to_string(i), verbose)); result.emplace_back(RunRemoval(Monitor::RemoveObject, "fmq_" + shmId.shmId + "_rg_" + to_string(i), verbose));

View File

@ -59,7 +59,7 @@ struct Region
{ {
using namespace boost::interprocess; using namespace boost::interprocess;
if (path != "") { if (!path.empty()) {
fName = std::string(path + fName); fName = std::string(path + fName);
if (!fRemote) { if (!fRemote) {

View File

@ -469,7 +469,7 @@ class Socket final : public fair::mq::Socket
static int GetConstant(const std::string& constant) static int GetConstant(const std::string& constant)
{ {
if (constant == "") return 0; if (constant.empty()) return 0;
if (constant == "sub") return ZMQ_SUB; if (constant == "sub") return ZMQ_SUB;
if (constant == "pub") return ZMQ_PUB; if (constant == "pub") return ZMQ_PUB;
if (constant == "xsub") return ZMQ_XSUB; if (constant == "xsub") return ZMQ_XSUB;

View File

@ -421,7 +421,7 @@ class Socket final : public fair::mq::Socket
static int GetConstant(const std::string& constant) static int GetConstant(const std::string& constant)
{ {
if (constant == "") return 0; if (constant.empty()) return 0;
if (constant == "sub") return ZMQ_SUB; if (constant == "sub") return ZMQ_SUB;
if (constant == "pub") return ZMQ_PUB; if (constant == "pub") return ZMQ_PUB;
if (constant == "xsub") return ZMQ_XSUB; if (constant == "xsub") return ZMQ_XSUB;