BOOST help again ...

David Abrahams dave at boost-consulting.com
Sat Mar 22 21:00:41 EST 2003


Jim <REMOVEjimdon at sympatico.caREMOVE> writes:

> Hi ...
> I have a new boost question ... how do convert a tuple to a c struct
> ... my half brained attempt is below ... but it has some obvious
> compile problems ...

Please post Boost.Python questions to the c++-sig:
http://mail.python.org/mailman/listinfo/c++-sig

> void BOOSTED_cosim_define_board(boost::python::tuple t)
> {
>    double x60_clk, pwm_clk, utx_clk, urx_clk, local_ref_clk,
>    pcr_ref_clk, mod_ref_clk, demod_ref_clk;
>    long mod_utopia, demod_utopia, dac_type, adc_type;
>
>    if (!PyArg_ParseTuple(t, "(ddddddddllll)",
>      &x60_clk,
>      &pwm_clk,
>      &utx_clk,
>      &urx_clk,
>
>      &local_ref_clk,
>      &pcr_ref_clk,
>      &mod_ref_clk,
>      &demod_ref_clk,
>
>      &mod_utopia,
>      &demod_utopia,
>
>      &dac_type,
>      &adc_type))
>    {
>      PyErr_SetString( PyCosim_Error, "invalid args" );
>      return;
>    }

use 

    extract<double>(t[0])
    extract<long>(t[8])

etc., to get the values out.  Your approach won't interact properly
with exception-handling.

>    theboard.x60_clk=x60_clk*1e6;
>    theboard.pwm_clk=pwm_clk*1e6;
>    theboard.utx_clk=utx_clk*1e6;
>    theboard.urx_clk=urx_clk*1e6;
>
>    theboard.local_ref_clk=local_ref_clk*1e6;
>    theboard.pcr_ref_clk=pcr_ref_clk*1e6;
>    theboard.mod_ref_clk=mod_ref_clk*1e6;
>    theboard.demod_ref_clk=demod_ref_clk*1e6;
>
>    theboard.mod_utopia=static_cast<ATM_INFO>(mod_utopia);
>    theboard.demod_utopia=static_cast<ATM_INFO>(demod_utopia);
>
>    theboard.dac_type=static_cast<DACADC_TYPE>(dac_type);
>    theboard.adc_type=static_cast<DACADC_TYPE>(adc_type);
>
>    return;
> }

Your compile problems are not "obvious" from what you posted.
If you need help with compilation errors, it helps to show us a few.
Reproducible test cases are also good.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Python-list mailing list