예제 #1
0
    std::vector<boost::shared_ptr<ObjectClass> > getObjectVector(
            const std::vector<std::string> &objectIDs,
            const int &nestingLevel = 0,
			bool includeGroups = false) {

        RP_REQUIRE(nestingLevel < 10, "getObjectVector - nesting level exceeds 10. "
            "(Possible infinite recursion?)");

        std::vector<boost::shared_ptr<ObjectClass> > ret;

        for (std::vector<std::string>::const_iterator i = objectIDs.begin();
                i != objectIDs.end(); ++i) {

            std::string objectId = *i;

            // If the object ID is a null string then silently ignore.
            // This will be revised to raise an exception in the absence of explicit
            // indication from the user to do otherwise.
            if (objectId.empty())
                continue;

            boost::shared_ptr<Object> object;
            Repository::instance().retrieveObject(object, objectId);

            boost::shared_ptr<Group> group =
                boost::dynamic_pointer_cast<Group>(object);
            if (group) {
                std::vector<boost::shared_ptr<ObjectClass> > ret2 =
                    getObjectVector<ObjectClass>(group->list(), nestingLevel + 1, includeGroups);
                ret.insert(ret.end(), ret2.begin(), ret2.end());
				if(includeGroups) {
					boost::shared_ptr<ObjectClass> objectDerived =
						boost::dynamic_pointer_cast<ObjectClass>(object);
					RP_REQUIRE(objectDerived, "Error converting Group with id '"
						<< objectId << "' - unable to convert to type '"
						<< typeid(ObjectClass).name() << "'");
					ret.push_back(objectDerived);				
				}
            } else {
                boost::shared_ptr<ObjectClass> objectDerived =
                    boost::dynamic_pointer_cast<ObjectClass>(object);
                RP_REQUIRE(objectDerived, "Error retrieving object with id '"
                    << objectId << "' - unable to convert reference to type '"
                    << typeid(ObjectClass).name() << "'");
                ret.push_back(objectDerived);
            }

        }
        return ret;
    }
예제 #2
0
 Group(const boost::shared_ptr<ValueObject>& properties,
       const std::vector<std::string>& list,
       bool permanent)
 : Object(properties, permanent), list_(list)
 {
     RP_REQUIRE(!list.empty(), "Input list is empty");
 }
    const CurveClass *get(const QuantLib::Extrapolator *extrapolator) const {

        const CurveClass *ret = dynamic_cast<const CurveClass*>(extrapolator);
        RP_REQUIRE(ret, "Unable to convert from type " << typeid(extrapolator).name()
            << " to type " << typeid(CurveClass).name());
        return ret;
    }
예제 #4
0
 void retrieveObject(boost::shared_ptr<T> &ret,
                     const std::string &id) {
     boost::shared_ptr<Object> object = retrieveObjectImpl(id);
     ret = boost::dynamic_pointer_cast<T>(object);
     RP_REQUIRE(ret, "Error retrieving object with id '"
         << id << "' - unable to convert reference to type '"
         << typeid(T).name() << "' found instead '"
         << typeid(*object).name() << "'");
 }
예제 #5
0
    std::string CallingRange::getKeyCount() {
        static const int KEY_BASE = 16;
        static const double KEY_MAX = pow((double)KEY_BASE, KEY_WIDTH);

        RP_REQUIRE(keyCount_ < KEY_MAX, "CallingRange::getKeyCount() : max key value exceeded");
        std::ostringstream s;
        s << '_' << std::setw(KEY_WIDTH) << std::setfill('0') << std::setbase(KEY_BASE) << keyCount_++;
        return s.str();
    }
예제 #6
0
    inline std::vector<std::string> Registry<KeyClass>::getTypeElements(
        const std::string& id) const {

        AllTypeMap &allTypeMap = getAllTypesMap();
        typename AllTypeMap::const_iterator map = allTypeMap.find(id);
        RP_REQUIRE(map != allTypeMap.end(), "Registry::getTypeElements: invalid enum id: " + id);
        std::vector<std::string> ret;
        for(typename TypeMap::const_iterator i = map->second->begin(); i != map->second->end(); ++i)
            ret.push_back(i->first);
        return ret;
    }
예제 #7
0
XLL_DEC OPER *ohFilter(
        OPER *xInput,
        OPER *flags) {

    // declare a shared pointer to the Function Call object

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

    try {

        // instantiate the Function Call object
    
        functionCall = boost::shared_ptr<reposit::FunctionCall>(
            new reposit::FunctionCall("ohFilter"));

        // convert input datatypes to C++ datatypes

        std::vector<bool> flagsCpp = reposit::operToVector<bool>(*flags, "flags");

        const OPER *xMulti;
        reposit::Xloper xTemp;
        if (xInput->xltype == xltypeMulti) {
            xMulti = xInput;
        } else {
            Excel(xlCoerce, &xTemp, 2, xInput, TempInt(xltypeMulti));
            xMulti = &xTemp;
        }

        int sizeInput = xMulti->val.array.rows * xMulti->val.array.columns;
        RP_REQUIRE(sizeInput == flagsCpp.size(),
            "size mismatch between value vector (" << sizeInput << 
            ") and flag vector (" << flagsCpp.size() << ")");


        static OPER xRet;
        xRet.val.array.rows = count(flagsCpp.begin(), flagsCpp.end(), true);
        xRet.val.array.columns = 1;
        xRet.val.array.lparray = new OPER[xRet.val.array.rows]; 
        xRet.xltype = xltypeMulti | xlbitDLLFree;

        int idx = 0;
        for (int i=0; i<sizeInput; i++) {
            if (flagsCpp[i]) {
                operToOper(&xRet.val.array.lparray[idx++], &xMulti->val.array.lparray[i]);
            }
        }

        return &xRet;

    } catch (const std::exception &e) {
        reposit::RepositoryXL::instance().logError(e.what(), functionCall);
        return 0;
    }
}
예제 #8
0
 Group(const boost::shared_ptr<ValueObject>& properties,
       const std::vector<boost::shared_ptr<reposit::Group> >& g,
       bool permanent)
 : Object(properties, permanent)
 {
     RP_REQUIRE(!g.empty(), "Group list is empty");
     list_ = g[0]->list();
     for (size_t i=1; i<g.size(); ++i) {
         const std::vector<std::string>& newList = g[i]->list();
         list_.insert(list_.end(), newList.begin(), newList.end());
     }
 }
예제 #9
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;
    }
예제 #10
0
    inline std::vector<std::string> Registry<KeyPair>::getTypeElements(
        const std::string& id) const {

        AllTypeMap &allTypeMap = getAllTypesMap();
        AllTypeMap::const_iterator map = allTypeMap.find(id);
        RP_REQUIRE(map != allTypeMap.end(), "Registry::getTypeElements: invalid enum id: " + id);
        std::vector<std::string> ret;
        for(TypeMap::const_iterator i = map->second->begin(); i != map->second->end(); ++i) {
            std::ostringstream s;
            s << i->first.first << " | " << i->first.second;
            ret.push_back(s.str());
        }
        return ret;
    }
예제 #11
0
    CallingRange::CallingRange() 
        : updateCount_(0), callerType_(FunctionCall::instance().callerType()) {

        if (callerType_ == CallerType::Cell) {
            // name the calling range
            key_ = getKeyCount();
            XLOPER xRet;
            Excel(xlfSetName, &xRet, 2, TempStrStl(key_), FunctionCall::instance().callerReference());
            //RP_REQUIRE(xRet.xltype == xltypeBool && xRet.val.boolean, "Error on call to xlfSetName");
            RP_REQUIRE(xRet.xltype == xltypeBool && xRet.val.xbool, "Error on call to xlfSetName");
        } else {
            key_ = "VBA";
        }
    }
예제 #12
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());
    }
}
예제 #13
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());
        }
    }
 // Retrieve the Caller pointer corresponding to a given InterpolatedYieldCurvePair
 const CallerBase *getCaller(InterpolatedYieldCurvePair tokenPair) const {
     CallerMap::const_iterator i = callerMap_.find(tokenPair);
     RP_REQUIRE(i!=callerMap_.end(), "Unable to retrieve caller for type " << tokenPair);
     return i->second;
 }
예제 #15
0
void validateReference(const XLOPER *xReference, const std::string &name) {
    RP_REQUIRE(xReference->xltype != xltypeErr && xReference->val.err != xlerrRef,
        "parameter '" << name << "' is not a valid range reference");
}