I’m trying to set up a “coroutine-like” system for a game engine, and am running into trouble finding any way to uniquely identify pointers-to-member-functions in a template function.
I’d like to be able to start & stop coroutines in “Behavior” derived classes by calling CoStart and CoStop methods in the base class that take a pointer to a member function:
CoStart( c_BlinkCycle );
CoStop( c_BlinkCycle );
Where the coroutine methods have a standard signature, e.g.:
CoCommand MyBehavior::c_BlinkCycle( int step ) {
// ...
}
I can use a template in the base class to handle these nicely:
template<typename T>
void CoStart( CoCommand (T::* coMethod)(int) ) {
// ...
}
However, I want to be able to store some metadata for the coroutine methods on their first use (in CoStart()) and have no idea of any kind of unique way of identifying them. I.e.:
if ( !metadataVector.contains( coMethod ) ) {
// ... set up metadata
}
If I could just somehow get the address, or a type ID, or the name, or any kind of unique identifier to the pointer-to-member-function, I’d be set. But with the template, I don’t seem to have have any shared pointer type I could cast those to, so I’m kinda at a loss. (FYI, I’m using boost::function and boost::bind later on, but doesn’t look like they allow comparisons either).
OK, think I’m going to give up on trying to uniquely identify the c_BlinkCycle() type methods intrinsically (unless someone knows a C++ trick to do it), and instead have them return a unqiue ID value when they get a certain special “step” parameter:
A little more boilerplate than I wanted, but not the end of the world.