From fdfcefa79c27e31c027824183a8056ac195cb1b2 Mon Sep 17 00:00:00 2001
From: Vasileios Karakasis <karakasis@cscs.ch>
Date: Thu, 10 Mar 2016 13:48:38 +0100
Subject: [PATCH] Added empty() calls.

+ some const specifiers.
---
 src/swcio.hpp        | 28 +++++++++++++++++++---------
 tests/test_swcio.cpp |  7 +++++++
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/src/swcio.hpp b/src/swcio.hpp
index e267c184..171c7bde 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 7ecd5fc0..79c38cf2 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());
+    }
 }
-- 
GitLab