28 #include <suplibxx/colselect.h> 30 #include "SelectedCols.h" 33 update_column_definitions( RDB& rdbtable,
const DefOverrideList& override_defn ) {
35 for (
const auto& odef : override_defn ) {
37 auto column = rdbtable.getColumn( odef.colname );
40 switch ( odef.type ) {
42 case OverrideType::Toggle :
43 type = RDBColumn::NUMERIC == column->getType( ) ?
"S" :
"N";
46 case OverrideType::Number :
50 case OverrideType::String :
55 column->setDef( type );
60 SelectedCols::SelectedCols( RDB& rdbtable,
61 const std::vector<std::string>& include_exact,
62 const std::vector<std::string>& include_re,
63 const std::vector<std::string>& exclude_exact,
64 const std::vector<std::string>& exclude_re,
65 const std::vector<std::string>& groups,
66 const DefOverrideList& override_defn
69 update_column_definitions( rdbtable, override_defn );
72 std::vector<std::string> icolumns;
76 size_t num = rdbtable.nColumns( );
77 for (
size_t ii = 0; ii < num; ii++ ) {
78 std::string name = rdbtable.getColumn( ii )->getName( );
79 if ( is_column_numeric( name, rdbtable ) && ! is_groupie( name, groups ) )
80 icolumns.push_back( name );
89 && exclude_exact.empty()
92 selected_cols = icolumns;
98 if ( ! include_exact.empty() ) {
99 for (
const auto& name : include_exact )
100 if ( ! is_column_numeric( name, rdbtable ) )
101 throw Exception( name +
"is not numeric" );
104 suplib::colselect( icolumns, include_exact, include_re, exclude_exact, exclude_re, selected_cols );
108 bool SelectedCols::is_column_numeric(
const std::string& colname,
111 return RDBColumn::NUMERIC == rdbtable.getColumn( colname )->getType( );
115 bool SelectedCols::is_groupie(
const std::string& name,
116 const std::vector<std::string>& groupies ) {
118 std::vector< std::string >::const_iterator current_group( groupies.begin( ) ),
119 end_group( groupies.end( ) );
120 for ( ; current_group != end_group; ++current_group )
121 if ( 0 == name.compare( *current_group ) )
128 void SelectedCols::print( std::ostream& os )
const {
130 copy( selected_cols.begin( ), selected_cols.end( ),
131 std::ostream_iterator< std::string >( os,
" " ) );