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

Discussion in 'C++' started by grbgooglefan, Jan 30, 2008.

  1. grbgooglefan

    grbgooglefan Guest

    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.
    grbgooglefan, Jan 30, 2008
    #1
    1. Advertising

  2. Re: How to call function whose function call with arguments is in a string

    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
    Victor Bazarov, Jan 30, 2008
    #2
    1. Advertising

  3. Re: How to call function whose function call with arguments is in a string

    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.
    Pascal Bourguignon, Jan 30, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    605
    Torsten Bronger
    Dec 31, 2007
  2. grbgooglefan
    Replies:
    4
    Views:
    438
    Kenny McCormack
    Jan 30, 2008
  3. grbgooglefan
    Replies:
    0
    Views:
    389
    grbgooglefan
    Jan 30, 2008
  4. Hicham Mouline
    Replies:
    1
    Views:
    352
    Vladyslav Lazarenko
    Mar 27, 2009
  5. Xeno Campanoli
    Replies:
    2
    Views:
    93
    Heesob Park
    Nov 4, 2008
Loading...

Share This Page