table: PIT iterator dereferences to const shared_ptr<pit::Entry>&

refs #3164

Change-Id: Id857e214a727917009f865c2cfac782077844799
diff --git a/daemon/table/pit-iterator.cpp b/daemon/table/pit-iterator.cpp
index 0cdb395..b3b9afa 100644
--- a/daemon/table/pit-iterator.cpp
+++ b/daemon/table/pit-iterator.cpp
@@ -36,27 +36,24 @@
 static_assert(std::is_default_constructible<Iterator>::value,
               "Iterator must be default-constructible");
 
-Iterator::Iterator()
-  : m_iPitEntry(0)
-{
-}
-
-Iterator::Iterator(const NameTree::const_iterator& ntIt)
+Iterator::Iterator(const NameTree::const_iterator& ntIt, size_t iPitEntry)
   : m_ntIt(ntIt)
-  , m_iPitEntry(0)
+  , m_iPitEntry(iPitEntry)
 {
 }
 
 Iterator&
 Iterator::operator++()
 {
-  ++m_iPitEntry;
-  if (m_iPitEntry < m_ntIt->getPitEntries().size()) {
-    return *this;
+  BOOST_ASSERT(m_ntIt != NameTree::const_iterator());
+  BOOST_ASSERT(m_iPitEntry < m_ntIt->getPitEntries().size());
+
+  if (++m_iPitEntry >= m_ntIt->getPitEntries().size()) {
+    ++m_ntIt;
+    m_iPitEntry = 0;
+    BOOST_ASSERT(m_ntIt == NameTree::const_iterator() || m_ntIt->hasPitEntries());
   }
 
-  ++m_ntIt;
-  m_iPitEntry = 0;
   return *this;
 }