Re: how to implement MAP<std::string,TYPE>
Oscar wrote:
client server
"foo" -> CFooCmd cmd; cmd.run();
"bar" -> CBarCmd cmd; cmd.run();
This is another message handler problem. You need a base class for
handling a message. Then you need a table from the string these
handlers (or factories).
If you have already-existing, unrelated classes then you write adapters
for them that derive from the base class.
class Handler
{
public:
virtual ~Handler();
virtual handleMessage( /* parameters */ ) = 0; // might be const
member
// but you need consistency. so if it never changes state of
handler
// make it const. if it sometimes does do not make it const.
};
class HandlerUsesFoo : public Handler // override handleMessage to use
Foo in its implementation
class HandlerUsesBar : public Handler // override handleMessage to use
Bar in its implementation.
It's then a matter of how you want to get the handlers into the table.
There are ways to do this keeping the model extensible. Have the table
global (possibly singleton but not necessarily). Have a loader class
that pulls in your handlers from a config.
My own preference is not to use globals and prefer the object-loader
approach.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]