diff --git a/src/swcio.hpp b/src/swcio.hpp index e267c184b4e462b2015fb8c38866e2133d60b8b1..171c7bde0bc9bf38b44c7e3636d11c11420e5143 100644 --- a/src/swcio.hpp +++ b/src/swcio.hpp @@ -265,7 +265,7 @@ public: return ret; } - value_type operator*() + value_type operator*() const { if (eof_) { throw std::out_of_range("attempt to read past eof"); @@ -283,7 +283,7 @@ public: } } - bool operator!=(const cell_record_stream_iterator &other) + bool operator!=(const cell_record_stream_iterator &other) const { return !(*this == other); } @@ -320,27 +320,32 @@ private: class cell_record_range_raw { public: - using value_type = cell_record; - using reference = value_type &; - using const_referene = const value_type &; - using iterator = cell_record_stream_iterator; - using const_iterator = const cell_record_stream_iterator; + using value_type = cell_record; + using reference = value_type &; + using const_reference = const value_type &; + using iterator = cell_record_stream_iterator; + using const_iterator = const cell_record_stream_iterator; cell_record_range_raw(std::istream &is) : is_(is) { } - iterator begin() + iterator begin() const { return cell_record_stream_iterator(is_); } - iterator end() + iterator end() const { iterator::eof_tag eof; return cell_record_stream_iterator(is_, eof); } + bool empty() const + { + return begin() == end(); + } + private: std::istream &is_; }; @@ -379,6 +384,11 @@ public: return cells_.size(); } + bool empty() const + { + return cells_.empty(); + } + private: std::vector<cell_record> cells_; }; diff --git a/tests/test_swcio.cpp b/tests/test_swcio.cpp index 7ecd5fc013d98e66428d7a85cb658360e4ca6f2d..79c38cf29379fd2f1132d2cb8b3c2f9a75002280 100644 --- a/tests/test_swcio.cpp +++ b/tests/test_swcio.cpp @@ -371,4 +371,11 @@ TEST(cell_record_ranges, raw) EXPECT_EQ(3u, e.lineno()); } } + + { + // Test empty range + std::stringstream is(""); + EXPECT_TRUE(swc_get_records<swc_io_raw>(is).empty()); + EXPECT_TRUE(swc_get_records<swc_io_clean>(is).empty()); + } }