Пример #1
0
    void SimpleTable::init( const DeckItem& deckItem ) {
        this->addColumns();

        if ( (deckItem.size() % numColumns()) != 0)
            throw std::runtime_error("Number of columns in the data file is"
                    "inconsistent with the ones specified");

        size_t rows = deckItem.size() / numColumns();
        for (size_t colIdx = 0; colIdx < numColumns(); ++colIdx) {
            auto& column = getColumn( colIdx );
            for (size_t rowIdx = 0; rowIdx < rows; rowIdx++) {
                size_t deckItemIdx = rowIdx*numColumns() + colIdx;
                if (deckItem.defaultApplied(deckItemIdx))
                    column.addDefault( );
                else
                    column.addValue( deckItem.getSIDouble(deckItemIdx) );
            }
            if (colIdx > 0)
                column.applyDefaults(getColumn( 0 ));
        }
    }
Пример #2
0
bool DeckItem::equal(const DeckItem& other, bool cmp_default, bool cmp_numeric) const {
    double rel_eps = 1e-4;
    double abs_eps = 1e-4;

    if (this->type != other.type)
        return false;

    if (this->size() != other.size())
        return false;

    if (this->item_name != other.item_name)
        return false;

    if (cmp_default)
        if (this->defaulted != other.defaulted)
            return false;

    switch( this->type ) {
    case type_tag::integer:
        if (this->ival != other.ival)
            return false;
        break;
    case type_tag::string:
        if (this->sval != other.sval)
            return false;
        break;
    case type_tag::fdouble:
        if (cmp_numeric) {
            const std::vector<double>& this_data = this->dval;
            const std::vector<double>& other_data = other.dval;
            for (size_t i=0; i < this_data.size(); i++) {
                if (!double_equal( this_data[i] , other_data[i], rel_eps, abs_eps))
                    return false;
            }
        } else {
            if (this->dval != other.dval)
                return false;
        }
        break;
    default:
        break;
    }

    return true;
}