Skip to content

Commit

Permalink
early return added and cppcheck fix
Browse files Browse the repository at this point in the history
  • Loading branch information
warunawickramasingha committed Dec 3, 2024
1 parent 86448cc commit 5aca6a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
50 changes: 25 additions & 25 deletions Framework/DataObjects/src/PeakShapeDetectorBinFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ namespace Mantid::DataObjects {
Mantid::Geometry::PeakShape *PeakShapeDetectorBinFactory::create(const std::string &source) const {
Json::Value root;
Mantid::Geometry::PeakShape *peakShape = nullptr;
if (Mantid::JsonHelpers::parse(source, &root)) {
const std::string shape = root["shape"].asString();
if (shape == PeakShapeDetectorBin::detectorBinShapeName()) {
const std::string algorithmName(root["algorithm_name"].asString());
const int algorithmVersion(root["algorithm_version"].asInt());
const auto frame(static_cast<SpecialCoordinateSystem>(root["frame"].asInt()));

std::vector<std::tuple<int32_t, double, double>> detectorBinList;
const Json::Value detectorList = root["detectors"];
for (uint32_t index = 0; index < detectorList.size(); index++) {
const Json::Value detBinVal = detectorList[index];
detectorBinList.emplace_back(detBinVal["detId"].asInt(), detBinVal["startX"].asDouble(),
detBinVal["endX"].asDouble());
}
peakShape = new PeakShapeDetectorBin(detectorBinList, frame, algorithmName, algorithmVersion);
} else {
if (m_successor) {
peakShape = m_successor->create(source);
} else {
throw std::invalid_argument("PeakShapeDetectorBinFactory:: No successor "
"factory able to process : " +
source);
}
}
} else {
if (!Mantid::JsonHelpers::parse(source, &root)) {
throw std::invalid_argument("PeakShapeDetectorBinFactory:: Source JSON for "
"the peak shape is not valid: " +
source);
}

const std::string shape = root["shape"].asString();
if (shape == PeakShapeDetectorBin::detectorBinShapeName()) {
const std::string algorithmName(root["algorithm_name"].asString());
const int algorithmVersion(root["algorithm_version"].asInt());
const auto frame(static_cast<SpecialCoordinateSystem>(root["frame"].asInt()));

std::vector<std::tuple<int32_t, double, double>> detectorBinList;
const Json::Value detectorList = root["detectors"];
for (uint32_t index = 0; index < detectorList.size(); index++) {
const Json::Value detBinVal = detectorList[index];
detectorBinList.emplace_back(detBinVal["detId"].asInt(), detBinVal["startX"].asDouble(),
detBinVal["endX"].asDouble());
}
peakShape = new PeakShapeDetectorBin(detectorBinList, frame, algorithmName, algorithmVersion);
} else {
if (m_successor) {
peakShape = m_successor->create(source);
} else {
throw std::invalid_argument("PeakShapeDetectorBinFactory:: No successor "
"factory able to process : " +
source);
}
}
return peakShape;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ void export_PeakShapeDetectorBin() {
.def("__init__", make_constructor(&createPeakShapeDetectorBin, default_call_policies(),
(arg("detectorBinList"), arg("frame") = SpecialCoordinateSystem::None,
arg("algorithmName") = "", arg("algorithmVersion") = -1)))
.def("__eq__", &PeakShapeDetectorBin::operator==, arg("self"), arg("other"));
.def("__eq__", &PeakShapeDetectorBin::operator==);
}

0 comments on commit 5aca6a1

Please sign in to comment.