I have a list of types that can be sent over the network, take this example:
enum types { E_T1, E_T2, E_T3, E_T4 };
Now I have a list of classes that correspond to each of the types, let each of them be declared as class E_T1 {...} , class E_T2 {...} , etc.
They are not derived from a common base class , and this cannot be done. Each of the classes has a verification method that I need to call when transmitting data over the network. The client sends data D and an identifier corresponding to the type of message. I need to get an object that matches the type. If necessary, I can use C ++ 0x functions.
I tried using specialized templates for types , while retaining a typedef for the object associated with it. Obviously, this was a stupid idea, since the template parameters should be a compile-time constant, so doing something on getType<data.id()>::type not possible.
Then I tried to use Boost.Variant to get a generic return type like this (used mpl vector to iterate over registered types at runtime for debbuging):
template <typename C> struct getType() { typedef C type; } typedef boost::mpl::vector< getType<E_T1>, getType<E_T2>, getType<E_TX>... > _types; typedef boost::make_variant_over<_types>::type _type;
The problem is that it is limited to 20 entries per default option. This can be rewritten, but from what I understand, the overhead of one type should be taken into account, and we are talking about several thousand types here.
Also tried boost.any, but it does not contain any type information, so the question is again. Does anyone have any good ideas on how to solve this elegantly? Looking for something where I donβt need to write a 1k switch statement anytime I process the type.
All types are displayed in compilation format, the same applies to their respective identifiers. Id -> A type decision must be executed at run time.
Thanks in advance, Robin.