#ifndef SEARCHJOB_HPP #define SEARCHJOB_HPP #include #include template class SearchJob { public: // initially reserve n entries in result-list (to cut down number of reallocations) enum { INITIAL_RESERVE = 128 }; // Type of the search result typedef std::vector ResultList; // Create partial search job for provided range SearchJob(Iterator begin, Iterator end, const std::string& pattern) : begin_(begin), end_(end), pattern_(pattern) { result_.reserve(INITIAL_RESERVE); } // Destructor ~SearchJob() { } // run the search job and collect results internally void run() { for (Iterator itr = begin_; itr != end_; itr++) { if (0 == itr->compare(0, pattern_.size(), pattern_)) { // found a match, save the index result_.push_back(itr); } } } // return the result const ResultList& get_result() const { return result_; }; private: // pattern to search for std::string pattern_; // start of search range Iterator begin_; // end of search range Iterator end_; // result of the search ResultList result_; }; #endif