Use C++ template to get the data from postgres
cvvergara opened this issue · 0 comments
During these last 10 years, work has been done to standardize the code.
These efforts are now at a point where because of this standarization there is duplicated code:
In particular for this issue:
- https://github.com/pgRouting/pgrouting/blob/v3.5.0/src/common/edges_input.c#L86
- https://github.com/pgRouting/pgrouting/blob/v3.5.0/src/common/edges_input.c#L129
- https://github.com/pgRouting/pgrouting/blob/v3.5.0/src/common/matrixRows_input.c#L72
is code that is very similar (aka standardized).
Imagine:
Instead of defining Column_info_t info[3]; ...etc
within the function, is passed as parameter
Then visualize the rest of the code:
the algorithm is the same, things that change is the fetch function that that is called.
More of the imagination:
Instead of defining the fetch function, it is passed as parameter
The result is a C++ template:
template <typename Data_ptr, typename Func>
void get_data(
char *sql,
Data_ptr **pgtuples,
size_t *total_pgtuples,
bool normal,
std::vector<Column_info_t> &info,
Func func)
A call to the function would look like: (after filling up info variable)
pgrouting::get_data(sql, delauny, total_delauny, true, info, &fetch_delauny);
pgrouting::get_data(edges_sql, edges, total_edges, true, info, &fetch_costFlow_edge);
This will:
- Reduce the code base size
- have more code compiled with C++ (even when linked as C)
There might be some more places where template can be used, but is not related with this particular issue