void XlfOperImpl::MissingOrEmptyError(int xltype, const char* ErrorId, const char* identifier) { if (xltype == xltypeMissing) THROW_XLW(CombineErrorString("parameter is missing" , ErrorId, identifier)); if (xltype == xltypeErr) THROW_XLW(CombineErrorString("parameter is error" , ErrorId, identifier)); if (xltype == xltypeNil) THROW_XLW(CombineErrorString("parameter is nil" , ErrorId, identifier)); ThrowOnError(xlretInvXloper, ErrorId, identifier); }
PayOffCall::PayOffCall(xlw::ArgumentList args) { if (args.GetStructureName() != "payoff") // must be lower case here THROW_XLW("payoff structure expected in PayOffCall class"); if (args.GetStringArgumentValue("name") != "call") THROW_XLW("payoff list not for call passed to PayOffCall : got " << args.GetStringArgumentValue("name")); Strike = args.GetDoubleArgumentValue("strike"); args.CheckAllUsed("PayOffCall"); }
xlw::DoubleOrNothing::DoubleOrNothing(const CellMatrix& cells, const std::string& identifier) { if (cells.ColumnsInStructure() != 1 || cells.RowsInStructure() != 1) THROW_XLW("Multiple values given where one expected for DoubleOrNothing " << identifier); if (!cells(0,0).IsEmpty() && !cells(0,0).IsANumber() ) THROW_XLW("expected a double or nothing, got something else " << identifier); Empty = cells(0,0).IsEmpty(); Value = Empty ? 0.0 : cells(0,0).NumericValue(); }
/*! Performs the parts of the Registration that are common to all the subclasses of XlfAbstractCmdDesc. It then calls the pure virtual method DoRegister for the subclass dependant parts of the algorithm. */ void xlw::XlfAbstractCmdDesc::Register(int functionId) const { std::string dllName = XlfExcel::Instance().GetName(); if (dllName.empty()) { THROW_XLW("Could not get library name"); } // generate the default helpId if we have found a // suitable help file std::string helpName = XlfExcel::Instance().GetHelpName(); std::string suggestedHelpId; if(!helpName.empty()) { std::ostringstream oss; oss << helpName << "!" << functionId; suggestedHelpId = oss.str(); } int err = DoRegister(dllName, suggestedHelpId); if (err != xlretSuccess) { std::cerr << XLW__HERE__ << "Error " << err << " while registering " << GetAlias().c_str() << std::endl; } return; }
PayOffSpread::PayOffSpread(xlw::ArgumentList args) { if (args.GetStructureName() != "payoff") // must be lower case here THROW_XLW("payoff structure expected in PayOffCall class"); if (args.GetStringArgumentValue("name") != "spread") THROW_XLW("payoff list not for spread passed to payoffspread : got " << args.GetStringArgumentValue("name")); if (!args.GetIfPresent("Volume1",Volume1)) Volume1= 1.0; if (!args.GetIfPresent("Volume2",Volume2)) Volume2= -1.0; OptionOne = Wrapper<PayOff>(xlw::GetFromFactory<PayOff>(args.GetArgumentListArgumentValue("optionone"))); OptionTwo = Wrapper<PayOff>(xlw::GetFromFactory<PayOff>(args.GetArgumentListArgumentValue("optiontwo"))); args.CheckAllUsed("PayOffSpread"); }
/*! Performs the parts of the Unregistration that are common to all the subclasses of XlfAbstractCmdDesc. It then calls the pure virtual method DoUnregister for the subclass dependent parts of the algorithm. */ void xlw::XlfAbstractCmdDesc::Unregister() const { std::string dllName = XlfExcel::Instance().GetName(); if (dllName.empty()) THROW_XLW("Could not get library name"); int err = DoUnregister(dllName); if (err != xlretSuccess) std::cerr << XLW__HERE__ << "Error " << err << " while registering " << GetAlias().c_str() << std::endl; return; }
int Information_t::GetCurrentSheetId() { XLFOPER result; int err = XlfExcel::Instance().Callv(xlSheetId, &result, 0, 0); if(err != xlretSuccess) { THROW_XLW("xlSheetId failed with result code " << err); } if (XlfExcel::Instance().excel12()) return result.oper12.val.mref.idSheet; else return result.oper4.val.mref.idSheet; }
MyArray Stats(const MyArray& data ) { double total=0.0; double totalsq=0.0; if (data.size() < 2) THROW_XLW("At least data points are needed"); for (unsigned long i=0; i < data.size(); i++) { total+=data[i]; totalsq+=data[i]*data[i]; } MyArray values(2); values[0] = total/data.size(); values[1] = totalsq/data.size() - values[0] *values[0] ; return values; }
void XlfOperImpl::ThrowOnError(int xlret, const char* ErrorId, const char* Identifier) { if (xlret & xlretUncalced) throw XlfExceptionUncalculated(); if (xlret & xlretAbort) throw XlfExceptionAbort(); if (xlret & xlretStackOvfl) throw XlfExceptionStackOverflow(); if (xlret & xlretInvXloper) THROW_XLW(CombineErrorString("invalid OPER structure (memory could be exhausted)" , ErrorId, Identifier)); if (xlret & xlretFailed) THROW_XLW(CombineErrorString("command failed" , ErrorId, Identifier)); if (xlret & xlretInvCount) THROW_XLW(CombineErrorString("invalid number of arguments" , ErrorId, Identifier)); if (xlret & xlretInvXlfn) THROW_XLW(CombineErrorString("invalid function number" , ErrorId, Identifier)); if (xlret & xlRetInvAsynchronousContext) THROW_XLW(CombineErrorString("invalid asynch conext" , ErrorId, Identifier)); if (xlret & xlretNotClusterSafe) THROW_XLW(CombineErrorString("function not cluster safe" , ErrorId, Identifier)); }