Template Class DataSet

Contents

Template Class DataSet#

Nested Relationships#

Nested Types#

Class Documentation#

template<typename T>
class DataSet#

Table of data.

A class for storing data of some type. It is accessible row-wise and not directly changeble, but columns can be swapped, toggled and restricted. Rows are divided in INPUTs and OUTPUTs, so they can be used in MooViE terms. It can also be parsed from a CSV file.

Author

stratmann

Date

28.11.2017

Public Types

enum ColumnType#

MooViE columns can either represent outputs or inputs. This is indicated by a member of the type ColumnType.

Values:

enumerator INPUT#
enumerator OUTPUT#

Public Functions

inline DataSet()#

Creates an empty DataSet.

inline DataSet(const std::string &fpath)#

Parses a DataSet from a given CSV file. The table must have the form: <input1>[<uniti1>], … , <inputN>[<unitiN>], <output1>[<unito1>], … , <outputM>[<unitoM>] <datai1>, … , <dataiN>, <datao1>, … , <dataoM>

Parameters:

fpath – the CSV file path

void parse_from_csv(const std::string &cont, std::string separator = ",", std::string comment = "#", std::string newline = "\n")#

Returns a data table parsed from a csv encoded string and encapsulated in a DataSet object. The table must have the form: <input1>[<uniti1>], … , <inputN>[<unitiN>], <output1>[<unito1>], … , <outputM>[<unitoM>] <datai1>, … , <dataiN>, <datao1>, … , <dataoM>

Parameters:
  • cont – the csv encoded string

  • num_ins – the number of input variables

  • separator – the column seperator used in this csv string

  • comment – the comment indicator used in this csv string

  • newline – the newline indicator used in this csv string

std::string write_to_csv(std::string separator = ",", std::string newline = "\n")#
inline void toggle_column(std::size_t c, bool mode)#

Enables/disables a column. The DataRows now do not contain the affected Cell anymore.

Parameters:
  • c – the column index

  • mode – set enabled or disabled

Throws:

out_of_range – id c is incorrect

inline void swap_columns(std::size_t c0, std::size_t c1)#

Swaps the two columns with the given index. The DataRows are changed accordingly.

Parameters:
  • c0 – the index of the first column

  • c1 – the index of the second column

Throws:

out_of_bounds – if indices are incorrect

inline void restrict_column(std::size_t c, T l_restr, T u_restr)#

Restricts a column to values in the given interval. The DataRows that contain a Cell not fitting in this interval will be disabled.

Parameters:
  • c – the column index

  • l_restr – lower restriction value

  • u_restr – upper restriction value

Throws:

out_of – range if c is incorrect

inline std::size_t get_num_active_cols() const#

Returns the number of active columns in this table. For every toggled-off column this size decreases by 1.

Returns:

the number of active columns

inline std::size_t get_num_cols() const#

Returns the total number of columns in this table. This includes toggled-off columns.

Returns:

the number of total columns

inline std::size_t get_num_rows() const#

Returns the number of rows in this table.

Returns:

the number of rows

inline std::size_t get_num_active_inputs() const#

Returns the number of active inputs in this table. For every toggled-off column this size decreases by 1.

Returns:

the number of active inputs

inline std::size_t get_num_inputs() const#

Returns the total number of inputs in this table. This includes toggled-off columns.

Returns:

the total number of inputs

inline std::size_t get_num_active_outputs() const#

Returns the number of outputs in this table. For every toggled-off column this size decreases by 1.

Returns:

the number of active outputs

inline std::size_t get_num_outputs() const#

Returns the total number of outputs in this table. This includes toggled-off columns.

Returns:

the total number of outputs

inline const DataRow &operator[](std::size_t i) const#

Returns the row at position i in the table (starting at 0). DataRow can be used like a vector from the given type.

Returns:

the DataRow object

inline std::vector<Variable> input_variables(void) const#

Returns a constant vector containing row (referred to as variables) information like the name and min/max values of the selected row.

Returns:

the input variables

inline std::vector<Variable> output_variables(void) const#

Returns a constant vector containing column (referred to as variables) information like the name and min/max values of the selected row.

Returns:

the output variables

inline const_iterator begin() const#

Returns a constant iterator pointing to the first DataRow.

Returns:

a const_iterator

inline const_iterator end() const#

Returns a constant iterator pointing to the end element of the DataRow storage.

Returns:

a const_iterator

inline std::tuple<std::string, std::string, std::string, std::string> extract_header_entry(const std::string &header) const#

Extracts the variable name and unit from a header entry

Returns:

a pair of strings, the first one is the name, the second one the unit

struct Cell#

Cell of a data table.

Stores the value of a cell. The value is 0 if the Cell is a null cell.

Public Functions

inline Cell()#

Creates a new null Cell.

inline Cell(T value_)#

Creates a new non-null Cell storing the value of T

Public Members

const bool null#

Null or not

const T value#

The value of the cell

class const_iterator : public std::iterator<std::input_iterator_tag, const DataRow>#

Public Functions

inline explicit const_iterator(const typename std::vector<DataRow>::const_iterator &it, const typename std::vector<DataRow>::const_iterator &end)#
inline const_iterator &operator++()#
inline const_iterator operator++(int)#
inline bool operator==(const const_iterator &other) const#
inline bool operator!=(const const_iterator &other) const#
inline const DataRow &operator*() const#
struct DataColumn#

Column of a data table.

DataColumn represents a column of a data set. It has a type (INPUT, OUTPUT), a Variable and a set of cells

Public Functions

inline DataColumn(ColumnType type_, Variable var_)#

Creates a new column with given ColumnType and Variable.

Parameters:
  • type_ – the ColumnType

  • var_ – the Variable

Public Members

const ColumnType type#

The ColumnType

Variable var#

The header information about this column (name, unit, range)

std::vector<Cell> cells#

An array of the cells of this column

class DataRow#

Row of a data table.

DataRow represents a row in this DataSet. A DataRow does not become invalid when column order is changed or a column is disabled. It might get invalid when restricting columns to a certain interval.

Public Functions

inline DataRow(const std::vector<MockColumn> &columns, const std::size_t &enabled_columns, std::size_t offset)#

Creates a DataRow from given reference to the columns and to the number of enabled columns (needed for update) and the row number (aka column offset).

Parameters:
  • columns – a reference to the column array

  • enabled_columns – a reference to the number of enabled columns

  • offset – the row offset

inline const Cell &operator[](std::size_t i) const#

Accesses the i-th Cell of this DataRow.

Parameters:

i – the index

Returns:

the Cell

inline void set_enabled(bool enabled)#

Sets the enabled flag of this MockColumn to the specified value.

Parameters:

enabled – set enabled or not

inline std::size_t size() const#

Returns the size of this MockColumn.

Returns:

the size

inline bool is_enabled() const#

Returns the value of the enabled flag.

Returns:

enabled or not

inline const_iterator begin() const#

Returns a const_iterator pointing to the first cell in this DataRow.

Returns:

the iterator

inline const_iterator end() const#

Returns a const_iterator pointing to the end of this DataRow

Returns:

the iterator

class const_iterator : public std::iterator<std::input_iterator_tag, const Cell>#

Public Functions

inline explicit const_iterator(const typename std::vector<MockColumn>::const_iterator &_it, const typename std::vector<MockColumn>::const_iterator &_end, std::size_t _offset)#
inline const_iterator &operator++()#
inline const_iterator operator++(int)#
inline bool operator==(const const_iterator &other) const#
inline bool operator!=(const const_iterator &other) const#
inline const Cell &operator*() const#
class MockColumn#

Technical column for internal use.

A mock column that is supposed to hold a pointer to the column storage. The DataColumns can be swapped between the MockColumn. MockColumns can be enabled and disabled which alters the number of cells in the DataRows accordingly.

Public Functions

inline MockColumn(DataColumn *column)#

Creates a MockColumn from a DataColumn. This MockColumn wraps and it and provides read-only access to all its components.

Parameters:

_column – the DataColumn

inline const Cell &operator[](std::size_t i) const#

Accesses the i-th Cell in the stored column.

Parameters:

i – the row index

Returns:

the Cell

inline void set_range(double l_restr, double u_restr)#
inline void set_enabled(bool enabled)#

Sets the enabled flag of this MockColumn to the specified value.

Parameters:

enabled – set enabled or not

inline ColumnType get_type() const#

Returns the ColumnType of this MockColumn. It is either INPUT or OUTPUT.

Returns:

the ColumnType

inline Variable get_var() const#

Returns the Variable of this MockColumn.

Returns:

the Variable

inline std::size_t size() const#

Returns the size of this MockColumn.

Returns:

the size

inline bool is_enabled() const#

Returns the value of the enabled flag.

Returns:

enabled or not

Public Static Functions

static inline void swap(MockColumn &m0, MockColumn &m1)#

Class function to swap the columns of two MockColumns.

Parameters:
struct Variable#

Header description.

Variable represents an entity attribute and stores its name, maximal and minimal value.

Public Functions

inline Variable(T min_, T max_, const std::string &name_, const std::string &unit_ = "")#

Creates a Variable with the given name, min and max value.

Parameters:
  • min – the min value

  • max – the max value

  • name – the name

Public Members

T min#

Minimal value

T max#

Maximal value

std::string name#

Variable name

std::string unit#

Unit of the Variables values