Mantid
Loading...
Searching...
No Matches
ITableWorkspace.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11namespace Mantid::API {
12
16ITableWorkspace_uptr ITableWorkspace::cloneColumns(const std::vector<std::string> &colNames) const {
17 return ITableWorkspace_uptr(doCloneColumns(colNames));
18}
19
20const std::string ITableWorkspace::toString() const {
21 std::ostringstream os;
22 os << id() << "\n";
23 os << "Columns: " << std::to_string(columnCount()) << "\n";
24 os << "Rows: " << std::to_string(rowCount()) << "\n";
25 os << getMemorySizeAsStr();
26 return os.str();
27}
28
35bool ITableWorkspace::addColumns(const std::string &type, const std::string &name, size_t n) {
36 bool ok = true;
37 for (size_t i = 0; i < n; i++) {
38 std::ostringstream ostr;
39 ostr << name << '_' << i;
40 ok = ok && addColumn(type, ostr.str());
41 }
42 return ok;
43}
44
48 return getRow(rowCount() - 1);
49}
50
56TableColumnHelper ITableWorkspace::getVector(const std::string &name) { return TableColumnHelper(this, name); }
57
63TableConstColumnHelper ITableWorkspace::getVector(const std::string &name) const {
64 return TableConstColumnHelper(this, name);
65}
66
71 if (!AnalysisDataService::Instance().doesExist(this->getName()))
72 return;
74 if (!ws)
75 return;
76 ITableWorkspace_sptr tws = std::dynamic_pointer_cast<ITableWorkspace>(ws);
77 if (!tws)
78 return;
79 AnalysisDataService::Instance().notificationCenter.postNotification(
81}
82
91void ITableWorkspace::sort(std::vector<std::pair<std::string, bool>> &criteria) {
92 UNUSED_ARG(criteria);
93 throw std::runtime_error("This type of ITableWorkspace (" + this->id() +
94 ") has not implemented sort() yet customSort() "
95 "returns true. Please contact the developers.");
96}
97
98} // namespace Mantid::API
99
101namespace Mantid::Kernel {
102template <>
103MANTID_API_DLL API::ITableWorkspace_sptr
104IPropertyManager::getValue<API::ITableWorkspace_sptr>(const std::string &name) const {
105 auto *prop = dynamic_cast<PropertyWithValue<API::ITableWorkspace_sptr> *>(getPointerToProperty(name));
106 if (prop) {
107 return *prop;
108 } else {
109 std::string message =
110 "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<ITableWorkspace>";
111 throw std::runtime_error(message);
112 }
113}
114
115template <>
117IPropertyManager::getValue<API::ITableWorkspace_const_sptr>(const std::string &name) const {
118 auto *prop = dynamic_cast<PropertyWithValue<API::ITableWorkspace_sptr> *>(getPointerToProperty(name));
119 if (prop) {
120 return prop->operator()();
121 } else {
122 std::string message =
123 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<ITableWorkspace>";
124 throw std::runtime_error(message);
125 }
126}
127
128} // namespace Mantid::Kernel
129
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
virtual ITableWorkspace * doCloneColumns(const std::vector< std::string > &colNames) const =0
const std::string id() const override
Return the workspace typeID.
virtual bool addColumns(const std::string &type, const std::string &name, size_t n)
Creates n new columns of the same type.
void modified()
If the workspace is the AnalysisDataService sends AfterReplaceNotification.
ITableWorkspace_uptr cloneColumns(const std::vector< std::string > &colNames) const
Returns a clone of the workspace.
TableRowHelper appendRow()
Appends a row.
virtual void sort(std::vector< std::pair< std::string, bool > > &criteria)
Overridable method to custom-sort the workspace.
virtual size_t insertRow(size_t index)=0
Inserts a row before row pointed to by index and fills it with default vales.
virtual Column_sptr addColumn(const std::string &type, const std::string &name)=0
Creates a new column.
const std::string toString() const override
Serializes the object to a string.
TableRowHelper getRow(size_t row)
Creates a TableRow object for row row.
virtual size_t columnCount() const =0
Number of columns in the workspace.
virtual size_t rowCount() const =0
Number of rows in the workspace.
TableColumnHelper getVector(const std::string &name)
Access the column with name name trough a ColumnVector object.
Helper class used to create ColumnVector.
Helper class used to create ConstColumnVector.
Helper class used to create TableRow.
const std::string & getName() const override
Get the workspace name.
Definition: Workspace.cpp:58
std::string getMemorySizeAsStr() const
Returns the memory footprint in sensible units.
Definition: Workspace.cpp:77
AfterReplaceNotification is sent after an object is replaced in the addOrReplace() function.
Definition: DataService.h:128
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::unique_ptr< ITableWorkspace > ITableWorkspace_uptr
unique pointer to Mantid::API::ITableWorkspace
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::string to_string(const wide_integer< Bits, Signed > &n)