Skip to content
Snippets Groups Projects
Commit 591e20ed authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

[tidy1] some improvements to core suggested by clang-tidy ()

Merging branch 'tidy1'  into 'main'.

See merge request !1202
parents b73d8c11 b0302e8e
No related branches found
No related tags found
1 merge request!1202some improvements to core suggested by clang-tidy
Pipeline #83838 passed
Showing
with 56 additions and 66 deletions
...@@ -25,7 +25,10 @@ Checks: '*, ...@@ -25,7 +25,10 @@ Checks: '*,
-*-uppercase-literal-suffix, -*-uppercase-literal-suffix,
-*nodiscard, -*nodiscard,
-abseil-string-find-str-contains, -abseil-string-find-str-contains,
-altera-unroll-loops,
-bugprone-branch-clone, -bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-suspicious-include, -bugprone-suspicious-include,
-cert-err58-cpp, -cert-err58-cpp,
-cert-err61-cpp, -cert-err61-cpp,
...@@ -69,10 +72,10 @@ Checks: '*, ...@@ -69,10 +72,10 @@ Checks: '*,
-performance-noexcept-move-constructor, -performance-noexcept-move-constructor,
-performance-no-automatic-move, -performance-no-automatic-move,
-performance-unnecessary-value-param, -performance-unnecessary-value-param,
-readability-identifier-length,
-readability-misleading-indentation, -readability-misleading-indentation,
-readability-use-anyofallof, -readability-use-anyofallof,
-SectionComment_To_be_manually_checked_from_time_to_time, -SectionComment_To_be_manually_checked_from_time_to_time,
-readability-isolate-declaration, -readability-isolate-declaration,
...@@ -107,6 +110,7 @@ Checks: '*, ...@@ -107,6 +110,7 @@ Checks: '*,
-SectionComment_Temporarily_disabled_checks__We_need_to_investigate_them_one_by_one, -SectionComment_Temporarily_disabled_checks__We_need_to_investigate_them_one_by_one,
-altera-id-dependent-backward-branch,
-bugprone-copy-constructor-init, -bugprone-copy-constructor-init,
-bugprone-exception-escape, -bugprone-exception-escape,
-bugprone-misplaced-widening-cast, -bugprone-misplaced-widening-cast,
...@@ -117,7 +121,7 @@ Checks: '*, ...@@ -117,7 +121,7 @@ Checks: '*,
-google-runtime-references, -google-runtime-references,
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
-modernize-loop-convert, -modernize-loop-convert,
-readability-function-cognitive-complexity,
-SectionComment_Automizable__To_be_kept_satisfied, -SectionComment_Automizable__To_be_kept_satisfied,
*-use-auto, *-use-auto,
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
Frame::Frame(const std::vector<const IAxis*>& axes) Frame::Frame(const std::vector<const IAxis*>& axes)
: m_axes(axes) : m_axes(axes)
, m_size(1)
{ {
m_size = 1;
for (size_t k = 0; k < rank(); ++k) { for (size_t k = 0; k < rank(); ++k) {
ASSERT(axis(k).size() > 0); ASSERT(axis(k).size() > 0);
m_size *= axis(k).size(); m_size *= axis(k).size();
...@@ -55,9 +55,9 @@ std::vector<int> Frame::allIndices(size_t i_flat) const ...@@ -55,9 +55,9 @@ std::vector<int> Frame::allIndices(size_t i_flat) const
size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const
{ {
if (rank() == 1) { if (rank() == 1)
return i_flat; return i_flat;
} else if (rank() == 2) { if (rank() == 2) {
if (k_axis == 0) if (k_axis == 0)
return (i_flat / m_axes[1]->size()) % m_axes[0]->size(); return (i_flat / m_axes[1]->size()) % m_axes[0]->size();
if (k_axis == 1) if (k_axis == 1)
...@@ -65,15 +65,6 @@ size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const ...@@ -65,15 +65,6 @@ size_t Frame::projectedIndex(size_t i_flat, size_t k_axis) const
ASSERT(0); ASSERT(0);
} }
ASSERT(0); ASSERT(0);
/* // generic code for rank>2 currently unused
size_t remainder(i_flat);
for (int k = rank() - 1; k >= 0; --k) {
size_t result = remainder % m_axes[k]->size();
if (k_axis == k)
return result;
remainder /= m_axes[k]->size();
}
*/
} }
size_t Frame::toGlobalIndex(const std::vector<unsigned>& axes_indices) const size_t Frame::toGlobalIndex(const std::vector<unsigned>& axes_indices) const
......
...@@ -50,14 +50,14 @@ double FramUtil::coordinateFromBinf(double value, const IAxis& axis) ...@@ -50,14 +50,14 @@ double FramUtil::coordinateFromBinf(double value, const IAxis& axis)
return result; return result;
} }
void FramUtil::coordinatesToBinf(double& x, double& y, const Frame& data) void FramUtil::coordinatesToBinf(double& x, double& y, const Frame& frame)
{ {
x = coordinateToBinf(x, data.xAxis()); x = coordinateToBinf(x, frame.xAxis());
y = coordinateToBinf(y, data.yAxis()); y = coordinateToBinf(y, frame.yAxis());
} }
void FramUtil::coordinatesFromBinf(double& x, double& y, const Frame& data) void FramUtil::coordinatesFromBinf(double& x, double& y, const Frame& frame)
{ {
x = coordinateFromBinf(x, data.xAxis()); x = coordinateFromBinf(x, frame.xAxis());
y = coordinateFromBinf(y, data.yAxis()); y = coordinateFromBinf(y, frame.yAxis());
} }
...@@ -30,7 +30,7 @@ PointwiseAxis* PointwiseAxis::clone() const ...@@ -30,7 +30,7 @@ PointwiseAxis* PointwiseAxis::clone() const
Bin1D PointwiseAxis::bin(size_t index) const Bin1D PointwiseAxis::bin(size_t index) const
{ {
checkIndex(index); checkIndex(index);
return Bin1D(minary(index), maxary(index)); return {minary(index), maxary(index)};
} }
double PointwiseAxis::min() const double PointwiseAxis::min() const
......
...@@ -32,7 +32,7 @@ DepthProbeElement::DepthProbeElement(double wavelength, double alpha_i, const IA ...@@ -32,7 +32,7 @@ DepthProbeElement::DepthProbeElement(double wavelength, double alpha_i, const IA
m_intensities.resize(z_positions->size(), 0.0); m_intensities.resize(z_positions->size(), 0.0);
} }
DepthProbeElement::DepthProbeElement(DepthProbeElement&& other) DepthProbeElement::DepthProbeElement(DepthProbeElement&& other) noexcept
: IElement(PolMatrices()) : IElement(PolMatrices())
, m_wavelength(other.m_wavelength) , m_wavelength(other.m_wavelength)
, m_alpha_i(other.m_alpha_i) , m_alpha_i(other.m_alpha_i)
......
...@@ -27,9 +27,9 @@ class IAxis; ...@@ -27,9 +27,9 @@ class IAxis;
class DepthProbeElement : public IElement { class DepthProbeElement : public IElement {
public: public:
DepthProbeElement(double wavelength, double alpha_i, const IAxis* z_positions, DepthProbeElement(double wavelength, double alpha_i, const IAxis* z_positions,
bool calculationFlag); bool calculation_flag);
DepthProbeElement(const DepthProbeElement& other) = delete; DepthProbeElement(const DepthProbeElement& other) = delete;
DepthProbeElement(DepthProbeElement&& other); DepthProbeElement(DepthProbeElement&& other) noexcept;
~DepthProbeElement(); ~DepthProbeElement();
......
...@@ -35,6 +35,5 @@ WavevectorInfo WavevectorInfo::makeZeroQ() ...@@ -35,6 +35,5 @@ WavevectorInfo WavevectorInfo::makeZeroQ()
WavevectorInfo WavevectorInfo::transformed(const RotMatrix& transform) const WavevectorInfo WavevectorInfo::transformed(const RotMatrix& transform) const
{ {
return WavevectorInfo(transform.transformed(m_ki), transform.transformed(m_kf), return {transform.transformed(m_ki), transform.transformed(m_kf), m_vacuum_wavelength};
m_vacuum_wavelength);
} }
...@@ -31,7 +31,7 @@ Beam::Beam(double intensity, double wavelength, const Direction& direction) ...@@ -31,7 +31,7 @@ Beam::Beam(double intensity, double wavelength, const Direction& direction)
Beam Beam::horizontalBeam() Beam Beam::horizontalBeam()
{ {
return Beam(1.0, 1.0, {0, 0}); return {1.0, 1.0, {0, 0}};
} }
Beam::~Beam() = default; Beam::~Beam() = default;
......
...@@ -139,12 +139,12 @@ Datafield* DataUtils::Data::importArrayToDatafield(const std::vector<std::vector ...@@ -139,12 +139,12 @@ Datafield* DataUtils::Data::importArrayToDatafield(const std::vector<std::vector
return DataUtils::Array::createPField2D(vec).release(); return DataUtils::Array::createPField2D(vec).release();
} }
std::vector<std::pair<double, double>> DataUtils::Data::FindPeaks(const Datafield& field, std::vector<std::pair<double, double>> DataUtils::Data::FindPeaks(const Datafield& data,
double sigma, double sigma,
const std::string& option, const std::string& option,
double threshold) double threshold)
{ {
std::vector<std::vector<double>> arr = DataUtils::Array::createVector2D(field); std::vector<std::vector<double>> arr = DataUtils::Array::createVector2D(data);
tspectrum::Spectrum2D spec; tspectrum::Spectrum2D spec;
auto peaks = spec.find_peaks(arr, sigma, option, threshold); auto peaks = spec.find_peaks(arr, sigma, option, threshold);
...@@ -156,10 +156,10 @@ std::vector<std::pair<double, double>> DataUtils::Data::FindPeaks(const Datafiel ...@@ -156,10 +156,10 @@ std::vector<std::pair<double, double>> DataUtils::Data::FindPeaks(const Datafiel
double col_value = p.second; double col_value = p.second;
auto xaxis_index = static_cast<size_t>(col_value); auto xaxis_index = static_cast<size_t>(col_value);
size_t yaxis_index = field.yAxis().size() - 1 - static_cast<size_t>(row_value); size_t yaxis_index = data.yAxis().size() - 1 - static_cast<size_t>(row_value);
Bin1D xbin = field.xAxis().bin(xaxis_index); Bin1D xbin = data.xAxis().bin(xaxis_index);
Bin1D ybin = field.yAxis().bin(yaxis_index); Bin1D ybin = data.yAxis().bin(yaxis_index);
double dx = col_value - static_cast<size_t>(col_value); double dx = col_value - static_cast<size_t>(col_value);
double dy = -1.0 * (row_value - static_cast<size_t>(row_value)); double dy = -1.0 * (row_value - static_cast<size_t>(row_value));
......
...@@ -32,7 +32,7 @@ Datafield* importArrayToDatafield(const std::vector<double>& vec); ...@@ -32,7 +32,7 @@ Datafield* importArrayToDatafield(const std::vector<double>& vec);
Datafield* importArrayToDatafield(const std::vector<std::vector<double>>& vec); Datafield* importArrayToDatafield(const std::vector<std::vector<double>>& vec);
//! Returns vector of peak center coordinates, for peaks in given histogram. //! Returns vector of peak center coordinates, for peaks in given histogram.
std::vector<std::pair<double, double>> FindPeaks(const Datafield& hist, double sigma = 2, std::vector<std::pair<double, double>> FindPeaks(const Datafield& data, double sigma = 2,
const std::string& option = {}, const std::string& option = {},
double threshold = 0.05); double threshold = 0.05);
......
...@@ -40,7 +40,7 @@ Datafield::Datafield(const Frame* frame, const std::vector<double>& values, ...@@ -40,7 +40,7 @@ Datafield::Datafield(const Frame* frame, const std::vector<double>& values,
, m_errSigmas(errSigmas) , m_errSigmas(errSigmas)
{ {
ASSERT(m_values.size() == m_frame->size()); ASSERT(m_values.size() == m_frame->size());
ASSERT(m_errSigmas.size() == 0 || m_errSigmas.size() == m_values.size()); ASSERT(m_errSigmas.empty() || m_errSigmas.size() == m_values.size());
} }
Datafield::Datafield(const std::vector<const IAxis*>& axes) Datafield::Datafield(const std::vector<const IAxis*>& axes)
...@@ -59,11 +59,11 @@ Datafield::Datafield(const std::vector<const IAxis*>& axes, const std::vector<do ...@@ -59,11 +59,11 @@ Datafield::Datafield(const std::vector<const IAxis*>& axes, const std::vector<do
{ {
} }
Datafield::~Datafield() {} Datafield::~Datafield() = default;
Datafield* Datafield::clone() const Datafield* Datafield::clone() const
{ {
Datafield* data = new Datafield(m_frame->cloned_axes(), m_values, m_errSigmas); auto* data = new Datafield(m_frame->cloned_axes(), m_values, m_errSigmas);
return data; return data;
} }
...@@ -79,7 +79,7 @@ double Datafield::valAt(size_t i) const ...@@ -79,7 +79,7 @@ double Datafield::valAt(size_t i) const
bool Datafield::hasErrorSigmas() const bool Datafield::hasErrorSigmas() const
{ {
return m_errSigmas.size() > 0; return !m_errSigmas.empty();
} }
const std::vector<double>& Datafield::errorSigmas() const const std::vector<double>& Datafield::errorSigmas() const
......
...@@ -40,7 +40,7 @@ inline size_t ycoord(size_t index, size_t sizeY) ...@@ -40,7 +40,7 @@ inline size_t ycoord(size_t index, size_t sizeY)
} // namespace } // namespace
IDetector::IDetector() {} IDetector::IDetector() = default;
IDetector::IDetector(const IDetector& other) IDetector::IDetector(const IDetector& other)
: INode() : INode()
...@@ -301,15 +301,13 @@ size_t IDetector::detectorIndexToRegionOfInterestIndex(const size_t detectorInde ...@@ -301,15 +301,13 @@ size_t IDetector::detectorIndexToRegionOfInterestIndex(const size_t detectorInde
/* -- IDetector::RoiOfAxis ----------------------------------------------------------- */ /* -- IDetector::RoiOfAxis ----------------------------------------------------------- */
IDetector::RoiOfAxis::RoiOfAxis(const IAxis& axis, double _lower, double _upper) IDetector::RoiOfAxis::RoiOfAxis(const IAxis& axis, double _lower, double _upper)
: lower(_lower)
, upper(_upper)
, lowerIndex(axis.findClosestIndex(lower))
, upperIndex(axis.findClosestIndex(upper))
, roiSize(upperIndex - lowerIndex + 1)
, detectorSize(axis.size())
{ {
lower = _lower;
upper = _upper;
lowerIndex = axis.findClosestIndex(lower);
upperIndex = axis.findClosestIndex(upper);
detectorSize = axis.size();
roiSize = upperIndex - lowerIndex + 1;
} }
/* -- from IDetector2D -- */ /* -- from IDetector2D -- */
......
...@@ -44,13 +44,13 @@ SimulationResult::SimulationResult(const SimulationResult& other) ...@@ -44,13 +44,13 @@ SimulationResult::SimulationResult(const SimulationResult& other)
m_coordsys.reset(other.m_coordsys->clone()); m_coordsys.reset(other.m_coordsys->clone());
} }
SimulationResult::SimulationResult(SimulationResult&& other) SimulationResult::SimulationResult(SimulationResult&& other) noexcept
: m_data(std::move(other.m_data)) : m_data(std::move(other.m_data))
, m_coordsys(std::move(other.m_coordsys)) , m_coordsys(std::move(other.m_coordsys))
{ {
} }
SimulationResult& SimulationResult::operator=(SimulationResult&& other) SimulationResult& SimulationResult::operator=(SimulationResult&& other) noexcept
{ {
m_data = std::move(other.m_data); m_data = std::move(other.m_data);
m_coordsys = std::move(other.m_coordsys); m_coordsys = std::move(other.m_coordsys);
...@@ -121,7 +121,7 @@ std::vector<double> SimulationResult::convertedBinCenters(size_t i_axis, Coords ...@@ -121,7 +121,7 @@ std::vector<double> SimulationResult::convertedBinCenters(size_t i_axis, Coords
if (i_axis >= m_coordsys->rank()) if (i_axis >= m_coordsys->rank())
throw std::runtime_error( throw std::runtime_error(
"Error in SimulationResult::axis: no axis corresponds to passed index."); "Error in SimulationResult::axis: no axis corresponds to passed index.");
auto axis = m_coordsys->createConvertedAxis(i_axis, units); auto* axis = m_coordsys->createConvertedAxis(i_axis, units); // TODO memory leak
return axis->binCenters(); return axis->binCenters();
} }
......
...@@ -36,9 +36,9 @@ public: ...@@ -36,9 +36,9 @@ public:
~SimulationResult(); ~SimulationResult();
SimulationResult(const SimulationResult& other); SimulationResult(const SimulationResult& other);
SimulationResult(SimulationResult&& other); SimulationResult(SimulationResult&& other) noexcept;
SimulationResult& operator=(SimulationResult&& other); SimulationResult& operator=(SimulationResult&& other) noexcept;
std::vector<double> flatVector(Coords units = Coords::UNDEFINED) const; std::vector<double> flatVector(Coords units = Coords::UNDEFINED) const;
Datafield* datafield(Coords units = Coords::UNDEFINED) const; Datafield* datafield(Coords units = Coords::UNDEFINED) const;
......
...@@ -201,7 +201,7 @@ void DataUtils::Format::fillDatafield(Datafield* data, std::istream& input_strea ...@@ -201,7 +201,7 @@ void DataUtils::Format::fillDatafield(Datafield* data, std::istream& input_strea
for (auto value : buffer) for (auto value : buffer)
data->errorSigmas().push_back(value); data->errorSigmas().push_back(value);
} }
if (data->errorSigmas().size() > 0 && data->errorSigmas().size() != data->size()) if (!data->errorSigmas().empty() && data->errorSigmas().size() != data->size())
throw std::runtime_error("Error while parsing data, num errorbars != num values"); throw std::runtime_error("Error while parsing data, num errorbars != num values");
} }
......
...@@ -146,7 +146,7 @@ bool IOFactory::fileTypeMatchesLoaderSelector(const std::string& fileName, Loade ...@@ -146,7 +146,7 @@ bool IOFactory::fileTypeMatchesLoaderSelector(const std::string& fileName, Loade
void IOFactory::writeSimulationResult(const SimulationResult& result, const std::string& file_name) void IOFactory::writeSimulationResult(const SimulationResult& result, const std::string& file_name)
{ {
auto data = result.datafield(); const auto* data = result.datafield();
writeDatafield(*data, file_name); // TODO delete ptr writeDatafield(*data, file_name); // TODO delete ptr
} }
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
//! @param mask_value The value of mask //! @param mask_value The value of mask
void addMask(const IShape2D& shape, bool mask_value); void addMask(const IShape2D& shape, bool mask_value);
bool isMasked(size_t index) const; bool isMasked(size_t i_flat) const;
//! Returns true if has masks //! Returns true if has masks
bool hasMasks() const; bool hasMasks() const;
......
...@@ -37,7 +37,7 @@ DiffuseElement::DiffuseElement(double wavelength, double alpha_i, double phi_i, ...@@ -37,7 +37,7 @@ DiffuseElement::DiffuseElement(double wavelength, double alpha_i, double phi_i,
{ {
} }
DiffuseElement::DiffuseElement(DiffuseElement&& other) DiffuseElement::DiffuseElement(DiffuseElement&& other) noexcept
: IElement(other.m_polMatrices) : IElement(other.m_polMatrices)
, m_wavelength(other.m_wavelength) , m_wavelength(other.m_wavelength)
, m_alpha_i(other.m_alpha_i) , m_alpha_i(other.m_alpha_i)
...@@ -124,7 +124,7 @@ double DiffuseElement::getPhi(double x, double y) const ...@@ -124,7 +124,7 @@ double DiffuseElement::getPhi(double x, double y) const
WavevectorInfo DiffuseElement::wavevectorInfo() const WavevectorInfo DiffuseElement::wavevectorInfo() const
{ {
return WavevectorInfo(getKi(), meanKf(), wavelength()); return {getKi(), meanKf(), wavelength()};
} }
double DiffuseElement::integrationFactor(double x, double y) const double DiffuseElement::integrationFactor(double x, double y) const
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
const SpinMatrix& analyzer, bool isSpecular_, const Fluxes* fluxes_in = nullptr, const SpinMatrix& analyzer, bool isSpecular_, const Fluxes* fluxes_in = nullptr,
const Fluxes* fluxes_out = nullptr); const Fluxes* fluxes_out = nullptr);
DiffuseElement(const DiffuseElement&) = delete; DiffuseElement(const DiffuseElement&) = delete;
DiffuseElement(DiffuseElement&&); DiffuseElement(DiffuseElement&&) noexcept;
~DiffuseElement(); ~DiffuseElement();
void setFluxes(const Fluxes* fluxes_in, const Fluxes* fluxes_out); void setFluxes(const Fluxes* fluxes_in, const Fluxes* fluxes_out);
......
...@@ -19,19 +19,17 @@ ...@@ -19,19 +19,17 @@
SpecularElement SpecularElement::FromQzScan(double kz, const PolMatrices& polMatrices, SpecularElement SpecularElement::FromQzScan(double kz, const PolMatrices& polMatrices,
bool computable) bool computable)
{ {
return SpecularElement(computable, polMatrices, [kz](const SliceStack& slices) { return {computable, polMatrices,
return Compute::Kz::computeKzFromSLDs(slices, kz); [kz](const SliceStack& slices) { return Compute::Kz::computeKzFromSLDs(slices, kz); }};
});
} }
SpecularElement SpecularElement::FromAlphaScan(double wavelength, double alpha, SpecularElement SpecularElement::FromAlphaScan(double wavelength, double alpha,
const PolMatrices& polMatrices, bool computable) const PolMatrices& polMatrices, bool computable)
{ {
return SpecularElement( return {computable, polMatrices,
computable, polMatrices, [k = vecOfLambdaAlphaPhi(wavelength, alpha, 0.0)](const SliceStack& slices) {
[k = vecOfLambdaAlphaPhi(wavelength, alpha, 0.0)](const SliceStack& slices) { return Compute::Kz::computeKzFromRefIndices(slices, k);
return Compute::Kz::computeKzFromRefIndices(slices, k); }};
});
} }
SpecularElement::SpecularElement(bool computable, const PolMatrices& polMatrices, SpecularElement::SpecularElement(bool computable, const PolMatrices& polMatrices,
...@@ -43,7 +41,7 @@ SpecularElement::SpecularElement(bool computable, const PolMatrices& polMatrices ...@@ -43,7 +41,7 @@ SpecularElement::SpecularElement(bool computable, const PolMatrices& polMatrices
{ {
} }
SpecularElement::SpecularElement(SpecularElement&& other) = default; SpecularElement::SpecularElement(SpecularElement&& other) noexcept = default;
SpecularElement::~SpecularElement() = default; SpecularElement::~SpecularElement() = default;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment