pgRouting / pgrouting

Repository contains pgRouting library. Development branch is "develop", stable branch is "master"
https://pgrouting.org
GNU General Public License v2.0
1.14k stars 364 forks source link

Use C++ template to get the data from postgres #2494

Closed cvvergara closed 5 months ago

cvvergara commented 1 year ago

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:

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:

There might be some more places where template can be used, but is not related with this particular issue