void resize( size_t rows, size_t cols ) { flut_error_if( rows < row_size() || cols < column_size(), "tables cannot be shrinked" ); // reorganize existing data data_.resize( row_size() * cols ); for ( index_t ri = rows; ri-- > 0; ) for ( index_t ci = cols; ci-- > 0; ) data_[ cols * ri + ci ] = ( ri < row_size() && ci < column_size() ) ? data_[ column_size() * ri + ci ] : T(); col_labels_.resize( cols ); row_labels_.resize( rows ); }
string load_string( const string& filename ) { #if 0 // read file contents into char array FILE* f = fopen( filename.c_str(), "rb" ); flut_error_if( f == NULL, "Could not open " + quoted( filename ) ); fseek( f, 0, SEEK_END ); int file_len = ftell( f ); rewind( f ); string s( file_len, '\0' ); fread( reinterpret_cast< void* >( &s[ 0 ] ), sizeof( char ), file_len, f ); return s; #else // this method uses a stringbuf, which may be slower but more stable std::ifstream ifstr( filename ); std::stringstream buf; buf << ifstr.rdbuf(); return buf.str(); #endif }
// get create func create_func_t& operator()( const string& type ) { auto it = factory_functions.find( type ); flut_error_if( it == factory_functions.end(), "Unregistered type: " + type ); return it->second; }