void ReSplit::handle(Input& input, Output& output) { RecordPtr rec = input.pop(); for (; !rec->eof(); output.push(rec), rec = input.pop()) { std::vector<std::size_t>::iterator iter = _columns.begin(); for (; iter != _columns.end(); ++iter) { const std::string& col = static_cast<const std::string&> ((*rec)[*iter]); boost::smatch parts; if (_option == Search) { boost::regex_search(col, parts, _regex); } else { boost::regex_match(col, parts, _regex); } boost::smatch::iterator iter = parts.begin(); for (; iter != parts.end(); ++iter) { if (!iter->matched) { continue; } rec->insert(rec->end(), std::string( iter->first, iter->second)); } } } }
void Filter::handle(Input& input, Output& output) { RecordPtr rec = input.pop(); if (_filterType == FilterAnd) { for (; !rec->eof(); rec = input.pop()) { bool test = true; std::vector<std::size_t>::iterator iter = _columns.begin(); for (; iter != _columns.end(); ++iter) { test = test && (bool) (*rec)[*iter]; if (!test) { break; } } if (!test) { output.push(rec); } } } else // _filterType == OpOr { bool initial = _columns.begin() == _columns.end(); for (; !rec->eof(); rec = input.pop()) { bool test = initial; std::vector<std::size_t>::iterator iter = _columns.begin(); for (; iter != _columns.end(); ++iter) { test = test || (bool) (*rec)[*iter]; if (test) { break; } } if (!test) { output.push(rec); } } } }
void Select::handle(Input& input, Output& output) { RecordPtr rec = input.pop(); for (; !rec->eof(); rec = input.pop()) { RecordPtr ptr = new Record(); ptr->resize(_columns.size()); std::vector<std::size_t>::iterator iter = _columns.begin(); for (; iter != _columns.end(); ++iter) { std::size_t index = iter - _columns.begin(); (*ptr)[index] = (*rec)[*iter]; } output.push(ptr); } }