TTable
Typed Dataframe C++
Install / Use
/learn @ewan15/TTableREADME
TTable
100% Compile time typed dataframe like tables.
What is this?
When accesing columns in a table-like structure we have two options. Create
a generic unordered_map<vector<T>> approach or a struct of type listed below.
struct Table {
std::vector<int> id;
std::vector<std::string> name;
}
Both are problematic.
The first introduces the problem of attempting to get a column which doesn't exist resulting in undefined behaviour. The second introduces the problem of cluttering the namespace with many tables of different types.
TTable attempts to allow users to create tables on the fly and typing checking all inserts and columns. If a column is added midway through the code the column will only exist there and will be unaccessable before.
How to use
Create a table schema
// Create all column types
using id_col = TTable::column<"id", int>;
using name_col = TTable::column<"name", std::string>;
// Create table with columns
auto table = TTable::create_table<id_col, name_col>();
Insert into table
TTable::push_back(table, 5, "test");
Fetch first row
auto row = TTable::get_row(table, 0);
auto id = TTable::get_col_from_row<"id">(row);
auto name = TTable::get_col_from_row<"name">(row);
std::cout << "id: " << id << " name: " << name << std::endl;
Insert new column
using IdCol = TTable::Column<"id", int>;
auto table = TTable::create_table<IdCol>();
// Currently, unable to access age column
using AgeCol = TTable::Column<"age", int>;
auto newTable = TTable::add_column<AgeCol>(table);
// Now age column has been added to the type
Importing with CMake
git clone git@github.com:ewan15/TTable.git
add_subdirectory(TTable)
target_link_libraries(
<Your Project>
TTable
)
Note
More examples in tests.
