Beispiel #1
0
va::ConstVectorView getColumnFromView(const va::Matrix& view, const std::string& model,
                                      const std::string& port)
{
    for(unsigned int j=1; j < view.columns(); j++){
        if(view.getString(j,0) == (model + std::string(".") + port)){
            return view.column(j);
        }
    }
    return view.column(0);
}
Beispiel #2
0
double
PlanSimSubpanel::getDouble(const vle::value::Matrix& view,
                              unsigned int col,
                              unsigned int row,
                              bool error_message)
{
    if (not view.get(col, row)) {
        if (error_message) {
            mLog->logExt(QString("output '%1' is null")
                           .arg(view.getString(col, 0).c_str()),
                         true);
        }
        return 0;
    } else if (view.get(col, row)->isInteger()) {
        return (double)view.getInt(col, row);
    } else if (view.get(col, row)->isDouble()) {
        return (double)view.getDouble(col, row);
    } else {
        if (error_message) {
            mLog->logExt(QString("output '%1' is neither an int nor a double")
                           .arg(view.getString(col, 0).c_str()),
                         true);
        }
        return 0;
    }
}
Beispiel #3
0
    bool readFile(vv::Matrix& matrixToFill)
    {
        clearFileStream();
        filestream = new std::ifstream(file_path.c_str());
        if (not filestream->good() or not filestream->is_open()) {
            throw vu::ArgError(vle::fmt("vle.reader: fails to topen %1% ") %
                    file_path);
        }
        matrixToFill.clear();

        //read the first line to get the number of columns
        std::string line;
        std::getline(*filestream, line);
        std::vector<std::string> strs;
        boost::split(strs,line,boost::is_any_of("\t"));
        //build parser parameter
        vle_reader_params p;
        p.separator.assign("\t");
        for (unsigned int i=0; i < strs.size(); i++) {
            if (not strs[i].empty()) {
                p.col_types.push_back(vv::Value::DOUBLE);
            }
        }
        TFR_matrix_tofill tofill(p, matrixToFill);
        matrixToFill.addRow();
        for (unsigned int i=0; i < strs.size(); i++) {
            if (not strs[i].empty()) {
                boost::replace_all(strs[i], "\"", "");
                boost::replace_all(strs[i], "#", "");
                matrixToFill.set(i,0, new vv::String(strs[i]));
            }
        }

        TFR_line_grammar g(p, tofill);
        tofill.nextRow();
        do {
            parseLine(g,line);
            tofill.nextRow();
        } while (not filestream->eof() and filestream->good());

        clearFileStream();
        return true;
    }
Beispiel #4
0
QString
PlanSimSubpanel::getString(const vle::value::Matrix& view,
                           unsigned int col,
                           unsigned int row,
                           bool error_message)
{
    if (not view.get(col, row)) {
        if (error_message) {
            mLog->logExt(QString("output '%1' is null")
                           .arg(view.getString(col, 0).c_str()),
                         true);
        }
        return 0;
    } else if (view.get(col, row)->isString()) {
        return QString::fromStdString((std::string)view.getString(col, row));
    } else {
        if (error_message) {
            mLog->logExt(QString("output '%1' is not a string")
                           .arg(view.getString(col, 0).c_str()),
                         true);
        }
        return 0;
    }
}