From 17f44d57164b123be802b3474f674d2e0df4d216 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Mon, 19 Sep 2016 11:30:09 -0600 Subject: Template definition back in header files --- omegalib/omega/include/basic/SimpleList.h | 109 ++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) (limited to 'omegalib/omega/include/basic/SimpleList.h') diff --git a/omegalib/omega/include/basic/SimpleList.h b/omegalib/omega/include/basic/SimpleList.h index a08b307..104390d 100644 --- a/omegalib/omega/include/basic/SimpleList.h +++ b/omegalib/omega/include/basic/SimpleList.h @@ -81,13 +81,114 @@ private: } // namespace -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - #define instantiate_Simple_List(T) template class Simple_List; \ template class Simple_List_Iterator; \ instantiate_Only_List_Element(T) \ instantiate_Sequence(T) +namespace omega { + +template Simple_List_Iterator::Simple_List_Iterator(Simple_List &l) +: List_Element_Iterator(l.contents) {} + +template Simple_List_Iterator::Simple_List_Iterator(const Simple_List &l) +: List_Element_Iterator(l.contents) {} + +template Simple_List_Iterator::Simple_List_Iterator() +: List_Element_Iterator(0) {} + +template Iterator *Simple_List::new_iterator() +{ + return new Simple_List_Iterator(*this); +} + +template const T &Simple_List::operator[](int i) const +{ + Simple_List_Iterator p(*this); + + while(--i > 0 && p) + p++; + + if (p) + return *p; + else + return *((T *)0); +} + +template T &Simple_List::operator[](int i) +{ + Simple_List_Iterator p(*this); + + while(--i > 0 && p) + p++; + + if (p) + return *p; + else + return *((T *)0); +} + + +template int Simple_List::size() const + { + int i = 0; + List_Element * p = contents; + while (p) + { + p = p->tail; + i++; + } + return i; + } + +template T &Simple_List::front() const + { + return contents->head; + } + +template T Simple_List::remove_front() + { + List_Element *frunt = contents; + contents = contents->tail; + T fruntT = frunt->head; + frunt->tail = 0; + delete frunt; + return fruntT; + } + +template void Simple_List::prepend(const T &item) + { + contents = new List_Element(item, contents); + } + + +template void Simple_List::append(const T &item) + { + *(end()) = new List_Element(item, 0); + } + + +template void Simple_List::del_front() + { + List_Element *e = contents; + contents = contents->tail; + e->tail = 0; + delete e; + } + + +template void Simple_List::clear() + { + delete contents; + contents = 0; + } + +template void Simple_List::join(Simple_List &consumed) + { + List_Element *e = consumed.contents; + consumed.contents = 0; + *(end()) = e; + } + +} // namespace #endif -- cgit v1.2.3-70-g09d2