
Dear, I need to handle a protocol defined with Protocol Buffers. My messages are defined as: enum EMessages { E_MSG_METHOD_CONNECT = 0x8001, E_MSG_EVENT_CONNECT = 0xA001, ... } struct MsgHeader { long sessionRef; long transactionId; long status; } struct MSG_METHOD_CONNECT { Messages opCode; MsgHeader header; .. other fields .. } Now, I defined an interface and a template class to add a level of indirection.. class IMessage { virtual INT getOpCode() = 0; virtual STRING getName() = 0; virtual size_t getSize() = 0; .... } template<class MESSAGE> class IMessageImpl : public IMessage { protected: MESSAGE m_Message; ///< The Message Implementation public: virtual MESSAGE& getMessage() = 0; }; Where I'll use IMessageImpl<MSG_METHOD_CONNECT> MsgConnect; Now, the problem in this situation is to build the correct message class on the receiving part, knowing only the Message opCode. I would like to manage the messages with a type list or map, but I'm a newbie in MPL... Is there a way to define something like this: boost::mpl::map<int, MESSAGE> where the key is the Message opCode and the MESSAGE is the message type? The idea was born reading this article: http://blog.florindinu.ro/posts/message-dispatching-in-c-part-1-type-lists.h... Thanks in advance, Daniele.