| IOLink 1.11.0

Loading...
Searching...
No Matches
DataFrameView.h
1#pragma once
2
3#include <string>
4
5#include <iolink/DataType.h>
6#include <iolink/FlagSet.h>
7#include <iolink/IOLinkAPI.h>
8#include <iolink/VectorX.h>
9#include <iolink/view/View.h>
10
11 namespace iolink
12{
13
19 enum class DataFrameCapability
20{
21 READ = 0x1,
22 WRITE = 0x2,
23 RESHAPE = 0x4,
24};
25
26 extern template class IOLINK_API_IMPORT FlagSet<DataFrameCapability>;
27
31 using DataFrameCapabilitySet = FlagSet<DataFrameCapability>;
32
33// Define bitwise operators for DataFrameCapability
34IOLINK_DEFINE_ENUM_BITWISE_OPERATORS(DataFrameCapability)
35
36
46class IOLINK_API DataFrameView : public View
47{
48 public:
54 virtual DataFrameCapabilitySet capabilities() const = 0;
55
61 virtual const Vector2u64& shape() const = 0;
62
72 virtual const std::string& columnName(size_t index) const = 0;
73
81 virtual size_t columnIndex(const std::string& name) const = 0;
82
90 virtual DataType columnDataType(size_t index) const = 0;
91
92 // ==== //
93 // READ //
94 // ==== //
95
120 virtual void read(size_t column, size_t offset, size_t count, void* dst) const;
121
134 template <typename T>
135 inline T at(size_t column, size_t row) const
136 {
137 T value;
138 this->read(column, row, 1, &value);
139 return value;
140 }
141
155 template <typename T>
156 inline T at(const std::string& columnName, size_t row) const
157 {
158 return this->at<T>(this->columnIndex(columnName), row);
159 }
160
164 const std::string& unit(size_t columnIndex);
165
166 // ===== //
167 // WRITE //
168 // ===== //
169
194 virtual void write(size_t column, size_t offset, size_t count, const void* src);
195
208 template <typename T>
209 inline void setAt(size_t column, size_t row, T value)
210 {
211 this->write(column, row, 1, &value);
212 }
213
226 template <typename T>
227 inline void setAt(const std::string& columnName, size_t row, T value)
228 {
229 this->setAt<T>(this->columnIndex(columnName), row, value);
230 }
231
235 void setUnit(size_t columnIndex, const std::string& unit);
236
237 // ======= //
238 // RESHAPE //
239 // ======= //
240
255 virtual void addColumn(const std::string& name, DataType dtype);
256
273 virtual void addRows(size_t offset, size_t count);
274
286 virtual void removeColumn(size_t index);
287
300 virtual void removeRows(size_t offset, size_t count);
301
305 std::string toString() const;
306
323 void reshape(const Vector2u64& shape, const std::string* columnNames, const DataType* columnDataTypes);
324};
325
326} // end namespace iolink
iolink::DataFrameView
View to model tabular data.
Definition DataFrameView.h:47
iolink::DataFrameView::at
T at(size_t column, size_t row) const
Get the value stored in a cell of the data frame.
Definition DataFrameView.h:135
iolink::DataFrameView::addRows
virtual void addRows(size_t offset, size_t count)
Insert rows at the specified position.
iolink::DataFrameView::shape
virtual const Vector2u64 & shape() const =0
Return the shape of the data frame.
iolink::DataFrameView::capabilities
virtual DataFrameCapabilitySet capabilities() const =0
Return the view's capabilities.
iolink::DataFrameView::setUnit
void setUnit(size_t columnIndex, const std::string &unit)
Set the unit of the column.
iolink::DataFrameView::columnDataType
virtual DataType columnDataType(size_t index) const =0
Return the data type of the column.
iolink::DataFrameView::columnIndex
virtual size_t columnIndex(const std::string &name) const =0
Get the index of a column from its name.
iolink::DataFrameView::removeRows
virtual void removeRows(size_t offset, size_t count)
Remove a continuous set of rows.
iolink::DataFrameView::setAt
void setAt(size_t column, size_t row, T value)
Set the element value in a cell of the data frame.
Definition DataFrameView.h:209
iolink::DataFrameView::reshape
void reshape(const Vector2u64 &shape, const std::string *columnNames, const DataType *columnDataTypes)
Method to reshape a DataFrame.
iolink::DataFrameView::columnName
virtual const std::string & columnName(size_t index) const =0
Get the name of a column from its index.
iolink::DataFrameView::removeColumn
virtual void removeColumn(size_t index)
Remove a column.
iolink::DataFrameView::write
virtual void write(size_t column, size_t offset, size_t count, const void *src)
Write data into a column.
iolink::DataFrameView::at
T at(const std::string &columnName, size_t row) const
Get the value stored in a cell of the data frame.
Definition DataFrameView.h:156
iolink::DataFrameView::toString
std::string toString() const
Return a string representation.
iolink::DataFrameView::addColumn
virtual void addColumn(const std::string &name, DataType dtype)
Add a column to the dataframe.
iolink::DataFrameView::unit
const std::string & unit(size_t columnIndex)
Return the unit of the column.
iolink::DataFrameView::read
virtual void read(size_t column, size_t offset, size_t count, void *dst) const
Read data from a column.
iolink::DataFrameView::setAt
void setAt(const std::string &columnName, size_t row, T value)
Set the element value in a cell of the data frame.
Definition DataFrameView.h:227
iolink::DataType
Stores information about a data type.
Definition DataType.h:162
iolink::FlagSet
Template class to handle a flags system from an enum.
Definition FlagSet.h:43
iolink::Vector
An arithmetic vector.
Definition Vector.h:37
iolink::View
Interface representing a generic view on data.
Definition View.h:16
iolink
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8
iolink::RandomAccessCapability::READ
@ READ
Data can be read.
iolink::RandomAccessCapability::WRITE
@ WRITE
Data can be written.
iolink::DataFrameCapability
DataFrameCapability
Capabilities of dataframes instances.
Definition DataFrameView.h:20
iolink::DataFrameCapability::RESHAPE
@ RESHAPE
Ability to add or remove columns and rows.