#include #include #include #include #include #include #include // #include // using boost::lexical_cast; template class LineInputIterator : public std::iterator { public: typedef typename StringT::value_type char_type; typedef typename StringT::traits_type traits_type; typedef std::basic_istream istream_type; LineInputIterator() : is(NULL) { } LineInputIterator(istream_type& is): is(&is) { } const StringT& operator*() const { return value; } const StringT* operator->() const { return &value; } LineInputIterator& operator++() { assert(is != NULL); if (is && !std::getline(*is, value)) { is = NULL; } return *this; } LineInputIterator operator++(int) { LineInputIterator prev(*this); ++*this; return prev; } bool operator!=(const LineInputIterator& other) const { return is != other.is; } bool operator==(const LineInputIterator& other) const { return !(*this != other); } protected: istream_type* is; StringT value; }; template class GeneScoreIterator : public LineInputIterator { public: typedef typename std::pair pair_type; typedef typename std::string::value_type char_type; typedef typename std::string::traits_type traits_type; typedef std::basic_istream istream_type; GeneScoreIterator() : is(NULL) { } GeneScoreIterator(istream_type& is): is(&is) { ++*this; // Priming read. } GeneScoreIterator& operator++() { assert(is != NULL); if (is) { if (std::getline(*is, value)) { // Cast the contents of the string std::istringstream in(value, std::istringstream::in); in >> value_gene_score.first; in >> value_gene_score.second; } else { is = NULL; } } return *this; } GeneScoreIterator operator++(int) { GeneScoreIterator prev(*this); ++*this; return prev; } // De-reference const pair_type operator*() const { return value_gene_score; } const pair_type* operator->() const { return &value_gene_score; } bool operator!=(const GeneScoreIterator& other) const { return is != other.is; } bool operator==(const GeneScoreIterator& other) const { return !(*this != other); } const std::string test_value() const { return value; } protected: istream_type* is; std::string value; pair_type value_gene_score; };