Пример #1
0
int updateNewTable(vector<ihead_t> &iheadvec, vector<ohead_t> &oheadvec, Table &itab, Table &otab, int orowoff)
{
    unsigned i, row;
    char c;
    std::stringstream valstream;
    if(itab.getNbrofrows()+orowoff>otab.getNbrofrows()) return -1;

    for(i=0; i<min(iheadvec.size(),oheadvec.size()); i++) {
        // write out tablehead
        c = oheadvec[i].oname[0];
        if('$'==c || '+'==c || '-'==c || '%'==c || '['==c || ']'==c) {
            otab.Tablewrite(0, oheadvec[i].ocol, oheadvec[i].oname.substr(1,std::string::npos));
        } else {
            otab.Tablewrite(0, oheadvec[i].ocol, oheadvec[i].oname);
        }
        // process/write table content
        for(row=1; row<itab.getNbrofrows(); row++) {
            if(1>iheadvec[i].iname.size()) return -4;
            if(-2==iheadvec[i].icol) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, iheadvec[i].iname.substr(1, std::string::npos));
            } else if('$'==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, "");
                valstream.str("");
                valstream << std::scientific << norm_value(itab.Tableread(row, iheadvec[i].icol));
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, valstream.str());
            } else if('%'==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, to_string(is_relative(itab.Tableread(row, iheadvec[i].icol))));
            } else if('\\'==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, firstword(itab.Tableread(row, iheadvec[i].icol)));
            } else if('+'==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, "");
                valstream.str("");
                valstream << std::scientific << tolupp(itab.Tableread(row, iheadvec[i].icol));
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, valstream.str());
            } else if('-'==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, "");
                valstream.str("");
                valstream << std::scientific << tollow(itab.Tableread(row, iheadvec[i].icol));
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, valstream.str());
            } else if('['==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, "");
                valstream.str("");
                valstream << std::scientific << vallow(norm_value(itab.Tableread(row, iheadvec[i+1].icol)), tollow(itab.Tableread(row, iheadvec[i].icol)), is_relative(itab.Tableread(row, iheadvec[i].icol)));
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, valstream.str());
            } else if(']'==oheadvec[i].oname[0]) {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, "");
                valstream.str("");
                valstream << std::scientific << valupp(norm_value(itab.Tableread(row, iheadvec[i-1].icol)), tolupp(itab.Tableread(row, iheadvec[i].icol)), is_relative(itab.Tableread(row, iheadvec[i].icol)));
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, valstream.str());
            } else {
                otab.Tablewrite(row + orowoff, oheadvec[i].ocol, itab.Tableread(row, iheadvec[i].icol));
            }
            if(false==otab.OK) return -2;
            if(false==itab.OK) return -3;
        }
    }
    return 0;
}
Пример #2
0
void updateicol(vector<ihead_t> &iheadvec, Table &itab)
{
    unsigned i, icol;
    string str;
    for(i=0; i<iheadvec.size(); i++) {
        for(icol=0; icol<itab.getNbrofcols(); icol++) {
            str = itab.Tableread(0, icol);
            if((iheadvec[i].iname == str) || (iheadvec[i].namecontains && std::string::npos!=str.find(iheadvec[i].iname)) || (iheadvec[i].strcontainsname && (std::string::npos!=iheadvec[i].iname.find(str)))) {
                iheadvec[i].icol = icol;
            }
            if('&'==iheadvec[i].iname[0]) {
                iheadvec[i].icol = -2;
            }
        }
    }
}