Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to call function whose function call with arguments is in astring

Reply
Thread Tools

How to call function whose function call with arguments is in astring

 
 
grbgooglefan
Guest
Posts: n/a
 
      01-30-2008
Hello,
Can you please enlighten me if we can do this in C++?

I would like to do something like this:
-----------------------------------------------------------------------------------------------------
typedef struct IOParams {
char *ioString;
long lionum;
double dionum;
float fionum;
int nionum;
} *pIOParams;
typedef std::vector<IOParams> ioparm_vector;
ioparm_vector v_ioparams; <---- This will be populated at startup &
may contain any number of elements.

char *strFunctionCmd =
"myfunctionCall("iiisd",v_ioparams[0].nionum,v_ioparams[1].nionum,v_ioparams[2].nionum,v_ioparams[3].ioString,v_ioparams[4].dionum)";

int retstat = call_function_in_string(strFunctionCmd );
-----------------------------------------------------------------------------------------------------
The vector size could vary, but that is not main issues here.
The problem is that even the variable number arguments function cannot
be used here because for those functions also we need to have the
number & type of arguments fixed at compile time and the input
arguments passed to them are individual variables.

In the above case, variables are part of a vector having variable
size, so writing call for that also is difficult.

Is there any way to achieve this in C++?
Any suggestions please?
Thanks in advance for help.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-30-2008
grbgooglefan wrote:
> Hello,
> Can you please enlighten me if we can do this in C++?
>
> I would like to do something like this:
> -----------------------------------------------------------------------------------------------------
> typedef struct IOParams {
> char *ioString;
> long lionum;
> double dionum;
> float fionum;
> int nionum;
> } *pIOParams;
> typedef std::vector<IOParams> ioparm_vector;
> ioparm_vector v_ioparams; <---- This will be populated at startup &
> may contain any number of elements.
>
> char *strFunctionCmd =
> "myfunctionCall("iiisd",v_ioparams[0].nionum,v_ioparams[1].nionum,v_ioparams[2].nionum,v_ioparams[3].ioString,v_ioparams[4].dionum)";
>
> int retstat = call_function_in_string(strFunctionCmd );
> -----------------------------------------------------------------------------------------------------
> The vector size could vary, but that is not main issues here.
> The problem is that even the variable number arguments function cannot
> be used here because for those functions also we need to have the
> number & type of arguments fixed at compile time and the input
> arguments passed to them are individual variables.
>
> In the above case, variables are part of a vector having variable
> size, so writing call for that also is difficult.
>
> Is there any way to achieve this in C++?
> Any suggestions please?


Take a look at 'boost::any' and 'boost::smart_ptr'. You can have
a vector of any type, essentially, and pass it into your function.
It is entirely possible I've missed the point of your inquiry
altogether, sorry, then.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Pascal Bourguignon
Guest
Posts: n/a
 
      01-30-2008
grbgooglefan <> writes:

> Hello,
> Can you please enlighten me if we can do this in C++?
>
> I would like to do something like this:
> -----------------------------------------------------------------------------------------------------
> typedef struct IOParams {
> char *ioString;
> long lionum;
> double dionum;
> float fionum;
> int nionum;
> } *pIOParams;
> typedef std::vector<IOParams> ioparm_vector;
> ioparm_vector v_ioparams; <---- This will be populated at startup &
> may contain any number of elements.
>
> char *strFunctionCmd =
> "myfunctionCall("iiisd",v_ioparams[0].nionum,v_ioparams[1].nionum,v_ioparams[2].nionum,v_ioparams[3].ioString,v_ioparams[4].dionum)";
>
> int retstat = call_function_in_string(strFunctionCmd );
> -----------------------------------------------------------------------------------------------------
> The vector size could vary, but that is not main issues here.
> The problem is that even the variable number arguments function cannot
> be used here because for those functions also we need to have the
> number & type of arguments fixed at compile time and the input
> arguments passed to them are individual variables.
>
> In the above case, variables are part of a vector having variable
> size, so writing call for that also is difficult.
>
> Is there any way to achieve this in C++?
> Any suggestions please?
> Thanks in advance for help.


You may use ffcall to build a call stack at run-time.
http://www.haible.de/bruno/packages-ffcall.html

--
__Pascal Bourguignon__ http://www.informatimago.com/

ADVISORY: There is an extremely small but nonzero chance that,
through a process known as "tunneling," this product may
spontaneously disappear from its present location and reappear at
any random place in the universe, including your neighbor's
domicile. The manufacturer will not be responsible for any damages
or inconveniences that may result.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
declaring a friend template function whose arguments are of type = private member type Hicham Mouline C++ 1 03-27-2009 03:58 PM
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 4 01-30-2008 05:12 PM
How to call function whose function call with arguments is in astring Options grbgooglefan C Programming 0 01-30-2008 04:19 AM
Is there a string function to trim all non-ascii characters out of astring silverburgh.meryl@gmail.com Python 10 12-31-2007 01:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57