summaryrefslogtreecommitdiff
path: root/omegalib/omega_lib/include/basic/Section.h
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-09-17 19:27:15 +0000
committerTuowen Zhao <ztuowen@gmail.com>2016-09-17 19:27:15 +0000
commitad1cadf3512f3dd789151983e5c93af411f929db (patch)
treed6d25d562617d9bec7b13286cf413ed8f7567275 /omegalib/omega_lib/include/basic/Section.h
parentcfafd2ffcad803e7bb02b60c085eafd73f28f87a (diff)
downloadchill-ad1cadf3512f3dd789151983e5c93af411f929db.tar.gz
chill-ad1cadf3512f3dd789151983e5c93af411f929db.tar.bz2
chill-ad1cadf3512f3dd789151983e5c93af411f929db.zip
restructure
Diffstat (limited to 'omegalib/omega_lib/include/basic/Section.h')
-rw-r--r--omegalib/omega_lib/include/basic/Section.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/omegalib/omega_lib/include/basic/Section.h b/omegalib/omega_lib/include/basic/Section.h
new file mode 100644
index 0000000..60821d1
--- /dev/null
+++ b/omegalib/omega_lib/include/basic/Section.h
@@ -0,0 +1,63 @@
+#if ! defined _Section_h
+#define _Section_h 1
+/*
+ Section of an existing collection viewed as a collection
+ */
+
+#include <basic/Collection.h>
+
+namespace omega {
+
+template<class T> class Section_Iterator;
+
+template <class T> class Section : public Sequence<T> {
+public:
+ Section(Sequence<T> *, int start, int length);
+
+ Iterator<T> *new_iterator();
+
+ const T &operator[](int) const;
+ T &operator[](int);
+
+ int index(const T &) const;
+ int size() const;
+
+ friend class Section_Iterator<T>;
+
+private:
+ Sequence<T> *it;
+ int _start, _length;
+};
+
+template <class T> class Section_Iterator : public Iterator<T> {
+public:
+ Section_Iterator(Section<T> &sec);
+ virtual ~Section_Iterator() { delete it; }
+
+ const T & operator*() const { return *(*it); }
+ T & operator*() { return *(*it); }
+
+ void operator++(int);
+ void operator++();
+
+ bool live() const;
+ Iterator<T> *new_copy() const;
+
+private:
+ Section_Iterator(const Section_Iterator<T> &si);
+ Iterator<T> *it;
+ int remaining;
+};
+
+} // namespace
+
+#if ! defined DONT_INCLUDE_TEMPLATE_CODE
+#include <basic/Section.c>
+#endif
+
+#define instantiate_Section(T) template class Section<T>; \
+ template class Section_Iterator<T>; \
+ instantiate_Sequence(T)
+#define instantiate_Section_Iterator(T) instantiate_Section(T)
+
+#endif