예제 #1
0
void operToOper(OPER *xTarget, const OPER *xSource) {
    if (xSource->xltype == xltypeNum) {
        xTarget->xltype = xltypeNum;
        xTarget->val.num = xSource->val.num;
        return;
    } else if (xSource->xltype == xltypeStr) {
        // Must use type unsigned char (BYTE) to process the 0th byte of Excel byte-counted string
        unsigned char len = xSource->val.str[0];
        xTarget->val.str = new char[ len + 1 ];
        xTarget->xltype = xltypeStr | xlbitDLLFree;
        xTarget->val.str[0] = len;
        if (len)
            strncpy(xTarget->val.str + 1, xSource->val.str + 1, len);
        return;
    } else if (xSource->xltype == xltypeBool) {
        xTarget->xltype = xltypeBool;
        //xTarget->val.boolean = xSource->val.boolean;
        xTarget->val.xbool = xSource->val.xbool;
        return;
    } else if (xSource->xltype == xltypeErr) {
        xTarget->xltype = xltypeErr;
        xTarget->val.err = xSource->val.err;
        return;
    } else if (xSource->xltype == xltypeNil) {
        xTarget->xltype = xltypeNil;
        return;
    } else if (xSource->xltype == xltypeInt) {
        xTarget->xltype = xltypeInt;
        xTarget->val.w = xSource->val.w;
        return;
    } else {
        RP_FAIL("operToOper: unexpected OPER type: " << xSource->xltype);
    }
}
예제 #2
0
 inline void ObjectWrapper::recreate(){
     try {
         object_ = SerializationFactory::instance().recreateObject( 
             object_->properties());
         dirty_ = false;
         updateTime_ = getTime();
     } catch (const std::exception &e) {
         RP_FAIL("Error in function ObjectWrapper::recreate() : " << e.what());
     }
 }
예제 #3
0
 inline void rpGroup::setSystemProperty(const std::string& name, const reposit::property_t& value) {
     std::string nameUpper = boost::algorithm::to_upper_copy(name);
     if(strcmp(nameUpper.c_str(), "OBJECTID")==0)
         objectId_ = boost::get<std::string>(value);
     else if(strcmp(nameUpper.c_str(), "CLASSNAME")==0)
         className_ = boost::get<std::string>(value);
     else if(strcmp(nameUpper.c_str(), "OBJECTIDLIST")==0)
         ObjectIdList_ = reposit::vector::convert2<std::string>(value, nameUpper);
     else if(strcmp(nameUpper.c_str(), "PERMANENT")==0)
         Permanent_ = reposit::convert2<bool>(value);
     else
         RP_FAIL("Error: attempt to set non-existent Property: '" + name + "'");
 }
예제 #4
0
 inline reposit::property_t rpGroup::getSystemProperty(const std::string& name) const {
     std::string nameUpper = boost::algorithm::to_upper_copy(name);
     if(strcmp(nameUpper.c_str(), "OBJECTID")==0)
         return objectId_;
     else if(strcmp(nameUpper.c_str(), "CLASSNAME")==0)
         return className_;
     else if(strcmp(nameUpper.c_str(), "OBJECTIDLIST")==0)
         return ObjectIdList_;
     else if(strcmp(nameUpper.c_str(), "PERMANENT")==0)
         return Permanent_;
     else
         RP_FAIL("Error: attempt to retrieve non-existent Property: '" + name + "'");
 }
예제 #5
0
QuantLib::Array operToQlArray(const OPER &xVector,
                              const std::string paramName) {
    OPER xTemp;
    bool excelToFree = false;
    bool xllToFree = false;
    try {
        RP_REQUIRE(!(xVector.xltype & xltypeErr),
                   "input value '" << paramName << "' has type=error");
        if (xVector.xltype & (xltypeMissing | xltypeNil))
            return QuantLib::Array();

        const OPER *xMulti;

        if (xVector.xltype == xltypeMulti) {
            xMulti = &xVector;
        } else if (xVector.xltype == xltypeStr) {
            splitOper(&xVector, &xTemp);
            xMulti = &xTemp;
            xllToFree = true;
        } else {
            Excel(xlCoerce, &xTemp, 2, &xVector, TempInt(xltypeMulti));
            xMulti = &xTemp;
            excelToFree = true;
        }

        int size = xMulti->val.array.rows * xMulti->val.array.columns;
        QuantLib::Array a(size);
        for (int i=0; i<size; ++i) {
            a[i] = reposit::convert2<double>(reposit::ConvertOper(xMulti->val.array.lparray[i]));
        }

        if (excelToFree) {
            Excel(xlFree, 0, 1, &xTemp);
        } else if (xllToFree) {
            freeOper(&xTemp);
        }

        return a;
    } catch (const std::exception &e) {
        if (excelToFree) {
            Excel(xlFree, 0, 1, &xTemp);
        } else if (xllToFree) {
            freeOper(&xTemp);
        }
        RP_FAIL("operToVector: error converting parameter '" << paramName << "' : " << e.what());
    }
}
예제 #6
0
    std::string CallingRange::initializeID(const std::string &objectID) {

        static const std::string anonPrefix("obj");
        static const std::string ANONPREFIX("OBJ");

        if (objectID.empty()) {
            if (callerType_ == CallerType::Cell) {
                return anonPrefix + key_;
            } else {
                RP_FAIL("Null string specified for object ID");
            }
        }

        RP_REQUIRE(objectID.find(counterDelimiter, 0) == std::string::npos,
            objectID << " is an invalid ID: cannot contain " << counterDelimiter);
        std::string ID = boost::algorithm::to_upper_copy(objectID);
        RP_REQUIRE(ID.rfind(ANONPREFIX, ANONPREFIX.size() - 1) == std::string::npos,
            objectID << " is an invalid ID: cannot start with " << anonPrefix);

        return objectID;
    }
예제 #7
0
    std::vector<std::vector<T> > operToMatrixImpl(
        const ConvertOper &xMatrix, 
        const std::string &paramName) {

        try {
            if (xMatrix.missing()) return std::vector<std::vector<T> >();

            RP_REQUIRE(!xMatrix.error(), "input value has type=error");

            const OPER *xMulti;
            Xloper xCoerce;  // Freed automatically

            if (xMatrix->xltype == xltypeMulti)
                xMulti = xMatrix.get();
            else {
                Excel(xlCoerce, &xCoerce, 2, xMatrix.get(), TempInt(xltypeMulti));
                xMulti = &xCoerce;
            }

            std::vector<std::vector<T> > ret;
            ret.reserve(xMulti->val.array.rows);
            for (int i=0; i<xMulti->val.array.rows; ++i) {
                std::vector<T> row;
                row.reserve(xMulti->val.array.columns);
                for (int j=0; j<xMulti->val.array.columns; ++j) {
                    row.push_back(convert2<T>(ConvertOper(xMulti->val.array.lparray[i * xMulti->val.array.columns + j])));                
                }
                ret.push_back(row);
            }

            return ret;
        } catch (const std::exception &e) {
            RP_FAIL("operToMatrixImpl: error converting parameter '" << paramName 
                << "' to type '" << typeid(T).name() << "' : " << e.what());
        }
    }
예제 #8
0
 ComplexLib::Grade convertGrade(const container_t& c) {
     if(c.type() == typeid(double))
         return ComplexLib::Grade(c.operator double());
     else
         RP_FAIL("unable to convert type '" << c.type().name() << "' to type 'ComplexLib::Grade'");
 }