I have a transport listener that receives a json object. For this purposes different subscribers will be interested in different properties of the json msg. The problem with that means being able to handle the type of the property dynamically.
I was thinking of having a data structure similar to this to help:
std::unordered_map<std::string,std::vector<std::function<void (T)>>>;
std::unordered_map<std::string,std::vector<T&>>>;
//this doesn't work because I will be forced to have template T on a class template level, bound to the same type which is not what I want.
I was thinking of a union
to encapsulate all possible types but that doesn't sound entirely feasible
How it will be used pseudocode:
void OnJsonObjectReceived(JsonObject msg)
{
auto key = "test_prop";
val = get_value_from_json_msg(key, msg) ;
for(subscriber in _unordered_map.find(key)->subscribers)
{
subscriber = val;
}
}