table.cpp
/** return the current representation of the table as a string */
return the current representation of the table as a string
return the current representation of the table as a string
std::string Table::str() const {
    std::vector<size_t> max_sizes;
    for (const auto& r : rows_) {
        std::vector<size_t> sizes = r.getSizes();
        for (size_t c = 0; c < sizes.size(); c++) {
            size_t row_size = sizes[c];
            if (c >= max_sizes.size()) {
                assert(max_sizes.size() == c);
                max_sizes.push_back(row_size);
            } else {
                max_sizes[c] = std::max(max_sizes[c], row_size);
            }
        }
    }
    std::stringstream ss;
    for (const auto& r : rows_) {
        r.str(ss, max_sizes);
        ss << "\n";
    }
    return ss.str();
}
std :: string Table :: str ( ) const { std :: vector < size_t > max_sizes ; for ( const auto & r : rows_ ) { std :: vector < size_t > sizes = r . getSizes ( ) ; for ( size_t c = 0 ; c < sizes . size ( ) ; c ++ ) { size_t row_size = sizes [ c ] ; if ( c >= max_sizes . size ( ) ) { assert ( max_sizes . size ( ) == c ) ; max_sizes . push_back ( row_size ) ; } else { max_sizes [ c ] = std :: max ( max_sizes [ c ] , row_size ) ; } } } std :: stringstream ss ; for ( const auto & r : rows_ ) { r . str ( ss , max_sizes ) ; ss << " \n " ; } return ss . str ( ) ; }
return the current representation of the table as a string
return the current representation of the table as a string
// calculate max row sizes