Skip to content

Commit

Permalink
clang-tidy: add more modernize-* checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHu committed Apr 10, 2024
1 parent 2f0b743 commit 8f1c0e2
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 50 deletions.
17 changes: 9 additions & 8 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
---
Checks: "-*, \
modernize-deprecated-headers, \
modernize-make-shared, \
modernize-make-unique, \
modernize-redundant-void-arg, \
modernize-use-auto, \
modernize-use-equals-default, \
modernize-use-nullptr, \
modernize-use-using, \
modernize-*, \
-modernize-avoid-c-arrays, \
-modernize-pass-by-value, \
-modernize-use-trailing-return-type, \
performance-faster-string-find, \
performance-for-range-copy, \
performance-inefficient-string-concatenation, \
performance-trivially-destructible, \
readability-delete-null-pointer, \
readability-duplicate-include, \
readability-string-compare"

CheckOptions:
- key: modernize-use-override.IgnoreDestructors
value: true

FormatStyle: file
HeaderFilterRegex: 'include/.*.hh'
1 change: 0 additions & 1 deletion include/RMGEventAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

class RMGRunAction;
class G4GenericMessenger;
class RMGVOutputManager;
class RMGEventAction : public G4UserEventAction {

public:
Expand Down
2 changes: 1 addition & 1 deletion include/RMGHardware.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RMGHardware : public G4VUserDetectorConstruction {

void RegisterDetector(DetectorType type, const std::string& pv_name, int uid, int copy_nr = 0);
inline const auto& GetDetectorMetadataMap() { return fDetectorMetadata; }
inline const auto& GetDetectorMetadata(std::pair<std::string, int> det) {
inline const auto& GetDetectorMetadata(const std::pair<std::string, int>& det) {
return fDetectorMetadata.at(det);
}
inline const auto& GetActiveDetectorList() { return fActiveDetectors; }
Expand Down
2 changes: 1 addition & 1 deletion include/RMGHardwareMessenger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RMGHardwareMessenger : public G4UImessenger {
RMGHardwareMessenger(RMGHardware* hw);
~RMGHardwareMessenger();

void SetNewValue(G4UIcommand* command, G4String newValues);
void SetNewValue(G4UIcommand* command, G4String newValues) override;

private:

Expand Down
6 changes: 3 additions & 3 deletions include/RMGMasterGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RMGMasterGenerator : public G4VUserPrimaryGeneratorAction {

inline RMGVGenerator* GetGenerator() { return fGeneratorObj.get(); }
inline RMGVVertexGenerator* GetVertexGenerator() { return fVertexGeneratorObj.get(); }
inline Confinement GetConfinement() const { return fConfinement; }
[[nodiscard]] inline Confinement GetConfinement() const { return fConfinement; }

void SetConfinement(Confinement code);
void SetConfinementString(std::string code);
Expand All @@ -65,10 +65,10 @@ class RMGMasterGenerator : public G4VUserPrimaryGeneratorAction {

private:

Confinement fConfinement;
Confinement fConfinement{RMGMasterGenerator::Confinement::kUnConfined};
std::unique_ptr<RMGVVertexGenerator> fVertexGeneratorObj;

Generator fGenerator;
Generator fGenerator{RMGMasterGenerator::Generator::kUndefined};
std::unique_ptr<RMGVGenerator> fGeneratorObj;

std::unique_ptr<G4GenericMessenger> fMessenger;
Expand Down
1 change: 0 additions & 1 deletion include/RMGPhysics.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "G4VModularPhysicsList.hh"
#include "globals.hh"

class RMGProcessesMessenger;
class RMGPhysics : public G4VModularPhysicsList {

public:
Expand Down
2 changes: 1 addition & 1 deletion include/RMGRun.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RMGRun : public G4Run {

using TimePoint = std::chrono::time_point<std::chrono::system_clock>;

inline const TimePoint& GetStartTime() const { return fStartTime; }
[[nodiscard]] inline const TimePoint& GetStartTime() const { return fStartTime; }
inline void SetStartTime(TimePoint t) { fStartTime = t; }

private:
Expand Down
4 changes: 2 additions & 2 deletions include/RMGTrackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class RMGTrackingAction : public G4UserTrackingAction {
RMGTrackingAction(RMGTrackingAction&&) = delete;
RMGTrackingAction& operator=(RMGTrackingAction&&) = delete;

virtual void PreUserTrackingAction(const G4Track*) override;
virtual void PostUserTrackingAction(const G4Track*) override;
void PreUserTrackingAction(const G4Track*) override;
void PostUserTrackingAction(const G4Track*) override;
inline G4TrackingManager* GetTrackingManager() {
return G4UserTrackingAction::fpTrackingManager;
};
Expand Down
2 changes: 1 addition & 1 deletion include/RMGVVertexGenerator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RMGVVertexGenerator {
inline int GetMaxAttempts() { return fMaxAttempts; }

#if RMG_HAS_BXDECAY0
inline void ShootVertex(G4ThreeVector& v) { GenerateVertex(v); }
inline void ShootVertex(G4ThreeVector& v) override { GenerateVertex(v); }
#endif

protected:
Expand Down
10 changes: 5 additions & 5 deletions include/RMGVertexConfinement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ class RMGVertexConfinement : public RMGVVertexGenerator {
SampleableObjectCollection() = default;
inline ~SampleableObjectCollection() { data.clear(); }

const SampleableObject& SurfaceWeightedRand() const;
const SampleableObject& VolumeWeightedRand() const;
bool IsInside(const G4ThreeVector& point) const;
[[nodiscard]] const SampleableObject& SurfaceWeightedRand() const;
[[nodiscard]] const SampleableObject& VolumeWeightedRand() const;
[[nodiscard]] bool IsInside(const G4ThreeVector& point) const;

// emulate std::vector
size_t size() const { return data.size(); }
[[nodiscard]] size_t size() const { return data.size(); }
SampleableObject& at(size_t i) { return data.at(i); }
void emplace_back(G4VPhysicalVolume* v, const G4RotationMatrix& r, const G4ThreeVector& t,
G4VSolid* s);
inline void push_back(const SampleableObject& obj) {
this->emplace_back(obj.physical_volume, obj.rotation, obj.translation, obj.sampling_solid);
}
inline bool empty() const { return data.empty(); }
[[nodiscard]] inline bool empty() const { return data.empty(); }
inline SampleableObject& back() { return data.back(); }
inline void clear() { data.clear(); }
inline void insert(SampleableObjectCollection& other) {
Expand Down
1 change: 0 additions & 1 deletion include/RMGVertexFromFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "G4GenericMessenger.hh"
#include "G4ThreeVector.hh"

class G4Event;
class G4VAnalysisReader;
class RMGVertexFromFile : public RMGVVertexGenerator {

Expand Down
7 changes: 3 additions & 4 deletions src/RMGGeneratorUtil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ G4ThreeVector RMGGeneratorUtil::rand(const G4VSolid* vol, bool on_surface) {
return RMGGeneratorUtil::rand(dynamic_cast<const G4Tubs*>(vol), on_surface);
else {
RMGLog::OutDev(RMGLog::fatal, "'", entity, "' is not supported (implement me)");
return G4ThreeVector();
return {};
}
}

Expand Down Expand Up @@ -78,10 +78,9 @@ G4ThreeVector RMGGeneratorUtil::rand(const G4Box* box, bool on_surface) {
y = dy * (2 * _g4rand() - 1);
z = dz * (2 * _g4rand() - 1);
}
return G4ThreeVector(x, y, z);
return {x, y, z};
} else {
return G4ThreeVector(dx * (2 * _g4rand() - 1), dy * (2 * _g4rand() - 1),
dz * (2 * _g4rand() - 1));
return {dx * (2 * _g4rand() - 1), dy * (2 * _g4rand() - 1), dz * (2 * _g4rand() - 1)};
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/RMGLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ RMGLog::RMGLog() {
void RMGLog::StartupInfo() {

std::string message = "";
message += " _ __ ___ _ __ ___ __ _ __ _ ___ \n";
message += " | '__/ _ \\ '_ ` _ \\ / _` |/ _` |/ _ \\\n";
message += " | | | __/ | | | | | (_| | (_| | __/\n";
message += " |_| \\___|_| |_| |_|\\__,_|\\__, |\\___| v" + RMGLog::fVersion + "\n";
message += " |___/ \n";
message += R"( _ __ ___ _ __ ___ __ _ __ _ ___ )" "\n";
message += R"( | '__/ _ \ '_ ` _ \ / _` |/ _` |/ _ \)" "\n";
message += R"( | | | __/ | | | | | (_| | (_| | __/)" "\n";
message += R"( |_| \___|_| |_| |_|\__,_|\__, |\___| v)" + RMGLog::fVersion + "\n";
message += R"( |___/ )" "\n";

// write message to screen
if (RMGLog::fMinimumLogLevel <= RMGLog::summary) G4cout << message << G4endl;
Expand Down
4 changes: 1 addition & 3 deletions src/RMGMasterGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@

#include "RMGTools.hh"

RMGMasterGenerator::RMGMasterGenerator()
: fConfinement(RMGMasterGenerator::Confinement::kUnConfined), fVertexGeneratorObj(nullptr),
fGenerator(RMGMasterGenerator::Generator::kUndefined), fGeneratorObj(nullptr) {
RMGMasterGenerator::RMGMasterGenerator() : fVertexGeneratorObj(nullptr), fGeneratorObj(nullptr) {

this->DefineCommands();
}
Expand Down
24 changes: 11 additions & 13 deletions src/remage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,18 @@

#include "magic_enum/magic_enum.hpp"

namespace CLI {
namespace detail {
bool lexical_cast(std::string input, RMGLog::LogLevel& output) {
try {
output = static_cast<RMGLog::LogLevel>(std::stoll(input));
return true;
} catch (...) {
auto r = magic_enum::enum_cast<RMGLog::LogLevel>(input);
if (r.has_value()) output = r.value();
return r.has_value();
}
namespace CLI::detail {
bool lexical_cast(std::string input, RMGLog::LogLevel& output) {
try {
output = static_cast<RMGLog::LogLevel>(std::stoll(input));
return true;
} catch (...) {
auto r = magic_enum::enum_cast<RMGLog::LogLevel>(input);
if (r.has_value()) output = r.value();
return r.has_value();
}
} // namespace detail
} // namespace CLI
}
} // namespace CLI::detail

#include "CLI11/CLI11.hpp"

Expand Down

0 comments on commit 8f1c0e2

Please sign in to comment.