35 "An input workspace.");
37 "An output workspace.");
40 "List of bools for each column: true for ascending order, "
41 "false for descending. "
42 "If contains a single value it applies to all columns.");
50 std::vector<std::string> columns =
getProperty(
"Columns");
51 std::vector<int> ascending =
getProperty(
"Ascending");
53 if (columns.empty()) {
54 throw std::invalid_argument(
"No column names given.");
58 if (ascending.empty()) {
59 ascending.emplace_back(1);
63 if (ascending.size() == 1) {
64 int commonValue = ascending.front();
65 ascending.resize(columns.size(), commonValue);
66 }
else if (ascending.size() != columns.size()) {
67 throw std::invalid_argument(
"Number of sorting options is different form number of columns.");
70 std::vector<std::pair<std::string, bool>> criteria(columns.size());
71 auto col = columns.begin();
72 auto asc = ascending.begin();
73 for (
auto crt = criteria.begin(); crt != criteria.end(); ++crt, ++col, ++asc) {
75 crt->second = (*asc) != 0;
79 outputWS->sort(criteria);
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
SortTableWorkspace : TODO: DESCRIPTION.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void init() override
Initialize the algorithm's properties.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.
@ Output
An output workspace.