c++ A Generic Callback object implementation

  actionscript-3, boost, c++, c++11, flash

I have a generic interface of callbacks for c++ written for flash, you can see an example here:
https://github.com/cpzhang/bud/blob/a37348b77fb2722c73d972a77827056b0b2344f6/trunk/tool/flash/ASInterface.inl#L393.

I’m looking for a standard implementation for generic callback like that (in std or in boost), that is not coupled with flash player.
What it does basically is to implement a generic Callback object that can be called with arbitrary number of arguments of primitive types.

typedef std::map<std::wstring, Callback> callbacks;
string functionName = "SomethingHappened";
string xml = "<some xml document/>";
Callbacks::iterator itCallback = callbacks.find(functionName);
if (itCallback != callbacks.end())
    {
        //parse arguments
        std::vector<std::wstring> args;
        _Args::split(xml, args);
        ASValue::Array arguments;
        for (size_t i = 0, s = args.size(); i < s; ++i)
        {
            ASValue arg; arg.FromXML(args[i]);
            arguments.push_back(arg);
        }
        ASValue returnValue;
        //***this is where the magic happens: call the function***
        HRESULT result = itCallback->second.Call(arguments, returnValue);
        return result;
    }

Source: Windows Questions C++

LEAVE A COMMENT