28 #include <Exception/Exception.h> 30 #include "colselect.h" 58 const std::vector<std::string>& icolumns,
59 const std::vector<std::string>& exact_add,
60 const std::vector<std::string>& regex_add,
61 const std::vector<std::string>& exact_del,
62 const std::vector<std::string>& regex_del,
63 std::vector<std::string>& ocolumns
66 if ( 0 == (exact_add.size( ) + regex_add.size( ) +
67 exact_del.size( ) + regex_del.size( )) ) {
72 add_set, exact_add_set, regex_add_set,
73 del_set, exact_del_set, regex_del_set,
76 exact_add_set.insert( exact_add.begin( ), exact_add.end( ) );
77 regex_add_set.insert( regex_add.begin( ), regex_add.end( ) );
78 exact_del_set.insert( exact_del.begin( ), exact_del.end( ) );
79 regex_del_set.insert( regex_del.begin( ), regex_del.end( ) );
80 column_set.insert( icolumns.begin( ), icolumns.end( ) );
85 set_intersection( column_set.begin( ), column_set.end( ),
86 exact_add_set.begin( ), exact_add_set.end( ),
87 inserter( add_set, add_set.begin( ) )
91 for (
const auto& pat : regex_add_set )
92 for (
auto& nam : column_set )
93 if (
match( nam, pat ) )
94 add_set.insert( nam );
97 set_difference( column_set.begin( ), column_set.end( ),
98 exact_del_set.begin( ), exact_del_set.end( ),
99 inserter( del_set, del_set.begin( ) )
103 for (
auto& pat : regex_del_set )
105 for (
auto nam = del_set.begin( ); nam != del_set.end( ) ; ) {
106 if (
match( *nam, pat ) )
107 nam = del_set.erase( nam );
112 if ( exact_add.size( ) + regex_add.size( ) ) {
113 std::set<std::string> ocolumn_set;
114 set_intersection( del_set.begin( ), del_set.end( ),
115 add_set.begin( ), add_set.end( ),
116 inserter( ocolumn_set, ocolumn_set.begin( ) ) );
118 for ( std::vector<std::string>::size_type idx = 0; idx < icolumns.size( ); idx++ ) {
119 if ( ocolumn_set.end( ) != ocolumn_set.find( icolumns[idx] ) ) {
120 ocolumns.push_back( icolumns[idx] );
125 for ( std::vector<std::string>::size_type idx = 0; idx != icolumns.size( ); idx++ ) {
126 if ( del_set.end( ) != del_set.find( icolumns[idx] ) ) {
127 ocolumns.push_back( icolumns[idx] );
The suplib namespace encompasses all of the functions in the suplib++ library.
bool match(const std::string &str, const std::string &pattern)
handles Perl regular expression matching.
void colselect(const std::vector< std::string > &icolumns, const std::vector< std::string > &exact_add, const std::vector< std::string > ®ex_add, const std::vector< std::string > &exact_del, const std::vector< std::string > ®ex_del, std::vector< std::string > &ocolumns)
select columns based on exact/regex matching/exclusion.