diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-19 11:30:09 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-09-19 11:30:09 -0600 |
commit | 17f44d57164b123be802b3474f674d2e0df4d216 (patch) | |
tree | d992c46f2f2f4933f2af2b71ec06cc0d60cd168c /omegalib/omega/include/basic/Section.h | |
parent | f255f2498da1fd985ad1ed79362580bbf4675723 (diff) | |
download | chill-17f44d57164b123be802b3474f674d2e0df4d216.tar.gz chill-17f44d57164b123be802b3474f674d2e0df4d216.tar.bz2 chill-17f44d57164b123be802b3474f674d2e0df4d216.zip |
Template definition back in header files
Diffstat (limited to 'omegalib/omega/include/basic/Section.h')
-rw-r--r-- | omegalib/omega/include/basic/Section.h | 83 |
1 files changed, 79 insertions, 4 deletions
diff --git a/omegalib/omega/include/basic/Section.h b/omegalib/omega/include/basic/Section.h index 60821d1..7a4d241 100644 --- a/omegalib/omega/include/basic/Section.h +++ b/omegalib/omega/include/basic/Section.h @@ -5,6 +5,7 @@ */ #include <basic/Collection.h> +#include <assert.h> namespace omega { @@ -51,13 +52,87 @@ private: } // 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) + +namespace omega { + +template <class T> Section<T>::Section(Sequence<T> *s, int start, int length) + { + assert(s->size() >= start-1 + length); + it = s; + _start = start; + _length = length; + } + +template <class T> Iterator<T> *Section<T>::new_iterator() + { + return new Section_Iterator<T>(*this); + } + +template <class T> const T &Section<T>::operator[](int i) const + { + assert(1 <= i && i <= size()); + return (*it)[i+(_start-1)]; + } + +template <class T> T &Section<T>::operator[](int i) + { + assert(1 <= i && i <= size()); + return (*it)[i+(_start-1)]; + } + +template <class T> int Section<T>::index(const T &var) const + { + int i; + for (i=1; i<=size(); i++) + if ((*this)[i] == var) + return i; + return 0; + } + +template <class T> int Section<T>::size() const + { + return _length; + } + + +template <class T> Section_Iterator<T>::Section_Iterator(Section<T> &sec) + { + it = sec.it->new_iterator(); + for (int i = 1; i < sec._start; i++) + (*it)++; + remaining = sec.size(); + } + + +template <class T> Section_Iterator<T>::Section_Iterator(const Section_Iterator<T> &si) : it(si.it), remaining(si.remaining) {} + + +template <class T> void Section_Iterator<T>::operator++() + { this->operator++(0); } + +template <class T> void Section_Iterator<T>::operator++(int) + { + if (remaining > 0) + { + (*it)++; + remaining--; + } + } + +template <class T> bool Section_Iterator<T>::live() const + { + return (remaining > 0); + } + +template <class T> Iterator<T> *Section_Iterator<T>::new_copy() const + { + return new Section_Iterator<T>(*this); + } + +} // namespace #endif |