Reputation: 3
I wrote a remote call procedure wrapper.. On server-side I have some human-readable interface, for example:
template<typename TBase>
class LogicUnit : TBase
{
public:
int getLenFromCalculate(
double antenaForce, const std::string & duration) IMPLEMENTATION;
float calcSomeAlse(
int tableW, float integral) IMPLEMENTATION;
};
From client-side I want use it like this:
#define IMPLEMENTATION TUPLE_FROM_ARGS
#include "logicUnit.h"
#undef
LogicUnit<ClientNetwork> logicUnit;
logicUnit.connect("10.123.123.123", "8080");
logicUnit.getLenFromCalculate( 20.032, "faster" );
In ClientNetwork
I have a helper function:
template< typename ... Args >
bool send( const std::string & funcName, std::tuple<Args...> tuple );
And my question - what can I write in TUPLE_FROM_ARGS-macros? I want something like the following:
define TUPLE_FROM_ARGS send( __FUNCTION__, std::make_tuple( ??????? ) );
Or how I can resolve my problem another way? In this library http://code.google.com/p/simple-rpc-cpp/ used script-generator for create IMPLEMENTATION code. But I think, is it possible by using templates and macros.
Upvotes: 0
Views: 247
Reputation: 3
-- continues my question --
I have definition of class member:
class LogicUnit
{
public:
RPC_FUNC_BEGIN
int getLenFromCalculate(double antenaForce, const std::string & duration);
RPC_FUNC_END
};
On the client-side, it mast be some Implementation, on the server-side, it mast be some another Implementation. For example:
// LogicUnit_c.h
int LogicUnit::getLenFromCalculate( double _1, const std::string & _2 )
{
return send(__COUNTER__, _1, _2);
}
// LogicUnit_s.h
int LogicUnit::getLenFromCalculate( double antenaForce, const std::string & duration )
{
return (int)(duration.length() * antenaForce);
}
If I have many members, I mast write next look-as-template code:
int Foo::fooBar( double _1, int _2 ) { return send(__COUNTER__, _1, _2); }
void Foo::someQwe( double _1, int _2 ) { return send(__COUNTER__, _1, _2); }
int Foo::getParam( const std::string & _1 ) { return send(__COUNTER__, _1); }
void Foo::beNext( int _1, float _2, SMyStruct _3 ) { return send(__COUNTER__, _1, _2, _3); }
I need __PRETTY_FUNCTION__
and something like that:
How to get function signature via preprocessor define written before it?
Upvotes: 0
Reputation: 56863
Looks like you are looking for a variadic macro:
#define TUPLE_FROM_ARGS( ... ) \
send( __FUNCTION__, std::make_tuple( __VA_ARGS__ ) );
It's hard to give good advice if you are so unclear about what you really need. Learn to write good SSCCE's. Anyways, maybe you are looking for this:
template< typename... Args >
int getLenFromCalculate( Args&&... args )
{
send( __FUNCTION__, std::make_tuple( std::forward< Args >( args )... ) );
}
(In the above I don't really see the need for the macro anymore)
Upvotes: 2