summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2016-03-13 10:07:14 +0100
committerDavid Tardon <dtardon@redhat.com>2016-03-13 15:15:05 +0100
commit675646f42ffedba4c7827c050d40a46ab6b10caf (patch)
treeb400942ee99e32386c97f361ff25af39bea0e55a
parentd996c9ef5c30bd86324b5056633da949213ef9b7 (diff)
add iterator adapter for stream
-rw-r--r--configure.ac1
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/lib/SW602StreamIterator.cpp64
-rw-r--r--src/lib/SW602StreamIterator.h45
4 files changed, 112 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 49e9b52..0ff3164 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,7 @@ AC_SUBST(REVENGE_LIBS)
# Find boost headers
# ==================
AC_CHECK_HEADERS(
+ boost/iterator/iterator_facade.hpp \
boost/optional.hpp \
boost/scoped_ptr.hpp \
boost/shared_ptr.hpp \
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 33159c6..66efcdd 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -64,6 +64,8 @@ libsw602_@SW602_MAJOR_VERSION@_@SW602_MINOR_VERSION@_la_SOURCES = \
SW602SpreadsheetEncoder.h \
SW602SpreadsheetListener.cpp \
SW602SpreadsheetListener.h \
+ SW602StreamIterator.cpp \
+ SW602StreamIterator.h \
SW602SubDocument.cpp \
SW602SubDocument.h \
SW602Table.cpp \
diff --git a/src/lib/SW602StreamIterator.cpp b/src/lib/SW602StreamIterator.cpp
new file mode 100644
index 0000000..c88d6e9
--- /dev/null
+++ b/src/lib/SW602StreamIterator.cpp
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libsw602 project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "SW602StreamIterator.h"
+
+#include <cassert>
+
+#include "libsw602_utils.h"
+
+namespace libsw602
+{
+
+SW602StreamIterator::SW602StreamIterator()
+ : m_input(0)
+ , m_pos(0)
+ , m_current('\0')
+{
+}
+
+SW602StreamIterator::SW602StreamIterator(librevenge::RVNGInputStream &input)
+ : m_input(&input)
+ , m_pos(input.tell())
+ , m_current('\0')
+{
+ read();
+}
+
+SW602StreamIterator::reference SW602StreamIterator::dereference() const
+{
+ assert(m_input);
+ return m_current;
+}
+
+bool SW602StreamIterator::equal(const SW602StreamIterator &other) const
+{
+ return (m_input == other.m_input) && (!m_input || (m_pos == other.m_pos));
+}
+
+void SW602StreamIterator::increment()
+{
+ assert(m_input);
+ ++m_pos;
+ read();
+}
+
+void SW602StreamIterator::read()
+{
+ if (m_input->tell() != m_pos)
+ m_input->seek(m_pos, librevenge::RVNG_SEEK_SET);
+ if (m_input->isEnd())
+ m_input = 0;
+ else
+ m_current = char(readU8(*m_input));
+}
+
+}
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
diff --git a/src/lib/SW602StreamIterator.h b/src/lib/SW602StreamIterator.h
new file mode 100644
index 0000000..7ad39f1
--- /dev/null
+++ b/src/lib/SW602StreamIterator.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * This file is part of the libsw602 project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SW602_STREAMITERATOR_H
+#define INCLUDED_SW602_STREAMITERATOR_H
+
+#include <boost/iterator/iterator_facade.hpp>
+
+#include <librevenge-stream/librevenge-stream.h>
+
+namespace libsw602
+{
+
+class SW602StreamIterator : public boost::iterator_facade<SW602StreamIterator, const char, boost::forward_traversal_tag>
+{
+ friend class boost::iterator_core_access;
+
+public:
+ SW602StreamIterator();
+ explicit SW602StreamIterator(librevenge::RVNGInputStream &input);
+
+private:
+ reference dereference() const;
+ bool equal(const SW602StreamIterator &other) const;
+ void increment();
+
+ void read();
+
+private:
+ librevenge::RVNGInputStream *m_input;
+ long m_pos;
+ char m_current;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=2 softtabstop=2 expandtab: */