Table implementation in C ++

In our C ++ project, I have a need for some unified data structure, I think it should be very similar to an SQL table. I have a set of arrays (std :: vectors) of the same size with different data types. eg:.

time(int), X(double), Y(double), valid(boolean), number_of_measurements(int)

Assuming they look like a table, I need to have equal access to them. For example, I need functionality to insert a row at an arbitrary position in the table, which will cause all rows to shift one element down, kill row. I may need to sort the table by time, combine it with other tables of the same type.

Is there anything similar in the C ++ world?

Basically, I need a universal solution that supports any number of columns and rows. And of course, performance makes sense, so I prefer to do this more in memory than in the database.

UPDATE

I see that many people suggest defining a simple string structure and storing it in a collection. No, this will not fly, because I need to work with columns often. For instance. I may need to multiply the entire column or calculate the average value from it. I can even interpolate it or apply many different algorithms in a specific column.

And I want to avoid the situation when I extract the column for the vector, apply some algorithms on it, and then return it to the structure. It looks ugly, doesn't it?

I need more or less like this:

// Initializing: (three columns: time, X, Y)
table t("time", std::vector<int>(), "X", std::vector<double>(), "Y", std::vector<double>());

// inserting a row
t.insert_row( 1, 20.0f, 20.0f );

// accessing values:
t["time"][10] = 20;

// getting a column:
std::vector<int> time = t["time"];

// sorting
t.sort_by( "time" );

Any thoughts?

+3
4

- SQL-, SQLite. , SQL SELECT, , , SQL. . .

+5
struct Point
{
   int time;
   double X,Y;
   bool valid;
   int number_of_measurements;
};

std::vector<Point> your_table;

: std::vector . "algorithm" std.

EDIT: , ++, "FastDb":

http://www.garret.ru/fastdb.html

( , " ".)

+3

time, X, Y, valid, number_of_measurements. std::vector std::list.

+2

, , , . , . , , , , , .

Better yet, make an abstract string class that defines the interface (for example, getColumn (int index)) that extends with a class that encapsulates this behavior based on the structure. Use the std :: vector class to process a list of these abstract strings and encapsulate it in an abstract table using a simple interface.

Abstraction is your friend here.

0
source

Source: https://habr.com/ru/post/1776876/


All Articles