TableRow

Data / Composite

Description

Represents a single row in a Table. Access values by column index or name.

Syntax

TableRow row(rowData, columns)

Parameters

None

Returns

TableRow

Methods

getString(int i)Gets value at column index as string
getString(std::string col)Gets value by column name as string
getInt(int i)Gets value at column index as int
getFloat(int i)Gets value at column index as float
setString(int i, std::string v)Sets value at column index
setInt(int i, int v)Sets value as int
setFloat(int i, float v)Sets value as float

Related

Under the Hood

From Processing.h:

class TableRow { public: std::vector<std::string>* row = nullptr; std::vector<std::string>* cols = nullptr; TableRow() = default; TableRow(std::vector<std::string>& r, std::vector<std::string>& c) : row(&r), cols(&c) {} std::string getString(int i) const { return (row&&i<(int)row->size())?(*row)[i]:""; } std::string getString(const std::string& col) const { if (!cols) return ""; for (int i=0;i<(int)cols->size();i++) if((*cols)[i]==col) return getString(i); return ""; } int getInt(int i) const { auto s=getString(i); return s.empty()?0:std::stoi(s); } int getInt(const std::string& c) const { auto s=getString(c); return s.empty()?0:std::stoi(s); } float getFloat(int i) const { auto s=getString(i); return s.empty()?0:std::stof(s); } float getFloat(const std::string& c)const{ auto s=getString(c); return s.empty()?0:std::stof(s); } void setString(int i, const std::string& v) { if(row&&i<(int)row->size()) (*row)[i]=v; } void setInt(int i, int v) { setString(i, std::to_string(v)); } void setFloat(int i, float v) { setString(i, std::to_string(v)); } };