Skip to content

Commit

Permalink
Merge pull request #2986 from SunBlack/readability-string-compare
Browse files Browse the repository at this point in the history
Simplify readability of string compare
  • Loading branch information
taketwo authored Apr 10, 2019
2 parents 93f9e72 + 3da8003 commit a13ad26
Show file tree
Hide file tree
Showing 38 changed files with 79 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace pcl
boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension.compare (ext) == 0)
if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string();

Expand Down Expand Up @@ -229,7 +229,7 @@ namespace pcl
typename std::vector<ModelT>::iterator it = models_->begin ();
while (it != models_->end ())
{
if (model_id.compare ((*it).id_) != 0)
if (model_id != (*it).id_)
{
it = models_->erase (it);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace pcl
else
{

if (this->model.id_.compare (other.model.id_) == 0)
if (this->model.id_ == other.model.id_)
{
//check view id
if ((this->view_id < other.view_id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ template<template<class > class Distance, typename PointInT, typename FeatureT>
{
boost::shared_ptr < std::vector<ModelT> > models;

if(search_model_.compare("") == 0) {
if(search_model_.empty()) {
models = source_->getModels ();
} else {
models = source_->getModels (search_model_);
Expand Down
6 changes: 3 additions & 3 deletions apps/3d_rec_framework/src/tools/global_classification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ main (int argc, char ** argv)
normal_estimator->setRemoveOutliers (true);
normal_estimator->setFactorsForCMR (3, 7);

if (desc_name.compare ("vfh") == 0)
if (desc_name == "vfh")
{
boost::shared_ptr<pcl::rec_3d_framework::VFHEstimation<pcl::PointXYZ, pcl::VFHSignature308> > vfh_estimator;
vfh_estimator.reset (new pcl::rec_3d_framework::VFHEstimation<pcl::PointXYZ, pcl::VFHSignature308>);
Expand All @@ -188,7 +188,7 @@ main (int argc, char ** argv)
segmentAndClassify<flann::L1, pcl::PointXYZ, pcl::VFHSignature308> (global);
}

if (desc_name.compare ("cvfh") == 0)
if (desc_name == "cvfh")
{
boost::shared_ptr<pcl::rec_3d_framework::CVFHEstimation<pcl::PointXYZ, pcl::VFHSignature308> > vfh_estimator;
vfh_estimator.reset (new pcl::rec_3d_framework::CVFHEstimation<pcl::PointXYZ, pcl::VFHSignature308>);
Expand All @@ -208,7 +208,7 @@ main (int argc, char ** argv)
segmentAndClassify<Metrics::HistIntersectionUnionDistance, pcl::PointXYZ, pcl::VFHSignature308> (global);
}

if (desc_name.compare ("esf") == 0)
if (desc_name == "esf")
{
boost::shared_ptr<pcl::rec_3d_framework::ESFEstimation<pcl::PointXYZ, pcl::ESFSignature640> > estimator;
estimator.reset (new pcl::rec_3d_framework::ESFEstimation<pcl::PointXYZ, pcl::ESFSignature640>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ template<template<class > class DistT, typename PointT, typename FeatureT>
g = 0.0f;
b = 0.0f;

if (models->at (j).id_.compare ("cheff") == 0)
if (models->at (j).id_ == "cheff")
{
r = 0.0f;
g = 255.0f;
b = 0.0f;
}
else if (models->at (j).id_.compare ("chicken_high") == 0)
else if (models->at (j).id_ == "chicken_high")
{
r = 0.0f;
g = 255.0f;
b = 255.0f;
}
else if (models->at (j).id_.compare ("parasaurolophus_high") == 0)
else if (models->at (j).id_ == "parasaurolophus_high")
{
r = 255.0f;
g = 255.0f;
Expand Down Expand Up @@ -260,7 +260,7 @@ getModelsInDirectory (bf::path & dir, std::string & rel_path_so_far, std::vector
boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension.compare (ext) == 0)
if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string();

Expand Down Expand Up @@ -318,13 +318,13 @@ main (int argc, char ** argv)
pcl::console::parse_argument (argc, argv, "-use_hv", use_hv);
pcl::console::parse_argument (argc, argv, "-thres_hyp", thres_hyp_);

if (mians_scenes.compare ("") == 0)
if (mians_scenes.empty())
{
PCL_ERROR("Set the directory containing mians scenes using the -mians_scenes_dir [dir] option\n");
return -1;
}

if (path.compare ("") == 0)
if (path.empty())
{
PCL_ERROR("Set the directory containing the models of mian dataset using the -models_dir [dir] option\n");
return -1;
Expand Down Expand Up @@ -428,7 +428,7 @@ main (int argc, char ** argv)
cast_hv_alg = boost::static_pointer_cast<pcl::HypothesisVerification<pcl::PointXYZ, pcl::PointXYZ> > (go);
}

if (desc_name.compare ("shot") == 0)
if (desc_name == "shot")
{
boost::shared_ptr<pcl::rec_3d_framework::SHOTLocalEstimation<pcl::PointXYZ, pcl::Histogram<352> > > estimator;
estimator.reset (new pcl::rec_3d_framework::SHOTLocalEstimation<pcl::PointXYZ, pcl::Histogram<352> >);
Expand Down Expand Up @@ -458,7 +458,7 @@ main (int argc, char ** argv)

}

if (desc_name.compare ("shot_omp") == 0)
if (desc_name == "shot_omp")
{
desc_name = std::string ("shot");
boost::shared_ptr<pcl::rec_3d_framework::SHOTLocalEstimationOMP<pcl::PointXYZ, pcl::Histogram<352> > > estimator;
Expand Down Expand Up @@ -492,7 +492,7 @@ main (int argc, char ** argv)

}

if (desc_name.compare ("fpfh") == 0)
if (desc_name == "fpfh")
{
boost::shared_ptr<pcl::rec_3d_framework::FPFHLocalEstimation<pcl::PointXYZ, pcl::FPFHSignature33> > estimator;
estimator.reset (new pcl::rec_3d_framework::FPFHLocalEstimation<pcl::PointXYZ, pcl::FPFHSignature33>);
Expand Down
2 changes: 1 addition & 1 deletion apps/in_hand_scanner/src/offline_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pcl::ihs::OfflineIntegration::getFilesFromDirectory (const std::string
const std::string extension,
std::vector <std::string>& files) const
{
if (path_dir == "" || !boost::filesystem::exists (path_dir))
if (path_dir.empty() || !boost::filesystem::exists (path_dir))
{
std::cerr << "ERROR in offline_integration.cpp: Invalid path\n '" << path_dir << "'\n";
return (false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace face_detection_apps_utils
boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension.compare (ext) == 0)
if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path().filename()).string();
relative_paths.push_back (path);
Expand Down
4 changes: 2 additions & 2 deletions apps/point_cloud_editor/src/cloudEditorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ CloudEditorWidget::save ()
QString file_path = QFileDialog::getSaveFileName(this,tr("Save point cloud"));

std::string file_path_std = file_path.toStdString();
if ( (file_path_std == "") || (!cloud_ptr_) )
if ( (file_path_std.empty()) || (!cloud_ptr_) )
return;

if (is_colored_)
Expand Down Expand Up @@ -577,7 +577,7 @@ CloudEditorWidget::isColored (const std::string &fileName) const
{
std::string name(field.name);
stringToLower(name);
if ((name.compare("rgb") == 0) || (name.compare("rgba") == 0))
if ((name == "rgb") || (name == "rgba"))
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions apps/point_cloud_editor/src/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ Statistics::getStats()
for(const auto &stat_vec : stat_vec_)
{
std::string stat_string = stat_vec -> getStat();
if (stat_string != "")
if (!stat_string.empty())
{
result += (stat_string + '\n');
}
}

if (result == "")
if (result.empty())
return ("Please load your cloud.");
return (result);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/src/face_detection/filesystem_face_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ int main(int argc, char ** argv)

pcl::visualization::PCLVisualizer vis ("PCL Face detection");

if (test_directory.compare ("") != 0)
if (!test_directory.empty())
{
//recognize all files in directory...
std::string start;
Expand Down
2 changes: 1 addition & 1 deletion apps/src/pcd_video_player/pcd_video_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ PCDVideoPlayer::selectFolderButtonPressed ()
for (boost::filesystem::directory_iterator itr (dir_.toStdString ()); itr != end_itr; ++itr)
{
std::string ext = itr->path ().extension ().string ();
if (ext.compare (".pcd") == 0)
if (ext == ".pcd")
{
pcd_files_.push_back (itr->path ().string ());
pcd_paths_.push_back (itr->path ());
Expand Down
2 changes: 1 addition & 1 deletion cuda/apps/src/kinect_planes_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class MultiRansac
//bool repeat = false;

//std::string path = "./pcl_logo.pcd";
//if (path != "" && boost::filesystem::exists (path))
//if (!path.empty() && boost::filesystem::exists (path))
//{
// filegrabber = new pcl::PCDGrabber<pcl::PointXYZRGB > (path, frames_per_second, repeat);
//}
Expand Down
2 changes: 1 addition & 1 deletion geometry/include/pcl/geometry/mesh_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace pcl
unsigned int line_number = 1;
int n_v = -1, n_he = -1, n_f = -1;

if (!std::getline (file, line) || line.compare ("PCL half-edge mesh") != 0)
if (!std::getline (file, line) || line != "PCL half-edge mesh")
{
std::cerr << "Error loading '" << filename << "' (line " << line_number << "): Wrong file format.\n";
return (false);
Expand Down
2 changes: 1 addition & 1 deletion io/src/depth_sense/depth_sense_grabber_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pcl::io::depth_sense::DepthSenseGrabberImpl::DepthSenseGrabberImpl (DepthSenseGr
, color_data_ (COLOR_SIZE * 3)
, depth_buffer_ (new pcl::io::SingleBuffer<float> (SIZE))
{
if (device_id == "")
if (device_id.empty())
device_id_ = DepthSenseDeviceManager::getInstance ()->captureDevice (this);
else if (device_id[0] == '#')
device_id_ = DepthSenseDeviceManager::getInstance ()->captureDevice (this, boost::lexical_cast<int> (device_id.substr (1)) - 1);
Expand Down
2 changes: 1 addition & 1 deletion io/src/ifs_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pcl::IFSReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
std::ifstream fs;
std::string line;

if (file_name == "" || !boost::filesystem::exists (file_name))
if (file_name.empty() || !boost::filesystem::exists (file_name))
{
PCL_ERROR ("[pcl::IFSReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
return (-1);
Expand Down
2 changes: 1 addition & 1 deletion io/src/lzf_image_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename,
std::vector<char> &data,
uint32_t &uncompressed_size)
{
if (filename == "" || !boost::filesystem::exists (filename))
if (filename.empty() || !boost::filesystem::exists (filename))
{
PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Could not find file '%s'.\n", filename.c_str ());
return (false);
Expand Down
20 changes: 10 additions & 10 deletions io/src/obj_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ int
pcl::MTLReader::read (const std::string& obj_file_name,
const std::string& mtl_file_name)
{
if (obj_file_name == "" || !boost::filesystem::exists (obj_file_name))
if (obj_file_name.empty() || !boost::filesystem::exists (obj_file_name))
{
PCL_ERROR ("[pcl::MTLReader::read] Could not find file '%s'!\n",
obj_file_name.c_str ());
return (-1);
}

if (mtl_file_name == "")
if (mtl_file_name.empty())
{
PCL_ERROR ("[pcl::MTLReader::read] MTL file name is empty!\n");
return (-1);
Expand All @@ -165,7 +165,7 @@ pcl::MTLReader::read (const std::string& obj_file_name,
int
pcl::MTLReader::read (const std::string& mtl_file_path)
{
if (mtl_file_path == "" || !boost::filesystem::exists (mtl_file_path))
if (mtl_file_path.empty() || !boost::filesystem::exists (mtl_file_path))
{
PCL_ERROR ("[pcl::MTLReader::read] Could not find file '%s'.\n", mtl_file_path.c_str ());
return (-1);
Expand All @@ -192,7 +192,7 @@ pcl::MTLReader::read (const std::string& mtl_file_path)
{
getline (mtl_file, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Tokenize the line
Expand Down Expand Up @@ -347,7 +347,7 @@ pcl::OBJReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
std::ifstream fs;
std::string line;

if (file_name == "" || !boost::filesystem::exists (file_name))
if (file_name.empty() || !boost::filesystem::exists (file_name))
{
PCL_ERROR ("[pcl::OBJReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
return (-1);
Expand Down Expand Up @@ -380,7 +380,7 @@ pcl::OBJReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
{
getline (fs, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Trim the line
Expand Down Expand Up @@ -548,7 +548,7 @@ pcl::OBJReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
std::string line;
getline (fs, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Tokenize the line
Expand Down Expand Up @@ -691,7 +691,7 @@ pcl::OBJReader::read (const std::string &file_name, pcl::TextureMesh &mesh,
{
getline (fs, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Tokenize the line
Expand Down Expand Up @@ -782,7 +782,7 @@ pcl::OBJReader::read (const std::string &file_name, pcl::TextureMesh &mesh,
}
}
// We didn't find the appropriate material so we create it here with name only.
if (mesh.tex_materials.back ().tex_name == "")
if (mesh.tex_materials.back ().tex_name.empty())
mesh.tex_materials.back ().tex_name = st[1];
mesh.tex_coordinates.push_back (coordinates);
coordinates.clear ();
Expand Down Expand Up @@ -880,7 +880,7 @@ pcl::OBJReader::read (const std::string &file_name, pcl::PolygonMesh &mesh,
std::string line;
getline (fs, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Tokenize the line
Expand Down
8 changes: 4 additions & 4 deletions io/src/pcd_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pcl::PCDReader::readHeader (std::istream &fs, pcl::PCLPointCloud2 &cloud,
{
getline (fs, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Tokenize the line
Expand Down Expand Up @@ -380,7 +380,7 @@ pcl::PCDReader::readHeader (const std::string &file_name, pcl::PCLPointCloud2 &c
Eigen::Vector4f &origin, Eigen::Quaternionf &orientation,
int &pcd_version, int &data_type, unsigned int &data_idx, const int offset)
{
if (file_name == "" || !boost::filesystem::exists (file_name))
if (file_name.empty() || !boost::filesystem::exists (file_name))
{
PCL_ERROR ("[pcl::PCDReader::readHeader] Could not find file '%s'.\n", file_name.c_str ());
return (-1);
Expand Down Expand Up @@ -442,7 +442,7 @@ pcl::PCDReader::readBodyASCII (std::istream &fs, pcl::PCLPointCloud2 &cloud, int
{
getline (fs, line);
// Ignore empty lines
if (line == "")
if (line.empty())
continue;

// Tokenize the line
Expand Down Expand Up @@ -692,7 +692,7 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
pcl::console::TicToc tt;
tt.tic ();

if (file_name == "" || !boost::filesystem::exists (file_name))
if (file_name.empty() || !boost::filesystem::exists (file_name))
{
PCL_ERROR ("[pcl::PCDReader::read] Could not find file '%s'.\n", file_name.c_str ());
return (-1);
Expand Down
2 changes: 1 addition & 1 deletion io/src/real_sense_grabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pcl::RealSenseGrabber::RealSenseGrabber (const std::string& device_id, const Mod
, mode_requested_ (mode)
, strict_ (strict)
{
if (device_id == "")
if (device_id.empty())
device_ = RealSenseDeviceManager::getInstance ()->captureDevice ();
else if (device_id[0] == '#')
device_ = RealSenseDeviceManager::getInstance ()->captureDevice (boost::lexical_cast<int> (device_id.substr (1)) - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace pcl
boost::split (strs, file, boost::is_any_of ("."));
std::string extension = strs[strs.size () - 1];

if (extension.compare (ext) == 0)
if (extension == ext)
{
std::string path = rel_path_so_far + (itr->path ().filename ()).string ();
relative_paths.push_back (path);
Expand Down
Loading

0 comments on commit a13ad26

Please sign in to comment.