Skip to content

Commit 0c87c51

Browse files
sf1919jclarkeSTFC
andauthored
Bravo team cppcheck set 41 (#38731)
* Fixing knownConditionTrueFalse suppressions in CSGObject * Fix constVariablePointer suppression in ObjCompAssembly * Fix cppcheck suppressions in Acomp - fix knownConditionTrueFalse and invalidContainer suppressions * Fix cppcheck suppressions - Fix erros in fixing Acomp and CSGObjects from previous commits - Fix constParameterReference and constVariablePointer instances in InstrumentDefinitionParser - Remove the shape code from the Structured Detector in InstrumentDefinitionParser. The shape is defined within StructuredDetector.cpp instead (probably a copy/paste error) * Fix cppcheck suppressions in XMLInstrumentParameter - fixed constParameterPointer and stlIfStrFind * Fix oustanding constVariablePointer * Use inline suppression for stlIfStrFind - cppcheck suggests using string::starts_with(). However this breaks functionality because position 0 can be anywhere. Although inefficient the find is necessary as it is. * Use west const more consistently * Change the call to find to starts_with to improve searching * Update Framework/Geometry/src/Instrument/XMLInstrumentParameter.cpp Co-authored-by: James Clarke <139879523+jclarkeSTFC@users.noreply.github.com> * Update Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp Co-authored-by: James Clarke <139879523+jclarkeSTFC@users.noreply.github.com> * Update Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp Co-authored-by: James Clarke <139879523+jclarkeSTFC@users.noreply.github.com> --------- Co-authored-by: James Clarke <139879523+jclarkeSTFC@users.noreply.github.com>
1 parent 0a85071 commit 0c87c51

File tree

8 files changed

+23
-36
lines changed

8 files changed

+23
-36
lines changed

Framework/Geometry/inc/MantidGeometry/Instrument/InstrumentDefinitionParser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class MANTID_GEOMETRY_DLL InstrumentDefinitionParser {
6868
static std::string getNameOfLocationElement(const Poco::XML::Element *pElem, const Poco::XML::Element *pCompElem);
6969

7070
/// Save DOM tree to xml file
71-
void saveDOM_Tree(std::string &outFilename);
71+
void saveDOM_Tree(const std::string &outFilename);
7272

7373
/// Get the applied caching option.
7474
CachingOption getAppliedCachingOption() const;
@@ -189,7 +189,7 @@ class MANTID_GEOMETRY_DLL InstrumentDefinitionParser {
189189
/// elements with \<cuboid\>'s
190190
/// (note for now this will only work for \<cuboid\>'s and when necessary this
191191
/// can be extended).
192-
void adjust(Poco::XML::Element *pElem, std::map<std::string, bool> &isTypeAssembly,
192+
void adjust(Poco::XML::Element *pElem, const std::map<std::string, bool> &isTypeAssembly,
193193
std::map<std::string, Poco::XML::Element *> &getTypeElement);
194194

195195
/// Take as input a \<locations\> element. Such an element is a short-hand
@@ -251,7 +251,7 @@ class MANTID_GEOMETRY_DLL InstrumentDefinitionParser {
251251

252252
/// This method returns the parent appended which its child components and
253253
/// also name of type of the last child component
254-
std::string getShapeCoorSysComp(Geometry::ICompAssembly *parent, Poco::XML::Element *pLocElem,
254+
std::string getShapeCoorSysComp(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
255255
std::map<std::string, Poco::XML::Element *> &getTypeElement,
256256
Geometry::ICompAssembly *&endAssembly);
257257

Framework/Geometry/inc/MantidGeometry/Instrument/XMLInstrumentParameter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class MANTID_GEOMETRY_DLL XMLInstrumentParameter {
7676

7777
/// Returns parameter value as generated using possibly equation expression
7878
/// etc
79-
double createParamValue(Mantid::Kernel::TimeSeriesProperty<double> *logData, const Kernel::TimeROI *) const;
79+
double createParamValue(const Mantid::Kernel::TimeSeriesProperty<double> *logData, const Kernel::TimeROI *) const;
8080

8181
/// when this const equals 1 it means that angle=degree (default) is set in
8282
/// IDF

Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ void InstrumentDefinitionParser::appendLocations(Geometry::ICompAssembly *parent
590590
*
591591
* @param outFilename :: Output filename
592592
*/
593-
void InstrumentDefinitionParser::saveDOM_Tree(std::string &outFilename) {
593+
void InstrumentDefinitionParser::saveDOM_Tree(const std::string &outFilename) {
594594
Poco::XML::DOMWriter writer;
595595
writer.setNewLine("\n");
596596
writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT);
@@ -1320,7 +1320,7 @@ void InstrumentDefinitionParser::createGridDetector(Geometry::ICompAssembly *par
13201320
const Poco::XML::Element *pCompElem, const std::string &filename,
13211321
const Poco::XML::Element *pType) {
13221322

1323-
//-------------- Create a RectangularDetector
1323+
//-------------- Create a GridDetector
13241324
//------------------------------------------------
13251325
std::string name = InstrumentDefinitionParser::getNameOfLocationElement(pLocElem, pCompElem);
13261326

@@ -1545,12 +1545,6 @@ void InstrumentDefinitionParser::createStructuredDetector(Geometry::ICompAssembl
15451545
std::vector<double> xValues;
15461546
std::vector<double> yValues;
15471547

1548-
// The shape!
1549-
// Given that this leaf component is actually an assembly, its constituent
1550-
// component detector shapes comes from its type attribute.
1551-
const std::string shapeType = pType->getAttribute("type");
1552-
std::shared_ptr<Geometry::IObject> shape = mapTypeNameToShape[shapeType];
1553-
15541548
std::string typeName = pType->getAttribute("name");
15551549
// These parameters are in the TYPE defining StructuredDetector
15561550
if (pType->hasAttribute("xpixels"))
@@ -2327,7 +2321,7 @@ void InstrumentDefinitionParser::setLogfile(const Geometry::IComponent *comp, co
23272321
unsigned long numberPoint = pNLpoint->length();
23282322

23292323
for (unsigned long j = 0; j < numberPoint; j++) {
2330-
auto *pPoint = static_cast<Element *>(pNLpoint->item(j));
2324+
const auto *pPoint = static_cast<Element *>(pNLpoint->item(j));
23312325
double x = attrToDouble(pPoint, "x");
23322326
double y = attrToDouble(pPoint, "y");
23332327
interpolation->addPoint(x, y);
@@ -2637,7 +2631,7 @@ void InstrumentDefinitionParser::createNeutronicInstrument() {
26372631
* @throw InstrumentDefinitionError Thrown if issues with the content of XML
26382632
* instrument file
26392633
*/
2640-
void InstrumentDefinitionParser::adjust(Poco::XML::Element *pElem, std::map<std::string, bool> &isTypeAssembly,
2634+
void InstrumentDefinitionParser::adjust(Poco::XML::Element *pElem, const std::map<std::string, bool> &isTypeAssembly,
26412635
std::map<std::string, Poco::XML::Element *> &getTypeElement) {
26422636
UNUSED_ARG(isTypeAssembly)
26432637
// check if pElem is an element with tag name 'type'
@@ -2674,7 +2668,7 @@ void InstrumentDefinitionParser::adjust(Poco::XML::Element *pElem, std::map<std:
26742668

26752669
// check if a <translate-rotate-combined-shape-to> is defined
26762670
Poco::AutoPtr<NodeList> pNL_TransRot = pElem->getElementsByTagName("translate-rotate-combined-shape-to");
2677-
Element *pTransRot = nullptr;
2671+
const Element *pTransRot = nullptr;
26782672
if (pNL_TransRot->length() == 1) {
26792673
pTransRot = static_cast<Element *>(pNL_TransRot->item(0));
26802674
}
@@ -3056,7 +3050,7 @@ according to pLocElem
30563050
instrument file
30573051
*/
30583052
std::string InstrumentDefinitionParser::getShapeCoorSysComp(Geometry::ICompAssembly *parent,
3059-
Poco::XML::Element *pLocElem,
3053+
const Poco::XML::Element *pLocElem,
30603054
std::map<std::string, Poco::XML::Element *> &getTypeElement,
30613055
Geometry::ICompAssembly *&endAssembly) {
30623056
// The location element is required to be a child of a component element.
@@ -3085,7 +3079,7 @@ std::string InstrumentDefinitionParser::getShapeCoorSysComp(Geometry::ICompAssem
30853079
if (pNL->length() == 0) {
30863080
return pType->getAttribute("name");
30873081
} else if (pNL->length() == 1) {
3088-
auto *pElem = static_cast<Element *>(pNL->item(0));
3082+
const auto *pElem = static_cast<Element *>(pNL->item(0));
30893083
return getShapeCoorSysComp(ass, pElem, getTypeElement, endAssembly);
30903084
} else {
30913085
throw Exception::InstrumentDefinitionError(

Framework/Geometry/src/Instrument/ObjCompAssembly.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ void ObjCompAssembly::testIntersectionWithChildren(Track &testRay,
343343
searchQueue.emplace_back(comp);
344344
}
345345
// Check the physical object intersection
346-
else if (auto *physicalObject = dynamic_cast<IObjComponent *>(comp.get())) {
346+
else if (const auto *physicalObject = dynamic_cast<IObjComponent *>(comp.get())) {
347347
physicalObject->interceptSurface(testRay);
348348
} else {
349349
}

Framework/Geometry/src/Instrument/XMLInstrumentParameter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <boost/regex.hpp>
1919
#include <ctime>
2020
#include <fstream>
21+
#include <string>
22+
#include <string_view>
2123
#include <utility>
2224

2325
namespace Mantid::Geometry {
@@ -89,7 +91,8 @@ XMLInstrumentParameter::XMLInstrumentParameter(std::string logfileID, std::strin
8991
* @throw InstrumentDefinitionError Thrown if issues with the content of XML
9092
*instrument definition file
9193
*/
92-
double XMLInstrumentParameter::createParamValue(TimeSeriesProperty<double> *logData, const Kernel::TimeROI *roi) const {
94+
double XMLInstrumentParameter::createParamValue(const TimeSeriesProperty<double> *logData,
95+
const Kernel::TimeROI *roi) const {
9396
// If this parameter is a <look-up-table> or <formula> return 0.0. Such
9497
// parameter types are
9598
// associated with 'fitting' parameters. In some sense this method should
@@ -143,7 +146,7 @@ double XMLInstrumentParameter::createParamValue(TimeSeriesProperty<double> *logD
143146
}
144147
// Looking for string: "position n", where n is an integer and is a 1-based
145148
// index
146-
else if (m_extractSingleValueAs.find("position") == 0 && m_extractSingleValueAs.size() >= 10) {
149+
else if (m_extractSingleValueAs.starts_with("position") && m_extractSingleValueAs.size() >= 10) {
147150
std::stringstream extractPosition(m_extractSingleValueAs);
148151
std::string dummy;
149152
int position;

Framework/Geometry/src/Math/Acomp.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Order (low first)
162162
if (*ax != *ux)
163163
return (*ux < *ax);
164164
}
165-
return uc != Units.end();
165+
return false;
166166
}
167167

168168
Acomp &Acomp::operator+=(const Acomp &A)
@@ -490,9 +490,8 @@ It requires that the Intersect is the same for both
490490
return -1;
491491

492492
if (!A.Units.empty()) {
493-
auto Ept = Units.end();
494493
Units.resize(Units.size() + A.Units.size());
495-
copy(A.Units.begin(), A.Units.end(), Ept);
494+
copy(A.Units.begin(), A.Units.end(), back_inserter(Units));
496495
std::sort(Units.begin(), Units.end());
497496
}
498497

Framework/Geometry/src/Objects/CSGObject.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ double coneSolidAngle(const V3D &observer, const Mantid::Kernel::V3D &centre, co
140140
double z0(0.0), z1(z_step);
141141
double r0(radius), r1(r0 - r_step);
142142

143+
// cppcheck-suppress knownConditionTrueFalse as although Cone::g_NSTACKS is currently set at 1 if this changes this
144+
// code block would stop working
143145
for (int st = 1; st < Cone::g_NSTACKS; ++st) {
144146
for (int sl = 0; sl < Cone::g_NSLICES; ++sl) {
145147
int vertex = sl;
@@ -317,6 +319,8 @@ double cylinderSolidAngle(const V3D &observer, const V3D &centre, const V3D &axi
317319
double z0(0.0), z1(z_step);
318320
double solid_angle(0.0);
319321
for (int st = 1; st <= Cylinder::g_NSTACKS; ++st) {
322+
// cppcheck-suppress knownConditionTrueFalse as although Cylinder::g_NSTACKS is currently set at 1 if this changes
323+
// this code block is necessary
320324
if (st == Cylinder::g_NSTACKS)
321325
z1 = height;
322326

buildconfig/CMake/CppCheck_Suppressions.txt.in

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -513,19 +513,6 @@ constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/CompA
513513
constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/CompAssembly.cpp:405
514514
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/ComponentInfo.cpp:129
515515
knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/ComponentInfoBankHelpers.cpp:113
516-
constParameterReference:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp:593
517-
unreadVariable:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp:1552
518-
constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp:2330
519-
constParameterReference:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp:2640
520-
constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp:2677
521-
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/InstrumentDefinitionParser.cpp:3059
522-
constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/ObjCompAssembly.cpp:346
523-
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/XMLInstrumentParameter.cpp:92
524-
stlIfStrFind:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Instrument/XMLInstrumentParameter.cpp:146
525-
knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Math/Acomp.cpp:165
526-
invalidContainer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Math/Acomp.cpp:495
527-
knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Objects/CSGObject.cpp:143
528-
knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Objects/CSGObject.cpp:320
529516
constVariableReference:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Rendering/RenderingHelpersOpenGL.cpp:204
530517
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Rendering/vtkGeometryCacheReader.cpp:64
531518
constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/Geometry/src/Rendering/vtkGeometryCacheWriter.cpp:83

0 commit comments

Comments
 (0)