From fac13f1e1f263eeb7abbc9d2c668f892ca92fd06 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 21 Aug 2024 11:22:18 +0200 Subject: [PATCH] clang-tidy --- src/ifcgeom/Iterator.h | 2 -- src/ifcparse/IfcCharacterDecoder.cpp | 38 +++++++++++------------ src/ifcparse/IfcEntityInstanceData.cpp | 4 +-- src/ifcparse/IfcFile.cpp | 22 +++++++------- src/ifcparse/IfcFile.h | 8 ++--- src/ifcparse/IfcGlobalId.cpp | 2 +- src/ifcparse/IfcLogger.cpp | 2 -- src/ifcparse/IfcParse.cpp | 42 +++++++++++++------------- src/ifcparse/IfcParse.h | 4 +-- src/ifcparse/IfcSpfHeader.cpp | 4 +-- src/ifcparse/IfcSpfStream.h | 4 +-- src/ifcparse/parse_ifcxml.cpp | 4 +-- 12 files changed, 66 insertions(+), 70 deletions(-) diff --git a/src/ifcgeom/Iterator.h b/src/ifcgeom/Iterator.h index 7b4a716d90..f4f4649b7c 100644 --- a/src/ifcgeom/Iterator.h +++ b/src/ifcgeom/Iterator.h @@ -55,8 +55,6 @@ * * ********************************************************************************/ -#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR - #ifndef IFCGEOMITERATOR_H #define IFCGEOMITERATOR_H diff --git a/src/ifcparse/IfcCharacterDecoder.cpp b/src/ifcparse/IfcCharacterDecoder.cpp index c3e729ebf9..5c84f77303 100644 --- a/src/ifcparse/IfcCharacterDecoder.cpp +++ b/src/ifcparse/IfcCharacterDecoder.cpp @@ -44,7 +44,7 @@ #define ARBITRARY (1 << 7) #define EXTENDED2 (1 << 8) #define EXTENDED4 (1 << 9) -#define HEX(N) (1 << (9 + N)) +#define HEX(N) (1 << (9 + (N))) #define THIRD_SOLIDUS (1 << 18) #define ENDEXTENDED_X (1 << 19) #define ENDEXTENDED_0 (1 << 20) @@ -52,22 +52,22 @@ #define ENCOUNTERED_HEX (1 << 23) // FIXME: These probably need to be less forgiving in terms of wrongly defined sequences -#define EXPECTS_ALPHABET(S) (S & FIRST_SOLIDUS) -#define EXPECTS_PAGE(S) (S & FIRST_SOLIDUS) -#define EXPECTS_ARBITRARY(S) (S & FIRST_SOLIDUS) -#define EXPECTS_N_OR_F(S) (S & FIRST_SOLIDUS && !(S & ARBITRARY)) -#define EXPECTS_ARBITRARY2(S) (S & ARBITRARY && !(S & SECOND_SOLIDUS)) -#define EXPECTS_ALPHABET_DEFINITION(S) (S & FIRST_SOLIDUS && S & ALPHABET) -#define EXPECTS_SOLIDUS(S) (S & ALPHABET_DEFINITION || S & PAGE || S & ARBITRARY || S & EXTENDED2 || S & EXTENDED4 || S & ENDEXTENDED_0 || S & IGNORED_DIRECTIVE || (S & EXTENDED4 && S & HEX(8)) || (S & EXTENDED2 && S & HEX(4))) -#define EXPECTS_CHARACTER(S) (S & PAGE && S & SECOND_SOLIDUS) -#define EXPECTS_HEX(S) (S & HEX(1) || S & HEX(3) || S & HEX(5) || S & HEX(6) || S & HEX(7) || (S & ARBITRARY && S & SECOND_SOLIDUS) || (S & EXTENDED2 && S & HEX(2)) || (S & EXTENDED4 && S & HEX(4))) -#define EXPECTS_ENDEXTENDED_X(S) (S & THIRD_SOLIDUS) -#define EXPECTS_ENDEXTENDED_0(S) (S & ENDEXTENDED_X) +#define EXPECTS_ALPHABET(S) ((S) & FIRST_SOLIDUS) +#define EXPECTS_PAGE(S) ((S) & FIRST_SOLIDUS) +#define EXPECTS_ARBITRARY(S) ((S) & FIRST_SOLIDUS) +#define EXPECTS_N_OR_F(S) ((S) & FIRST_SOLIDUS && !((S) & ARBITRARY)) +#define EXPECTS_ARBITRARY2(S) ((S) & ARBITRARY && !((S) & SECOND_SOLIDUS)) +#define EXPECTS_ALPHABET_DEFINITION(S) ((S) & FIRST_SOLIDUS && (S) & ALPHABET) +#define EXPECTS_SOLIDUS(S) ((S) & ALPHABET_DEFINITION || (S) & PAGE || (S) & ARBITRARY || (S) & EXTENDED2 || (S) & EXTENDED4 || (S) & ENDEXTENDED_0 || (S) & IGNORED_DIRECTIVE || ((S) & EXTENDED4 && (S) & HEX(8)) || ((S) & EXTENDED2 && (S) & HEX(4))) +#define EXPECTS_CHARACTER(S) ((S) & PAGE && (S) & SECOND_SOLIDUS) +#define EXPECTS_HEX(S) ((S) & HEX(1) || (S) & HEX(3) || (S) & HEX(5) || (S) & HEX(6) || (S) & HEX(7) || ((S) & ARBITRARY && (S) & SECOND_SOLIDUS) || ((S) & EXTENDED2 && (S) & HEX(2)) || ((S) & EXTENDED4 && (S) & HEX(4))) +#define EXPECTS_ENDEXTENDED_X(S) ((S) & THIRD_SOLIDUS) +#define EXPECTS_ENDEXTENDED_0(S) ((S) & ENDEXTENDED_X) -#define IS_VALID_ALPHABET_DEFINITION(C) (C >= 0x41 && C <= 0x49) -#define IS_HEXADECIMAL(C) ((C >= 0x30 && C <= 0x39) || (C >= 0x41 && C <= 0x46)) -#define HEX_TO_INT(C) ((C >= 0x30 && C <= 0x39) ? C - 0x30 : (C + 10) - 0x41) -#define CLEAR_HEX(C) (C &= ~(HEX(1) | HEX(2) | HEX(3) | HEX(4) | HEX(5) | HEX(6) | HEX(7) | HEX(8))) +#define IS_VALID_ALPHABET_DEFINITION(C) ((C) >= 0x41 && (C) <= 0x49) +#define IS_HEXADECIMAL(C) (((C) >= 0x30 && (C) <= 0x39) || ((C) >= 0x41 && (C) <= 0x46)) +#define HEX_TO_INT(C) (((C) >= 0x30 && (C) <= 0x39) ? (C) - 0x30 : ((C) + 10) - 0x41) +#define CLEAR_HEX(C) ((C) &= ~(HEX(1) | HEX(2) | HEX(3) | HEX(4) | HEX(5) | HEX(6) | HEX(7) | HEX(8))) using namespace IfcParse; @@ -80,7 +80,7 @@ IfcCharacterDecoder::~IfcCharacterDecoder() { } namespace { -static unsigned int reference_helper = 0; +unsigned int reference_helper = 0; class pure_impure_helper { private: @@ -446,9 +446,9 @@ std::u32string IfcUtil::convert_utf8_to_utf32(const std::string& s) { } if (is_ascii) { return std::u32string(s.begin(), s.end()); - } else { + } return std::wstring_convert, std::u32string::value_type>().from_bytes(s); - } + } #endif diff --git a/src/ifcparse/IfcEntityInstanceData.cpp b/src/ifcparse/IfcEntityInstanceData.cpp index 8b20702215..1fd064114e 100644 --- a/src/ifcparse/IfcEntityInstanceData.cpp +++ b/src/ifcparse/IfcEntityInstanceData.cpp @@ -14,8 +14,8 @@ public: int operator()(const double& /*i*/) const { return -1; } int operator()(const std::string& /*i*/) const { return -1; } int operator()(const boost::dynamic_bitset<>& /*i*/) const { return -1; } - int operator()(const empty_aggregate_t&) const { return 0; } - int operator()(const empty_aggregate_of_aggregate_t&) const { return 0; } + int operator()(const empty_aggregate_t& /*unused*/) const { return 0; } + int operator()(const empty_aggregate_of_aggregate_t& /*unused*/) const { return 0; } int operator()(const std::vector& i) const { return (int)i.size(); } int operator()(const std::vector& i) const { return (int)i.size(); } int operator()(const std::vector>& i) const { return (int)i.size(); } diff --git a/src/ifcparse/IfcFile.cpp b/src/ifcparse/IfcFile.cpp index 9812d242ac..5a8db304e5 100644 --- a/src/ifcparse/IfcFile.cpp +++ b/src/ifcparse/IfcFile.cpp @@ -80,7 +80,7 @@ namespace { target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_INT || target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_DOUBLE || target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE; - } else if (source == IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE) { + } if (source == IfcUtil::Argument_AGGREGATE_OF_EMPTY_AGGREGATE) { return target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_INT || target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_DOUBLE || target == IfcUtil::Argument_AGGREGATE_OF_AGGREGATE_OF_ENTITY_INSTANCE; @@ -237,9 +237,9 @@ namespace { IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_references& references_to_resolve, const IfcParse::declaration* decl) { std::vector parameter_types; - if (decl && decl->as_type_declaration()) { + if ((decl != nullptr) && (decl->as_type_declaration() != nullptr)) { parameter_types = { decl->as_type_declaration()->declared_type() }; - } else if (decl && decl->as_entity()) { + } else if ((decl != nullptr) && (decl->as_entity() != nullptr)) { auto entity_attrs = decl->as_entity()->all_attributes(); std::transform( entity_attrs.begin(), @@ -251,32 +251,32 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re ); } - if (decl && (tokens_.size() != parameter_types.size())) { + if ((decl != nullptr) && (tokens_.size() != parameter_types.size())) { // warning } - if (tokens_.size() == 0) { + if (tokens_.empty()) { return IfcEntityInstanceData(storage_t(0)); } - storage_t storage(decl + storage_t storage(decl != nullptr ? (std::min)(parameter_types.size(), tokens_.size()) : tokens_.size() ); auto it = tokens_.begin(); auto kt = parameter_types.begin(); - for (; it != tokens_.end() && (!decl || kt != parameter_types.end()); ++it) { + for (; it != tokens_.end() && ((decl == nullptr) || kt != parameter_types.end()); ++it) { auto& token = *it; // @todo coerce to expected type, e.g empty -> std::vector, bool -> logical const IfcParse::parameter_type* param_type = nullptr; - if (decl) { + if (decl != nullptr) { param_type = *kt; } auto index = (uint8_t) std::distance(tokens_.begin(), it); - boost::apply_visitor([this, &storage, name, &references_to_resolve, index, it, param_type](auto& v) { + boost::apply_visitor([this, &storage, name, &references_to_resolve, index, param_type](auto& v) { if constexpr (std::is_same_v, IfcParse::Token>) { dispatch_token(v, param_type && param_type->as_named_type() ? param_type->as_named_type()->declared_type() : nullptr, [this, &storage, name, &references_to_resolve, index](auto v) { if constexpr (std::is_same_v, IfcParse::reference_or_simple_type>) { @@ -292,7 +292,7 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re } }); } else if constexpr (std::is_same_v, IfcParse::parse_context*>) { - auto pt = param_type; + const auto *pt = param_type; if (pt) { while (pt->as_named_type()) { pt = pt->as_named_type()->declared_type()->as_type_declaration()->declared_type(); @@ -312,7 +312,7 @@ IfcEntityInstanceData IfcParse::parse_context::construct(int name, unresolved_re } }, token); - if (decl) { + if (decl != nullptr) { ++kt; } } diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index 0508c39218..79357b4241 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -274,11 +274,11 @@ class IFC_PARSE_API IfcFile { /// Performs a depth-first traversal, returning all entity instance /// attributes as a flat list. NB: includes the root instance specified /// in the first function argument. - aggregate_of_instance::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level = -1); + static aggregate_of_instance::ptr traverse(IfcUtil::IfcBaseClass* instance, int max_level = -1); /// Same as traverse() but maintains topological order by using a /// breadth-first search - aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level = -1); + static aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level = -1); /// Get the attribute indices corresponding to the list of entity instances /// returned by getInverse(). @@ -324,10 +324,10 @@ class IFC_PARSE_API IfcFile { const IfcSpfHeader& header() const { return _header; } IfcSpfHeader& header() { return _header; } - std::string createTimestamp() const; + static std::string createTimestamp() ; void load(unsigned entity_instance_name, const IfcParse::entity* entity, parse_context&, int attribute_index = -1); - void try_read_semicolon(); + void try_read_semicolon() const; void register_inverse(unsigned, const IfcParse::entity* from_entity, Token, int attribute_index); void register_inverse(unsigned, const IfcParse::entity* from_entity, IfcUtil::IfcBaseClass*, int attribute_index); diff --git a/src/ifcparse/IfcGlobalId.cpp b/src/ifcparse/IfcGlobalId.cpp index d095c2b66b..d89e439a64 100644 --- a/src/ifcparse/IfcGlobalId.cpp +++ b/src/ifcparse/IfcGlobalId.cpp @@ -94,7 +94,7 @@ IfcParse::IfcGlobalId::IfcGlobalId() { uuid_data_ = gen(); std::vector v(uuid_data_.size()); std::copy(uuid_data_.begin(), uuid_data_.end(), v.begin()); - string_data_ = compress(&v[0]); + string_data_ = compress(v.data()); #if BOOST_VERSION < 104400 formatted_string = boost::lexical_cast(uuid_data); #else diff --git a/src/ifcparse/IfcLogger.cpp b/src/ifcparse/IfcLogger.cpp index 5aeb0c3813..1b1d9ee437 100644 --- a/src/ifcparse/IfcLogger.cpp +++ b/src/ifcparse/IfcLogger.cpp @@ -17,8 +17,6 @@ * * ********************************************************************************/ -#define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR - #include "IfcLogger.h" #include "Argument.h" diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 4ecd4ec2c8..a31bc7d11e 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -245,7 +245,7 @@ char IfcSpfStream::Read(unsigned int offset) { // // Returns the cursor position // -unsigned int IfcSpfStream::Tell() { +unsigned int IfcSpfStream::Tell() const { return ptr_; } @@ -274,7 +274,7 @@ IfcSpfLexer::~IfcSpfLexer() { delete decoder_; } -unsigned int IfcSpfLexer::skipWhitespace() { +unsigned int IfcSpfLexer::skipWhitespace() const { unsigned int index = 0; while (!stream->eof) { char character = stream->Peek(); @@ -288,7 +288,7 @@ unsigned int IfcSpfLexer::skipWhitespace() { return index; } -unsigned int IfcSpfLexer::skipComment() { +unsigned int IfcSpfLexer::skipComment() const { char character = stream->Peek(); if (character != '/') { return 0; @@ -376,7 +376,7 @@ Token IfcSpfLexer::Next() { return t; } -bool IfcSpfStream::is_eof_at(unsigned int local_ptr) { +bool IfcSpfStream::is_eof_at(unsigned int local_ptr) const { return local_ptr >= len_; } @@ -646,7 +646,7 @@ std::string TokenFunc::asString(const Token& token) { boost::dynamic_bitset<> TokenFunc::asBinary(const Token& token) { const std::string& str = asStringRef(token); - if (str.size() < 1) { + if (str.empty()) { throw IfcException("Token is not a valid binary sequence"); } @@ -716,7 +716,7 @@ void IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::enti try { parse_context ps; load(0, nullptr, ps, -1); - auto decl = schema_->declaration_by_name(TokenFunc::asStringRef(next)); + const auto *decl = schema_->declaration_by_name(TokenFunc::asStringRef(next)); auto* simple_type_instance = schema_->instantiate(decl, ps.construct(-1, references_to_resolve, decl)); //@todo decide addEntity(((IfcUtil::IfcBaseClass*)*entity)); context.push(simple_type_instance); @@ -748,7 +748,7 @@ IfcEntityInstanceData IfcParse::read(unsigned int i, IfcFile* f) { return IfcEntityInstanceData(pc.construct(i, f->references_to_resolve, ty)); } -void IfcParse::IfcFile::try_read_semicolon() { +void IfcParse::IfcFile::try_read_semicolon() const { unsigned int old_offset = tokens->stream->Tell(); Token semilocon = tokens->Next(); if (!TokenFunc::isOperator(semilocon, ';')) { @@ -799,7 +799,7 @@ namespace { // The REAL token definition from the IFC SPF standard does not necessarily match // the output of the C++ ostream formatting operation. // REAL = [ SIGN ] DIGIT { DIGIT } "." { DIGIT } [ "E" [ SIGN ] DIGIT { DIGIT } ] . - std::string format_double(const double& d) { + static std::string format_double(const double& d) { std::ostringstream oss; oss.imbue(std::locale::classic()); oss << std::setprecision(std::numeric_limits::digits10) << d; @@ -821,7 +821,7 @@ namespace { return oss.str(); } - std::string format_binary(const boost::dynamic_bitset<>& b) { + static std::string format_binary(const boost::dynamic_bitset<>& b) { std::ostringstream oss; oss.imbue(std::locale::classic()); oss.put('"'); @@ -906,8 +906,8 @@ namespace { } data_ << ")"; } - void operator()(const empty_aggregate_t&) const { data_ << "()"; } - void operator()(const empty_aggregate_of_aggregate_t&) const { data_ << "()"; } + void operator()(const empty_aggregate_t& /*unused*/) const { data_ << "()"; } + void operator()(const empty_aggregate_of_aggregate_t& /*unused*/) const { data_ << "()"; } }; template <> @@ -1428,8 +1428,6 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) { } references_to_resolve.clear(); - - return; } void IfcFile::recalculate_id_counter() { @@ -1969,7 +1967,7 @@ namespace { template void visit_subtypes(const IfcParse::entity* ent, Fn fn) { fn(ent); - for (auto& st : ent->subtypes()) { + for (const auto& st : ent->subtypes()) { visit_subtypes(st, fn); } } @@ -1985,7 +1983,7 @@ namespace { aggregate_of_instance::ptr IfcFile::instances_by_type(const IfcParse::declaration* t) { aggregate_of_instance::ptr insts(new aggregate_of_instance); - if (t->as_entity()) { + if (t->as_entity() != nullptr) { visit_subtypes(t->as_entity(), [this, &insts](const IfcParse::entity* ent) { auto it = bytype_excl_.find(ent); if (it != bytype_excl_.end()) { @@ -2096,7 +2094,7 @@ std::ostream& operator<<(std::ostream& out, const IfcParse::IfcFile& file) { return out; } -std::string IfcFile::createTimestamp() const { +std::string IfcFile::createTimestamp() { char buf[255]; time_t t; @@ -2104,7 +2102,7 @@ std::string IfcFile::createTimestamp() const { struct tm* ti = localtime(&t); - std::string result = ""; + std::string result; if (strftime(buf, 255, "%Y-%m-%dT%H:%M:%S", ti) != 0U) { result = std::string(buf); } @@ -2194,8 +2192,10 @@ size_t IfcFile::getTotalInverses(int instance_id) { } void IfcFile::setDefaultHeaderValues() { - const std::string empty_string = ""; - std::vector file_description, schema_identifiers, empty_vector; + const std::string empty_string; + std::vector file_description; + std::vector schema_identifiers; + std::vector empty_vector; file_description.push_back("ViewDefinition [CoordinationView]"); if (schema() != nullptr) { @@ -2311,8 +2311,8 @@ void IfcUtil::IfcBaseClass::unset_attribute_value(size_t index) { void IfcUtil::IfcBaseClass::toString(std::ostream& out, bool upper) const { - auto ent = declaration().as_entity(); - if (ent) { + const auto *ent = declaration().as_entity(); + if (ent != nullptr) { out << "#" << as()->id() << "="; } if (upper) { diff --git a/src/ifcparse/IfcParse.h b/src/ifcparse/IfcParse.h index c24488cb59..10b26630ed 100644 --- a/src/ifcparse/IfcParse.h +++ b/src/ifcparse/IfcParse.h @@ -148,8 +148,8 @@ Token NoneTokenPtr(); class IFC_PARSE_API IfcSpfLexer { private: IfcCharacterDecoder* decoder_; - unsigned int skipWhitespace(); - unsigned int skipComment(); + unsigned int skipWhitespace() const; + unsigned int skipComment() const; public: std::string& GetTempString() const { diff --git a/src/ifcparse/IfcSpfHeader.cpp b/src/ifcparse/IfcSpfHeader.cpp index 7160d942c3..0cef9e3dfd 100644 --- a/src/ifcparse/IfcSpfHeader.cpp +++ b/src/ifcparse/IfcSpfHeader.cpp @@ -50,9 +50,9 @@ namespace { } HeaderEntity::HeaderEntity(const char* const datatype, size_t size, IfcFile* file) - : data_(file ? read_from_file(file, size) : IfcEntityInstanceData(storage_t(size))) - , datatype_(datatype) + : datatype_(datatype) , file_(file) + , data_(file ? read_from_file(file, size) : IfcEntityInstanceData(storage_t(size))) {} HeaderEntity::~HeaderEntity() { diff --git a/src/ifcparse/IfcSpfStream.h b/src/ifcparse/IfcSpfStream.h index 4aa73d375c..dda8742d5c 100644 --- a/src/ifcparse/IfcSpfStream.h +++ b/src/ifcparse/IfcSpfStream.h @@ -71,9 +71,9 @@ class IFC_PARSE_API IfcSpfStream { /// Moves the file cursor to an arbitrary offset in the file void Seek(unsigned int offset); /// Returns the cursor position - unsigned int Tell(); + unsigned int Tell() const; - bool is_eof_at(unsigned int); + bool is_eof_at(unsigned int) const; void increment_at(unsigned int&); char peek_at(unsigned int); }; diff --git a/src/ifcparse/parse_ifcxml.cpp b/src/ifcparse/parse_ifcxml.cpp index d94c19fccb..2dd5eccf71 100644 --- a/src/ifcparse/parse_ifcxml.cpp +++ b/src/ifcparse/parse_ifcxml.cpp @@ -459,7 +459,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs) }; // Create or reference an instance from the file and set attributes based on XML attributes. - auto create_instance = [&state, &attributes, &id](const IfcParse::declaration* decl) { + auto create_instance = [&state, &attributes](const IfcParse::declaration* decl) { boost::optional id; boost::variant rv; @@ -479,7 +479,7 @@ static void start_element(void* user, const xmlChar* tag, const xmlChar** attrs) } } - auto untyped = IfcEntityInstanceData(storage_t(decl->as_entity() ? decl->as_entity()->attribute_count() : 1)); + auto untyped = IfcEntityInstanceData(storage_t(decl->as_entity() != nullptr ? decl->as_entity()->attribute_count() : 1)); const IfcParse::entity* entity = decl->as_entity(); if (entity != nullptr) {