I currently have an object that implements a complex system for storing and reading configuration objects of several types, that can be easily locally used:
template <typename T>
void rdData(std::string path, T& ref);
template <typename T>
void wrData(std::string path, T& ref);
int value;
rdData("tree1.scalar", value);
struct my_struct;
wrData("tree1", my_struct);
The T type can be a primitive data type, or a POD C Struct defined in a separate file, say legal_structs.c. This file defining structs grow over time, as new structs are added. If a wrong type is used, an exception is thrown.
However, now we want to use the same system concurrently by several other processes. It can be by sockets, RPC or messaging.
Is there a way to determine the type of an object over sockets, as the templates do? For example, the clients will do:
remote_rdData(path, data);
And data will be passed as raw bytes to the server running our system. In the server side, there will need to be a way to identify which data type is it, and call the local template function with the appropriate type. So far, the only way I see is to transmit an object identifier (its type_info, for example), and in the server, have a huge switch comparing type_infos and calling for each object. However, it will need to be appended each time a new struct is added in the system.
Is there a more automatic way to do this reconstruction of objects in the server side?