From dafa99c41eaa2baac2259159c4f738109be2a234 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 9 Apr 2019 14:11:48 +0200 Subject: [PATCH] Replace empty string comparison --- include/deal.II/lac/block_matrix_array.h | 2 +- include/deal.II/lac/swappable_vector.templates.h | 12 ++++++------ source/base/data_out_base.cc | 14 +++++++------- source/base/exceptions.cc | 2 +- source/base/parameter_acceptor.cc | 8 ++++---- source/base/parameter_handler.cc | 6 +++--- source/base/path_search.cc | 2 +- source/base/subscriptor.cc | 6 +++--- source/base/table_handler.cc | 4 ++-- source/base/timer.cc | 4 ++-- source/gmsh/utilities.cc | 2 +- source/grid/grid_in.cc | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/include/deal.II/lac/block_matrix_array.h b/include/deal.II/lac/block_matrix_array.h index 75fd70b812..3f8a102237 100644 --- a/include/deal.II/lac/block_matrix_array.h +++ b/include/deal.II/lac/block_matrix_array.h @@ -609,7 +609,7 @@ BlockMatrixArray::print_latex(StreamType &out) const std::ostringstream stream; - if (array(m->row, m->col) != "" && m->prefix >= 0) + if (!array(m->row, m->col).empty() && m->prefix >= 0) stream << "+"; if (m->prefix != 1.) stream << m->prefix << 'x'; diff --git a/include/deal.II/lac/swappable_vector.templates.h b/include/deal.II/lac/swappable_vector.templates.h index 54963f8920..74b39b7b72 100644 --- a/include/deal.II/lac/swappable_vector.templates.h +++ b/include/deal.II/lac/swappable_vector.templates.h @@ -39,7 +39,7 @@ SwappableVector::SwappableVector(const SwappableVector &v) , filename() , data_is_preloaded(false) { - Assert(v.filename == "", ExcInvalidCopyOperation()); + Assert(v.filename.empty(), ExcInvalidCopyOperation()); } @@ -54,7 +54,7 @@ SwappableVector::~SwappableVector() // first, before killing the vector // itself - if (filename != "") + if (!filename.empty()) { try { @@ -72,7 +72,7 @@ SwappableVector & SwappableVector::operator=(const SwappableVector &v) { // if necessary, first delete data - if (filename != "") + if (!filename.empty()) kill_file(); // if in MT mode, block all other @@ -97,7 +97,7 @@ SwappableVector::swap_out(const std::string &name) // that has not been deleted in the // meantime, then we kill that file // first - if (filename != "") + if (!filename.empty()) kill_file(); filename = name; @@ -197,7 +197,7 @@ SwappableVector::reload_vector(const bool set_flag) { (void)set_flag; - Assert(filename != "", ExcInvalidFilename(filename)); + Assert(!filename.empty(), ExcInvalidFilename(filename)); Assert(this->size() == 0, ExcSizeNonzero()); std::ifstream tmp_in(filename.c_str()); @@ -233,7 +233,7 @@ SwappableVector::kill_file() // is most probably an error, not? Assert(data_is_preloaded == false, ExcInternalError()); - if (filename != "") + if (!filename.empty()) { int status = std::remove(filename.c_str()); (void)status; diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 939c0c9050..719909c3db 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -5345,7 +5345,7 @@ namespace DataOutBase // underscores unless a vector name has been specified out << "VECTORS "; - if (std::get<2>(nonscalar_data_range) != "") + if (!std::get<2>(nonscalar_data_range).empty()) out << std::get<2>(nonscalar_data_range); else { @@ -5580,7 +5580,7 @@ namespace DataOutBase // underscores unless a vector name has been specified out << " (nonscalar_data_range) != "") + if (!std::get<2>(nonscalar_data_range).empty()) out << std::get<2>(nonscalar_data_range); else { @@ -5811,7 +5811,7 @@ namespace DataOutBase // underscores unless a vector name has been specified out << " (nonscalar_data_range) != "") + if (!std::get<2>(nonscalar_data_range).empty()) out << std::get<2>(nonscalar_data_range); else { @@ -7820,7 +7820,7 @@ DataOutBase::write_filtered_data( // Determine the vector name. Concatenate all the component names with // double underscores unless a vector name has been specified - if (std::get<2>(nonscalar_data_ranges[n_th_vector]) != "") + if (!std::get<2>(nonscalar_data_ranges[n_th_vector]).empty()) { vector_name = std::get<2>(nonscalar_data_ranges[n_th_vector]); } @@ -8565,7 +8565,7 @@ DataOutInterface::validate_dataset_names() const for (const auto &range : ranges) { const std::string &name = std::get<2>(range); - if (name != "") + if (!name.empty()) { Assert(all_names.find(name) == all_names.end(), ExcMessage( @@ -9013,7 +9013,7 @@ namespace DataOutBase while ((header.size() != 0) && (header[header.size() - 1] == ' ')) header.erase(header.size() - 1); } - while ((header == "") && in); + while ((header.empty()) && in); std::ostringstream s; s << "[deal.II intermediate Patch<" << dim << ',' << spacedim << ">]"; diff --git a/source/base/exceptions.cc b/source/base/exceptions.cc index 412b3b008c..9d743306cb 100644 --- a/source/base/exceptions.cc +++ b/source/base/exceptions.cc @@ -147,7 +147,7 @@ const char * ExceptionBase::what() const noexcept { // If no error c_string was generated so far, do it now: - if (what_str == "") + if (what_str.empty()) { #ifdef DEAL_II_HAVE_GLIBC_STACKTRACE // We have deferred the symbol lookup to this point to avoid costly diff --git a/source/base/parameter_acceptor.cc b/source/base/parameter_acceptor.cc index b239541c40..da217ac3ca 100644 --- a/source/base/parameter_acceptor.cc +++ b/source/base/parameter_acceptor.cc @@ -47,8 +47,8 @@ ParameterAcceptor::~ParameterAcceptor() std::string ParameterAcceptor::get_section_name() const { - return (section_name != "" ? section_name : - boost::core::demangle(typeid(*this).name())); + return (!section_name.empty() ? section_name : + boost::core::demangle(typeid(*this).name())); } @@ -60,7 +60,7 @@ ParameterAcceptor::initialize( ParameterHandler & prm) { declare_all_parameters(prm); - if (filename != "") + if (!filename.empty()) { // check the extension of input file if (filename.substr(filename.find_last_of('.') + 1) == "prm") @@ -106,7 +106,7 @@ ParameterAcceptor::initialize( "Invalid extension of parameter file. Please use .prm or .xml")); } - if (output_filename != "") + if (!output_filename.empty()) { std::ofstream outfile(output_filename.c_str()); Assert(outfile, ExcIO()); diff --git a/source/base/parameter_handler.cc b/source/base/parameter_handler.cc index 68e828c745..3e9f4b3e2b 100644 --- a/source/base/parameter_handler.cc +++ b/source/base/parameter_handler.cc @@ -494,8 +494,8 @@ namespace // make sure we have a corresponding entry in the destination // object as well const std::string full_path = - (current_path == "" ? p->first : - current_path + path_separator + p->first); + (current_path.empty() ? p->first : + current_path + path_separator + p->first); const std::string new_value = p->second.get("value"); AssertThrow(destination.get_optional(full_path) && @@ -533,7 +533,7 @@ namespace { // it must be a subsection read_xml_recursively(p->second, - (current_path == "" ? + (current_path.empty() ? p->first : current_path + path_separator + p->first), path_separator, diff --git a/source/base/path_search.cc b/source/base/path_search.cc index 4faee0bd51..cf53ddb590 100644 --- a/source/base/path_search.cc +++ b/source/base/path_search.cc @@ -146,7 +146,7 @@ PathSearch::find(const std::string &filename, // try again with the suffix appended, unless there is // no suffix - if (suffix != "") + if (!suffix.empty()) { real_name = *path + filename + suffix; if (debug > 1) diff --git a/source/base/subscriptor.cc b/source/base/subscriptor.cc index 3aa98f2d5f..973e5d2e1f 100644 --- a/source/base/subscriptor.cc +++ b/source/base/subscriptor.cc @@ -84,7 +84,7 @@ Subscriptor::check_no_subscribers() const noexcept std::string(map_entry.first); } - if (infostring == "") + if (infostring.empty()) infostring = ""; AssertNothrow(counter == 0, @@ -136,7 +136,7 @@ Subscriptor::subscribe(std::atomic *const validity, object_info = &typeid(*this); ++counter; - const std::string name = (id != "") ? id : unknown_subscriber; + const std::string name = (!id.empty()) ? id : unknown_subscriber; map_iterator it = counter_map.find(name); if (it == counter_map.end()) @@ -154,7 +154,7 @@ void Subscriptor::unsubscribe(std::atomic *const validity, const std::string & id) const { - const std::string name = (id != "") ? id : unknown_subscriber; + const std::string name = (!id.empty()) ? id : unknown_subscriber; if (counter == 0) { AssertNothrow(counter > 0, ExcNoSubscriber(object_info->name(), name)); diff --git a/source/base/table_handler.cc b/source/base/table_handler.cc index 6ae95c51ce..6342e4f57f 100644 --- a/source/base/table_handler.cc +++ b/source/base/table_handler.cc @@ -722,9 +722,9 @@ TableHandler::write_tex(std::ostream &out, const bool with_header) const } out << "\\end{tabular}" << std::endl << "\\end{center}" << std::endl; - if (tex_table_caption != "") + if (!tex_table_caption.empty()) out << "\\caption{" << tex_table_caption << "}" << std::endl; - if (tex_table_label != "") + if (!tex_table_label.empty()) out << "\\label{" << tex_table_label << "}" << std::endl; out << "\\end{table}" << std::endl; if (with_header) diff --git a/source/base/timer.cc b/source/base/timer.cc index 13ee1aa8f7..119ae4d477 100644 --- a/source/base/timer.cc +++ b/source/base/timer.cc @@ -459,7 +459,7 @@ TimerOutput::leave_subsection(const std::string §ion_name) std::lock_guard lock(mutex); - if (section_name != "") + if (!section_name.empty()) { Assert(sections.find(section_name) != sections.end(), ExcMessage("Cannot delete a section that was never created.")); @@ -472,7 +472,7 @@ TimerOutput::leave_subsection(const std::string §ion_name) // if no string is given, exit the last // active section. const std::string actual_section_name = - (section_name == "" ? active_sections.back() : section_name); + (section_name.empty() ? active_sections.back() : section_name); sections[actual_section_name].timer.stop(); sections[actual_section_name].total_wall_time += diff --git a/source/gmsh/utilities.cc b/source/gmsh/utilities.cc index 456e4fe6f8..512196010e 100644 --- a/source/gmsh/utilities.cc +++ b/source/gmsh/utilities.cc @@ -59,7 +59,7 @@ namespace Gmsh { std::string base_name = prm.output_base_name; char dir_template[] = "ctfbc-XXXXXX"; - if (base_name == "") + if (base_name.empty()) { const char *temp = mkdtemp(dir_template); AssertThrow(temp != nullptr, diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 28f2907258..addc9a384c 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -382,7 +382,7 @@ GridIn::read_vtk(std::istream &in) set = keyword; break; } - if (set == "") + if (set.empty()) // keep ignoring everything until the next SCALARS // keyword continue; -- 2.39.5