I am in this very boring part in developing my library, where I want to build a class based on the Windows message id and arguments WPARAMand LPARAM. The prototype of such functions is trivial:
boost::shared_ptr<EventArgs>(const UINT& _id, const WPARAM& _w, const LPARAM& _l);
For each message box, I will have such a function.
Now what I'm doing now, use the FastDelegate library to execute your delegates. They are saved on the map as follows:
typedef fastdelegate::FastDelegate3<const UINT&, const WPARAM&, const LPARAM&, boost::shared_ptr<EventArgs> > delegate_type;
typedef std::map<int, delegate_type> CreatorMap;
And when a Windows message needs to have the EventArg-derived class created, this is a simple case of finding the appropriate delegate, calling it and returning the newly created instance contained in shared_ptr.
boost::shared_ptr<EventArgs> make(const UINT& _id, const WPARAM& _w, const LPARAM& _l) const
{
MsgMap::const_iterator cit(m_Map.find(_id));
assert(cit != m_Map.end());
boost::shared_ptr<EventArgs> ret(cit->second(_w, _l));
return ret;
};
. , , ++ 0x? , :
typedef std::map<int, std::function<boost::shared_ptr<EventArgs>(const WPARAM&, const LPARAM&)> > MapType;
typedef MapType::iterator mit;
MapType map;
map[WM_WHATEVER] = [](const WPARAM& _w, const LPARAM& _l) { };
map[WM_ANOTHER] = ....;
, :
mit m = map.find(WM_PAINT);
boost::shared_ptr<EventArgs> e(m->second(_wParam, _lParam));
lambdas ? , / ( int), wndProc ++, . , lambdas , , , , , :) , , gotchas/-, ?