|
From: Frank V. C. <fr...@co...> - 2000-10-29 18:26:31
|
Recent check-in includes the ability to declare a function dispatch
table, each member of the table containing a text descriptor and
function address that can be used to direct the appropriate object
method call.
For example (lots of stuff omitted) :
// in A.hpp
class A : public virtual FrameworkEntity
{
DECLARE_METATYPEMEMBERS( A );
public:
int doSomething( int v );
};
// in A.cpp
// Either use macros or create by hand, to define the function
// If using the macro, then just provide the body
// **note the names
DISPATCH_FUNCTION( A, doSomething )
*((int *)ret) = myPointer->doSomething( (int) args[0] );
CLOSE_DISPATCH_FUNCTION;
// Which expands to
static extern "C" void AdoSomething
(
FrameworkEntityPtr aClass,
void **args,
void *ret
)
{
A *myPointer = A::castdown( aClass );
*((int *)ret) = myPointer->doSomething( (int) args[0] );
}
// Then create a dispatch descriptor
DEFINE_DISPATCH_DESCRIPTOR( A, doSomething, doSomething );
// where first arg is class
// second arg is stringified for lookup
// third arg is the method
//
// Create the table to collect all descriptors
OPEN_DISPATCH_TABLE( A )
DEFINE_DISPATCH_ENTRY( A, doSomething )
CLOSE_DISPATCH_TABLE;
DEFINE_METATYPE( A, someid, someversion );
// In user application, the ability will be used to call the method with
// the context of the instance (anA)
int main( void )
{
A anA;
int x(5);
int y(0);
anA.getType()->dispatch(&anA,"doSomething",(void **)&x,(void *)&y);
}
The MetaType method (dispatch) should be in sometime tonight, all the
macros are in.
--
Frank V. Castellucci
http://corelinux.sourceforge.net
OOA/OOD/C++ Standards and Guidelines for Linux
http://PythPat.sourceforge.net
Pythons Pattern Package
|