Returning std::vector<double> using ObjectHandler

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning std::vector<double> using ObjectHandler

Stale-2
Hi all, 

I have a function doing some calculations on a vector of doubles, and would like to return a vector (or more correctly a XLOPER structure). For some reason I can't get this simple test-code to work:


DLLEXPORT OPER *VectorTest(
OPER *Indata) {

boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;

    try {
                std::vector<double> values=ObjectHandler::operToVector<double>(*Indata, "Indata");

std::vector<double> outdata;

for(int i=0; i<values.size(); i++) outdata.push_back(values[i]);
static OPER xRet;
ObjectHandler::vectorToOper(outdata, xRet);
                return &xRet;

    } catch (...) {

        return 0;

    }
}

All compiles and linkes nicely, and the add-inn seems to work, but Excel complains about #NUM when I try it.

All input appreciated!

Thanks!

Bjørn

--
Up, down, turn around
Please dont let me hit the ground
Tonight I think Ill walk alone
Ill find my soul as I go home.

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Returning std::vector<double> using ObjectHandler

Eric Ehlers-2
Hi Bjorn,

> DLLEXPORT OPER *VectorTest(
> OPER *Indata) {
>
>
> boost::shared_ptr<ObjectHandler::FunctionCall> functionCall;
>
>     try {

At this point in the code - first thing within the try block - you
should say:

functionCall = boost::shared_ptr<ObjectHandler::FunctionCall>(
  new ObjectHandler::FunctionCall("VectorTest"));

> Excel complains about #NUM when I try it.

Please show us the code you use to register the function with Excel.

Kind Regards,
Eric



------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users