My system defines multiple unordered_map-like data, e.g.
std::unordered_map< int, int> int_map; std::unordered_map< int, double> double_map; std::unordered_map< string, string> string_map; std::unordered_map< string, string> string_map_2; ... std::unordered_map< string, vector<string> > string_string_map; std::unordered_map< string, vector<string> > string_string_map_2; Each map holds different data types. These are used with a framework (written in C) that registers callback functions. The registration function (register_undo_handler) takes two arguments: a pointer to the callback function and data to be passed to the callback. In our case, the data is a map pointer.
//register our callback function to UNDO framework register_undo_handler(clear_data, &int_map); //or : register_undo_handler(clear_data, &string_map); // this is a sketch of the callback function, which frees the map resources void clear_data(void *data) { data->clear(); } If an UNDO happens, the UNDO framework will call each defined callback function, e.g. clear_data, and pass the registered data, cast to void*, as the parameter like this
// For each registered callback function, run with registered parameter (*registered_callback_func)(data); We want to have a single callback function that can free any map. Any suggestion on the implementation?
undo_clear_dataa function template, but why don't you just calldata->clear()directly?std::unordered_map. Please show real codevoid undo_clear_data(void *data) { data->clear(); }hmmm...register_undo_handler?