14#include "MantidDataObjects/DllConfig.h"
19#include <boost/tuple/tuple.hpp>
26namespace DataObjects {
74 std::unique_ptr<TableWorkspace>
clone()
const {
return std::unique_ptr<TableWorkspace>(doClone()); }
77 std::unique_ptr<TableWorkspace>
cloneEmpty()
const {
return std::unique_ptr<TableWorkspace>(doCloneEmpty()); }
80 const std::string
id()
const override {
return "TableWorkspace"; }
82 size_t getMemorySize()
const override;
84 API::Column_sptr addColumn(
const std::string &type,
const std::string &name)
override;
86 void removeColumn(
const std::string &name)
override;
88 size_t columnCount()
const override {
return static_cast<int>(m_columns.size()); }
98 std::vector<std::string> getColumnNames()
const override;
100 size_t rowCount()
const override {
return m_rowCount; }
116 return pTableCol->
data();
118 throw std::runtime_error(
"TableWorkspace::getColVector(): Can not cast "
119 "to proper TableCol type");
126 return pTableCol->
data();
128 throw std::runtime_error(
"TableWorkspace::getColVector()const: Can not "
129 "cast to proper TableCol type");
139 template <
class T> std::vector<T> &
getColVector(
const std::string &name) {
140 auto ci = std::find_if(m_columns.begin(), m_columns.end(),
FindName(name));
141 if (ci == m_columns.end())
142 throw(std::runtime_error(
"column with name: " + name +
" does not exist"));
145 return pTableCol->
data();
147 throw std::runtime_error(
"TableWorkspace::getColVector(): Can not cast "
148 "to proper TableCol type");
152 template <
class T>
const std::vector<T> &
getColVector(
const std::string &name)
const {
153 auto ci = std::find_if(m_columns.begin(), m_columns.end(),
FindName(name));
154 if (ci == m_columns.end())
155 throw(std::runtime_error(
"column with name: " + name +
" does not exist"));
158 return pTableCol->
data();
160 throw std::runtime_error(
"TableWorkspace::getColVector()const: Can not "
161 "cast to proper TableCol type");
171 auto ci = std::find_if(m_columns.begin(), m_columns.end(),
FindName(name));
172 if (ci == m_columns.end())
188 auto ci = std::find_if(m_columns.begin(), m_columns.end(),
FindName(name));
189 if (ci == m_columns.end())
199 void setRowCount(
size_t count)
override;
202 size_t insertRow(
size_t index)
override;
204 void removeRow(
size_t index)
override;
212 void find(
size_t value,
size_t &row,
size_t col)
override { findValue(
value, row, col); }
219 void find(
const std::string &
value,
size_t &row,
size_t col)
override { findValue(
value, row, col); }
226 void find(
float value,
size_t &row,
size_t col)
override { findValue(
value, row, col); }
240 void find(
double value,
size_t &row,
size_t col)
override { findValue(
value, row, col); }
252 template <
class U> U
cell_cast(
size_t nRow,
size_t nCol)
const {
254 return static_cast<U
>(spCol->operator[](nRow));
256 template <
class U> U
cell_cast(
size_t nRow,
const std::string &col_name)
const {
258 return static_cast<U
>(spCol->operator[](nRow));
262 void sort(std::vector<std::pair<std::string, bool>> &criteria)
override;
273 TableWorkspace *doCloneColumns(
const std::vector<std::string> &colNames)
const override;
276 template <
typename Type>
void findValue(
const Type
value,
size_t &row,
size_t colIndex) {
280 std::vector<Type> dataVec = tc_sptr->data();
281 typename std::vector<Type>::iterator itr;
282 itr = std::find(dataVec.begin(), dataVec.end(),
value);
283 if (itr != dataVec.end()) {
284 std::vector<int>::difference_type pos;
285 pos = std::distance(dataVec.begin(), itr);
287 row =
static_cast<int>(pos);
290 throw std::out_of_range(
"Search object not found in table workspace");
292 }
catch (std::range_error &) {
294 }
catch (std::runtime_error &) {
299 void addColumn(
const std::shared_ptr<API::Column> &column);
307 FindName(
const std::string &name) : m_name(name) {}
309 bool operator()(std::shared_ptr<API::Column> &cp)
const {
return cp->name() == m_name; }
310 bool operator()(
const std::shared_ptr<const API::Column> &cp)
const {
return cp->name() == m_name; }
313 using column_it = std::vector<std::shared_ptr<API::Column>>::iterator;
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
Shared pointer to a column with automatic type cast and data type check.
Class TableColumn implements abstract class Column for any copyable data type.
Type * dataArray()
Pointer to the data array.
std::vector< Type > & data()
Reference to the data.
Used in std::find_if algorithm to find a Column with name name.
bool operator()(std::shared_ptr< API::Column > &cp) const
Comparison operator.
bool operator()(const std::shared_ptr< const API::Column > &cp) const
std::string m_name
Name to find.
FindName(const std::string &name)
Constructor.
TableWorkspace is an implementation of Workspace in which the data are organised in columns of same s...
size_t columnCount() const override
Number of columns in the workspace.
std::vector< std::shared_ptr< API::Column > >::const_iterator column_const_it
U cell_cast(size_t nRow, const std::string &col_name) const
void find(double value, size_t &row, size_t col) override
This method finds the row and column index of an double cell value in a table workspace.
API::LogManager_sptr m_LogManager
shared pointer to the logManager, responsible for the workspace properties.
TableWorkspace * doClone() const override
Virtual clone method. Not implemented to force implementation in children.
size_t rowCount() const override
Number of rows in the workspace.
T * getColDataArray(const std::string &name)
Non-throwing access to the pointer to the column data array for the column with given name.
TableWorkspace & operator=(const TableWorkspace &other)=delete
std::vector< std::shared_ptr< API::Column > >::iterator column_it
Column const iterator.
const std::vector< T > & getColVector(size_t index) const
get constant access to column vector for index i.
void find(size_t value, size_t &row, size_t col) override
This method finds the row and column index of an integer cell value in a table workspace.
std::unique_ptr< TableWorkspace > clone() const
Returns a clone of the workspace.
void findValue(const Type value, size_t &row, size_t colIndex)
template method to find a given value in a table.
std::vector< T > & getColVector(size_t index)
get access to column vector for index i.
std::unique_ptr< TableWorkspace > cloneEmpty() const
Returns a default-initialized clone of the workspace.
TableWorkspace * doCloneEmpty() const override
Virtual cloneEmpty method.
void find(const std::string &value, size_t &row, size_t col) override
This method finds the row and column index of an string cell value in a table workspace.
size_t m_rowCount
row count
API::LogManager_const_sptr getLogs() const override
Get constant access to shared pointer containing workspace porperties.
T * getColDataArray(const std::string &name) const
Non-throwing const access to the pointer to the column data array for the column with given name.
U cell_cast(size_t nRow, size_t nCol) const
Casts cells through converting their values to/from double without type checking; Can produce stuped ...
API::LogManager_sptr logs() override
Get access to shared pointer containing workspace porperties.
void find(API::Boolean value, size_t &row, size_t col) override
This method finds the row and column index of an API::Bollean value in a table workspace.
void find(const Mantid::Kernel::V3D &value, size_t &row, size_t col) override
This method finds the row and column index of an Mantid::Kernel::V3D cell value in a table workspace.
std::vector< std::shared_ptr< API::Column > > m_columns
Shared pointers to the columns.
const std::string id() const override
Return the workspace typeID.
void find(float value, size_t &row, size_t col) override
This method finds the row and column index of an float value in a table workspace.
const std::vector< T > & getColVector(const std::string &name) const
get access to column vector for column with given name
std::vector< T > & getColVector(const std::string &name)
get access to the column vector for column with given name .
std::shared_ptr< const LogManager > LogManager_const_sptr
shared pointer to the logManager base class (const version)
std::shared_ptr< Column > Column_sptr
std::shared_ptr< LogManager > LogManager_sptr
shared pointer to the logManager base class
std::shared_ptr< const Column > Column_const_sptr
Helper class which provides the Collimation Length for SANS instruments.
As TableColumn stores its data in a std::vector bool type cannot be used in the same way as the other...