Hi,
I have a set of old classes which I use for inter process communication:
Example:
template class Interface2: public InterfaceBase {
public:
Interface2( const std::string & name,
IPCManager * ipcmanager) :
InterfaceBase(name, ipcmanager){ }
Interface2( const std::string & name,
boost::function _f,
IPCManager * ipcmanager) :
InterfaceBase(name, ipcmanager),
f(_f) { }
virtual ~Interface2() { }
boost::function f;
protected:
void handler(IpcMsg & m) {
if(! f.empty()){
if( m.value_size() != 2 ) {
m.set_type(IpcMsg_Type_RESPONSE_FAILED_WRONG_VALUE_NUMBERS);
return;
}
GMB_ARGUMENT_DESERILIZE(T0, 0);
GMB_ARGUMENT_DESERILIZE(T1, 1);
try {
f(t0, t1);
m.set_type(IpcMsg_Type_RESPONSE_OK);
} catch (std::exception e) {
m.set_type(IpcMsg_Type_RESPONSE_FAILED_EXCEPTION);
}
}else{
m.set_type(IpcMsg_Type_RESPONSE_FAILED_NO_FUNCTION_ATTACHED);
}
}
IPCManager * ipc;
};
It works fine, but it might not be the most elegant solution, and I
would very much like to improve it. Today I have Interface0-10 which
accept from 0 to 10 arguments, and InterfaceCaller0-10 which call an
interface with 0-10 arguments. And another set of classes with an
return value as well.
What I would like is an interface where the following would be valid
(much like boost function):
Interface< int (int, std::string ) > if1(...) ;
I known this might not be easy or the intension of c++99, but I would
like to give it a try anyway...
So, I would appreciate it if somebody could give me some pointers on
how I can process each of the templates arguments.
I do not have access to a c++0x compiler on the target where this is used.
Best regards
Allan W. Nielsen