Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0143708
Add validatorT typedef as a std::pair of boost::optional<T> and bool …
adriazalvarez Apr 11, 2025
acfdd0a
Refactor variadic template functions to validate all table fields are…
adriazalvarez Apr 11, 2025
64dfd10
Change boost optional in common classes
adriazalvarez Apr 11, 2025
f32a97b
- Changed boost to std optional in batch classes
adriazalvarez Apr 16, 2025
1865c82
- Changed boost to std optional in decoder/encoder
adriazalvarez Apr 16, 2025
26d36e6
- Changed boost to std optional in experiment and preview classes
adriazalvarez Apr 16, 2025
0af8b3a
- Changed boost to std optional in Runs and RunsTable
adriazalvarez Apr 16, 2025
bc32fdf
- Changed boost to std optional in Reduction
adriazalvarez Apr 16, 2025
ebf5237
- Make tests compatible with changes to std::optional in IsisReflecto…
adriazalvarez Apr 16, 2025
b502d41
- Change more boost optional in ISIS Reflectometry
adriazalvarez Apr 16, 2025
4135c66
- Remove unused allinitialized file
adriazalvarez Apr 16, 2025
54bd449
Fix a bunch of cppcheck suppresions
adriazalvarez Apr 17, 2025
626ebc7
Move TaggetOptional out of validation result
adriazalvarez Apr 25, 2025
1d9cc4e
remove unnecesary include
adriazalvarez Apr 25, 2025
7d104b4
Make sure boost::optional contains values before initializing clipboard
adriazalvarez Apr 25, 2025
b656f83
Move TaggedOptional into ParseReflectometryStrings
adriazalvarez Apr 25, 2025
d6104af
Fix broken scale factor test
adriazalvarez Apr 25, 2025
51d20fc
Remove unnecesary creation of optionals for the row objects and rena…
adriazalvarez Apr 25, 2025
8f83fbb
Add extra check for std::nullopt in parse scale factor test
adriazalvarez Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions buildconfig/CMake/CppCheck_Suppressions.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/WorkflowAlgorithms/src/HFIRLo
unreadVariable:${CMAKE_SOURCE_DIR}/Framework/WorkflowAlgorithms/src/SofTwoThetaTOF.cpp:196
missingOverride:${CMAKE_SOURCE_DIR}/Testing/Tools/cxxtest/cxxtest/GlobalFixture.h:22
constParameterReference:${CMAKE_SOURCE_DIR}/qt/icons/src/Icon.cpp:80
constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/Common/Clipboard.cpp:80
passedByValue:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/Common/OptionDefaults.h:47
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Common/IReflMessageHandler.h:21
constParameterReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Experiment/QtExperimentView.cpp:267
Expand All @@ -544,16 +543,9 @@ constParameterReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflect
constParameterReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/QtInstrumentView.cpp:91
constParameterReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Instrument/QtInstrumentView.cpp:95
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Options/OptionsDialogModel.h:20
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Preview/PreviewModel.h:31
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/IRunsView.h:66
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Runs/QtCatalogSearcher.h:32
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/IRunsTableView.h:31
constVariablePointer:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:510
constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:749
constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:754
constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:785
unreadVariable:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:786
constVariableReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.cpp:788
virtualCallInConstructor:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/RunsTable/RunsTablePresenter.h:60
missingOverride:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/GUI/Save/SaveAlgorithmRunner.h:18
returnByReference:${CMAKE_SOURCE_DIR}/qt/scientific_interfaces/ISISReflectometry/Reduction/Experiment.h:54
Expand Down
37 changes: 19 additions & 18 deletions qt/scientific_interfaces/ISISReflectometry/Common/Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

namespace MantidQt::CustomInterfaces::ISISReflectometry {

Clipboard::Clipboard() : m_subtrees(boost::none), m_subtreeRoots(boost::none) {}
Clipboard::Clipboard() : m_subtrees(std::nullopt), m_subtreeRoots(std::nullopt) {}

Clipboard::Clipboard(boost::optional<std::vector<MantidQt::MantidWidgets::Batch::Subtree>> subtrees,
boost::optional<std::vector<MantidQt::MantidWidgets::Batch::RowLocation>> subtreeRoots)
: m_subtrees(std::move(subtrees)), m_subtreeRoots(std::move(subtreeRoots)) {}
Clipboard::Clipboard(std::vector<MantidQt::MantidWidgets::Batch::Subtree> subtrees,
std::vector<MantidQt::MantidWidgets::Batch::RowLocation> subtreeRoots)
: m_subtrees(std::optional(subtrees)), m_subtreeRoots(std::optional(subtreeRoots)) {}

bool Clipboard::isInitialized() const { return m_subtrees.is_initialized() && m_subtreeRoots.is_initialized(); }
bool Clipboard::isInitialized() const { return m_subtrees.has_value() && m_subtreeRoots.has_value(); }

int Clipboard::numberOfRoots() const {
if (!isInitialized())
Expand Down Expand Up @@ -77,30 +77,30 @@ Group Clipboard::createGroupForRoot(int rootIndex) const {

auto result = Group(groupName(rootIndex));
auto rowsToAdd = createRowsForRootChildren(rootIndex);
for (auto &row : rowsToAdd)
for (auto const &row : rowsToAdd)
result.appendRow(row);
return result;
}

std::vector<boost::optional<Row>> Clipboard::createRowsForAllRoots() const {
std::vector<std::optional<Row>> Clipboard::createRowsForAllRoots() const {
if (containsGroups(*this))
throw std::runtime_error("Attempted to get row for group clipboard item");

auto result = std::vector<boost::optional<Row>>();
auto result = std::vector<std::optional<Row>>();
std::for_each(subtrees().cbegin(), subtrees().cend(), [this, &result](const auto &subtree) {
const auto rowsToAdd = createRowsForSubtree(subtree);
std::copy(rowsToAdd.cbegin(), rowsToAdd.cend(), std::back_inserter(result));
});
return result;
}

std::vector<boost::optional<Row>> Clipboard::createRowsForRootChildren(int rootIndex) const {
std::vector<std::optional<Row>> Clipboard::createRowsForRootChildren(int rootIndex) const {
return createRowsForSubtree(subtrees()[rootIndex]);
}

std::vector<boost::optional<Row>>
std::vector<std::optional<Row>>
Clipboard::createRowsForSubtree(MantidQt::MantidWidgets::Batch::Subtree const &subtree) const {
auto result = std::vector<boost::optional<Row>>();
auto result = std::vector<std::optional<Row>>();

for (auto const &row : subtree) {
// Skip the root item if it is a group
Expand All @@ -111,25 +111,26 @@ Clipboard::createRowsForSubtree(MantidQt::MantidWidgets::Batch::Subtree const &s
std::transform(row.cells().cbegin(), row.cells().cend(), std::back_inserter(cells),
[](MantidQt::MantidWidgets::Batch::Cell const &cell) { return cell.contentText(); });
auto validationResult = validateRow(cells);
if (validationResult.isValid())
if (validationResult.isValid()) {
result.emplace_back(validationResult.assertValid());
else
result.emplace_back(boost::none);
} else {
result.emplace_back(std::nullopt);
}
}

return result;
}

std::vector<MantidQt::MantidWidgets::Batch::Subtree> &Clipboard::mutableSubtrees() { return m_subtrees.get(); }
std::vector<MantidQt::MantidWidgets::Batch::Subtree> &Clipboard::mutableSubtrees() { return m_subtrees.value(); }

std::vector<MantidQt::MantidWidgets::Batch::Subtree> const &Clipboard::subtrees() const { return m_subtrees.get(); }
std::vector<MantidQt::MantidWidgets::Batch::Subtree> const &Clipboard::subtrees() const { return m_subtrees.value(); }

std::vector<MantidQt::MantidWidgets::Batch::RowLocation> const &Clipboard::subtreeRoots() const {
return m_subtreeRoots.get();
return m_subtreeRoots.value();
}

std::vector<MantidQt::MantidWidgets::Batch::RowLocation> &Clipboard::mutableSubtreeRoots() {
return m_subtreeRoots.get();
return m_subtreeRoots.value();
}

bool containsGroups(Clipboard const &clipboard) {
Expand Down
14 changes: 7 additions & 7 deletions qt/scientific_interfaces/ISISReflectometry/Common/Clipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL Clipboard {
};

Clipboard();
Clipboard(boost::optional<std::vector<MantidQt::MantidWidgets::Batch::Subtree>> subtrees,
boost::optional<std::vector<MantidQt::MantidWidgets::Batch::RowLocation>> subtreeRoots);
Clipboard(std::vector<MantidQt::MantidWidgets::Batch::Subtree> subtrees,
std::vector<MantidQt::MantidWidgets::Batch::RowLocation> subtreeRoots);

bool isInitialized() const;
int numberOfRoots() const;
bool isGroupLocation(int rootIndex) const;
std::string groupName(int rootIndex) const;
void setGroupName(int rootIndex, std::string const &groupName);
Group createGroupForRoot(int rootIndex) const;
std::vector<boost::optional<Row>> createRowsForAllRoots() const;
std::vector<std::optional<Row>> createRowsForAllRoots() const;

std::vector<MantidQt::MantidWidgets::Batch::Subtree> const &subtrees() const;
std::vector<MantidQt::MantidWidgets::Batch::Subtree> &mutableSubtrees();
Expand All @@ -44,16 +44,16 @@ class MANTIDQT_ISISREFLECTOMETRY_DLL Clipboard {
private:
// The subtrees for each of the roots. Note that the Rows here contain
// relative paths
boost::optional<std::vector<MantidQt::MantidWidgets::Batch::Subtree>> m_subtrees;
std::optional<std::vector<MantidQt::MantidWidgets::Batch::Subtree>> m_subtrees;
// The actual locations of the roots that were copied. This allows us to work
// out the actual paths that were copied and determine whether items are rows
// or groups in the reflectometry GUI sense. Note that these locations may
// not be valid in the table if other edits have been made so this should
// only be used for checking whether copied values were rows/groups.
boost::optional<std::vector<MantidQt::MantidWidgets::Batch::RowLocation>> m_subtreeRoots;
std::optional<std::vector<MantidQt::MantidWidgets::Batch::RowLocation>> m_subtreeRoots;

std::vector<boost::optional<Row>> createRowsForRootChildren(int rootIndex) const;
std::vector<boost::optional<Row>> createRowsForSubtree(MantidQt::MantidWidgets::Batch::Subtree const &subtree) const;
std::vector<std::optional<Row>> createRowsForRootChildren(int rootIndex) const;
std::vector<std::optional<Row>> createRowsForSubtree(MantidQt::MantidWidgets::Batch::Subtree const &subtree) const;
};

bool MANTIDQT_ISISREFLECTOMETRY_DLL containsGroups(Clipboard const &clipboard);
Expand Down
22 changes: 11 additions & 11 deletions qt/scientific_interfaces/ISISReflectometry/Common/First.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <optional>
#include <vector>

namespace MantidQt {
namespace CustomInterfaces {
namespace ISISReflectometry {

template <typename T> boost::optional<T> first(std::vector<T> const &values) {
if (values.size() > 0)
return boost::optional<T>(values[0]);
else
return boost::none;
template <typename T> std::optional<T> first(std::vector<T> const &values) {
if (values.size() > 0) {
return std::optional<T>(values[0]);
}
return std::nullopt;
}

/**
* Operates on a variant<vector<Ts>...> extracting the first element and
* returning it as a optional<variant<T>> where the optional is empty if
* the vector held by the variant<vector<T>> held no values.
*/
template <typename... Ts> class FirstVisitor : public boost::static_visitor<boost::optional<boost::variant<Ts...>>> {
template <typename... Ts> class FirstVisitor : public boost::static_visitor<std::optional<boost::variant<Ts...>>> {
public:
template <typename T> boost::optional<boost::variant<Ts...>> operator()(std::vector<T> const &values) const {
template <typename T> std::optional<boost::variant<Ts...>> operator()(std::vector<T> const &values) const {
auto value = first(values);
if (value)
if (value) {
return boost::variant<Ts...>(value.get());
else
return boost::none;
}
return std::nullopt;
}
};
} // namespace ISISReflectometry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
#include "Common/First.h"
#include "Common/ValueOr.h"
#include "GetInstrumentParameter.h"
#include <boost/optional.hpp>
#include <optional>
#include <vector>

namespace MantidQt {
namespace CustomInterfaces {
namespace ISISReflectometry {

template <typename T>
boost::optional<T> firstFromParameterFile(Mantid::Geometry::Instrument_const_sptr instrument,
std::string const &parameterName) {
std::optional<T> firstFromParameterFile(Mantid::Geometry::Instrument_const_sptr instrument,
std::string const &parameterName) {
return first(getInstrumentParameter<T>(instrument, parameterName));
}

template <typename... Ts>
boost::optional<boost::variant<Ts...>> firstFromParameterFileVariant(Mantid::Geometry::Instrument_const_sptr instrument,
std::string const &parameterName) {
std::optional<boost::variant<Ts...>> firstFromParameterFileVariant(Mantid::Geometry::Instrument_const_sptr instrument,
std::string const &parameterName) {
auto values = getInstrumentParameter<boost::variant<Ts...>>(instrument, parameterName);
return boost::apply_visitor(FirstVisitor<Ts...>(), values);
}
Expand Down Expand Up @@ -52,18 +52,17 @@ class InstrumentParameters {
return fromFileOrDefaultConstruct<T>(parameterName);
}

template <typename T> boost::optional<T> optional(std::string const &parameterName) {
template <typename T> std::optional<T> optional(std::string const &parameterName) {
return fromFile<T>(parameterName);
}

template <typename Default, typename T>
T handleMandatoryIfMissing(boost::optional<T> const &value, std::string const &parameterName) {
if (value)
return value.get();
else {
m_missingValueErrors.emplace_back(parameterName);
return Default();
T handleMandatoryIfMissing(std::optional<T> const &value, std::string const &parameterName) {
if (value) {
return value.value();
}
m_missingValueErrors.emplace_back(parameterName);
return Default();
}

template <typename T> T mandatory(std::string const &parameterName) {
Expand Down Expand Up @@ -107,12 +106,12 @@ class InstrumentParameters {
return value_or(fromFile<T>(parameterName), T());
}

template <typename T> boost::optional<T> fromFile(std::string const &parameterName) {
template <typename T> std::optional<T> fromFile(std::string const &parameterName) {
try {
return firstFromParameterFile<T>(m_instrument, parameterName);
} catch (InstrumentParameterTypeMissmatch const &ex) {
m_typeErrors.emplace_back(ex);
return boost::none;
return std::nullopt;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <boost/optional.hpp>
#include <boost/variant.hpp>
#include <optional>

namespace MantidQt {
namespace CustomInterfaces {
namespace ISISReflectometry {

// Use TaggedOptional to avoid nested std::optionals in LookupRow validator classes.
// The first pair holds the value of type T held by the optional, while the second pair tags whether the content is in
// a valid state.
template <typename T> using TaggedOptional = std::pair<std::optional<T>, bool>;

template <typename Validated, typename Error = boost::blank> class ValidationResult {
public:
explicit ValidationResult(Validated validItem);
Expand All @@ -22,7 +27,7 @@ template <typename Validated, typename Error = boost::blank> class ValidationRes
bool isError() const;
Validated const &assertValid() const;
Error const &assertError() const;
boost::optional<Validated> validElseNone() const;
std::optional<Validated> validElseNone() const;

private:
boost::variant<Validated, Error> m_innerResult;
Expand Down Expand Up @@ -55,11 +60,11 @@ template <typename Validated, typename Error> Error const &ValidationResult<Vali
}

template <typename Validated, typename Error>
boost::optional<Validated> ValidationResult<Validated, Error>::validElseNone() const {
if (isValid())
std::optional<Validated> ValidationResult<Validated, Error>::validElseNone() const {
if (isValid()) {
return assertValid();
else
return boost::none;
}
return std::nullopt;
}
} // namespace ISISReflectometry
} // namespace CustomInterfaces
Expand Down
Loading