I have a bunch of templates that are used for rpc and was wondering if there is a way to simplify them down as it repeats it self allot. I know varags for templates is coming in the next standard but can you do default values for templates?
Also is there a way to handle void returning functions as normal functions? Atm i have to separate them and treat them as two different things every where due to templates not picking up void as type.
template <typename R>
R functionCall(IPC::IPCClass* c, const char* name)
{
IPC::IPCParameterI* r = c->callFunction( name, false );
return handleReturn<R>(r);
}
template <typename R, typename A>
R functionCall(IPC::IPCClass* cl, const char* name, A a)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a));
return handleReturn<R>(r);
}
template <typename R, typename A, typename B>
R functionCall(IPC::IPCClass* cl, const char* name, A a, B b)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b) );
return handleReturn<R>(r);
}
template <typename R, typename A, typename B, typename C>
R functionCall(IPC::IPCClass* cl, const char* name, A a, B b, C c)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c) );
return handleReturn<R>(r);
}
template <typename R, typename A, typename B, typename C, typename D>
R functionCall(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d) );
return handleReturn<R>(r);
}
template <typename R, typename A, typename B, typename C, typename D, typename E>
R functionCall(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d, E e)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d), IPC::getParameter(e) );
return handleReturn<R>(r);
}
template <typename R, typename A, typename B, typename C, typename D, typename E, typename F>
R functionCall(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d, E e, F f)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d), IPC::getParameter(e), IPC::getParameter(f) );
return handleReturn<R>(r);
}
inline void functionCallV(IPC::IPCClass* cl, const char* name)
{
IPC::IPCParameterI* r = cl->callFunction( name, false );
handleReturnV(r);
}
template <typename A>
void functionCallV(IPC::IPCClass* cl, const char* name, A a)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a));
handleReturnV(r);
}
template <typename A, typename B>
void functionCallV(IPC::IPCClass* cl, const char* name, A a, B b)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b) );
handleReturnV(r);
}
template <typename A, typename B, typename C>
void functionCallV(IPC::IPCClass* cl, const char* name, A a, B b, C c)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c) );
handleReturnV(r);
}
template <typename A, typename B, typename C, typename D>
void functionCallV(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d) );
handleReturnV(r);
}
template <typename A, typename B, typename C, typename D, typename E>
void functionCallV(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d, E e)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d), IPC::getParameter(e) );
handleReturnV(r);
}
template <typename A, typename B, typename C, typename D, typename E, typename F>
void functionCallV(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d, E e, F f)
{
IPC::IPCParameterI* r = cl->callFunction( name, false, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d), IPC::getParameter(e), IPC::getParameter(f) );
handleReturnV(r);
}
inline void functionCallAsync(IPC::IPCClass* cl, const char* name)
{
IPC::IPCParameterI* r = cl->callFunction( name, true );
handleReturnV(r);
}
template <typename A>
void functionCallAsync(IPC::IPCClass* cl, const char* name, A a)
{
IPC::IPCParameterI* r = cl->callFunction( name, true, IPC::getParameter(a));
handleReturnV(r);
}
template <typename A, typename B>
void functionCallAsync(IPC::IPCClass* cl, const char* name, A a, B b)
{
IPC::IPCParameterI* r = cl->callFunction( name, true, IPC::getParameter(a), IPC::getParameter(b) );
handleReturnV(r);
}
template <typename A, typename B, typename C>
void functionCallAsync(IPC::IPCClass* cl, const char* name, A a, B b, C c)
{
IPC::IPCParameterI* r = cl->callFunction( name, true, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c) );
handleReturnV(r);
}
template <typename A, typename B, typename C, typename D>
void functionCallAsync(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d)
{
IPC::IPCParameterI* r = cl->callFunction( name, true, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d) );
handleReturnV(r);
}
template <typename A, typename B, typename C, typename D, typename E>
void functionCallAsync(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d, E e)
{
IPC::IPCParameterI* r = cl->callFunction( name, true, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d), IPC::getParameter(e) );
handleReturnV(r);
}
template <typename A, typename B, typename C, typename D, typename E, typename F>
void functionCallAsync(IPC::IPCClass* cl, const char* name, A a, B b, C c, D d, E e, F f)
{
IPC::IPCParameterI* r = cl->callFunction( name, true, IPC::getParameter(a), IPC::getParameter(b), IPC::getParameter(c), IPC::getParameter(d), IPC::getParameter(e), IPC::getParameter(f) );
handleReturnV(r);
}
extra code as requested:
template <typename R>
R handleReturn(IPC::IPCParameterI* r)
{
if (r->getType() == PException::getTypeS())
{
gcException gce((gcException*)r->getValue());
safe_delete(r);
throw gce;
}
R temp = IPC::getParameterValue<R>(r, true);
safe_delete(r);
return temp;
}
inline void handleReturnV(IPC::IPCParameterI* r)
{
if (r->getType() == PException::getTypeS())
{
gcException gce((gcException*)r->getValue());
safe_delete(r);
throw gce;
}
safe_delete(r);
return;
}