aerostitch / testnavit

0 stars 0 forks source link

item.priv_data type causes confusion #296

Open aerostitch opened 6 years ago

aerostitch commented 6 years ago

Issue migrated from trac ticket # 1361

component: core | priority: minor

2018-01-04 09:41:16: @mvglasow created the issue


Currently, the priv_data member of struct item is of type void *, allowing map providers to tack any kind of data to their items. Consequently, the following function prototypes take a void * argument:

item_attr_get()
item_attr_rewind()
item_coord_get()
item_coord_rewind()

To add to the confusion, some map providers (notably route and route graph) tack the map rect's private data (a struct map_rect_priv) to each item. Thus, by examining the code, it is very easy to get confused about what is passed in the first argument of the above functions. Also, there doesn't really seem to be a convenient place to document function prototypes to be implemented by another dev.

Suggestion: change the type of priv_data to struct item_priv * and declare it as an incomplete type, to be implemented independently by each map provider.

Map providers who maintain item-specific private structs could then use this type.

If a map provider decides to stick a different struct to their items (as route.c does), this could be solved either by an explicit cast (though that's ugly) or, more elegantly, by doing:

typedef struct item_priv {
    struct map_rect_priv mr_priv;
}

which would be backward-comptaible with existing code.

Not a major issue—Navit still runs, but devs of future map plugins will likely appreciate the clarification (would have saved me a good deal of debugging).

Assigning to myself; I'll take care of it once my current traffic project approaches completion.

aerostitch commented 6 years ago

2018-01-04 09:41:47: @mvglasow changed owner from jkoan to mvglasow (2)

aerostitch commented 6 years ago

2018-01-04 09:41:47: @mvglasow changed component from CI to core