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/SimpleList.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/SimpleList.h')
| -rw-r--r-- | omegalib/omega/include/basic/SimpleList.h | 109 | 
1 files changed, 105 insertions, 4 deletions
| 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 <basic/SimpleList.c> -#endif -  #define instantiate_Simple_List(T)	template class Simple_List<T>;  \    template class Simple_List_Iterator<T>;                           \    instantiate_Only_List_Element(T)                                  \    instantiate_Sequence(T) +namespace omega { +   +template<class T> Simple_List_Iterator<T>::Simple_List_Iterator(Simple_List<T> &l)  +: List_Element_Iterator<T>(l.contents) {} + +template<class T> Simple_List_Iterator<T>::Simple_List_Iterator(const Simple_List<T> &l)  +: List_Element_Iterator<T>(l.contents) {} + +template<class T> Simple_List_Iterator<T>::Simple_List_Iterator() +: List_Element_Iterator<T>(0) {} + +template<class T> Iterator<T> *Simple_List<T>::new_iterator() +{ +    return new Simple_List_Iterator<T>(*this); +} + +template<class T> const T &Simple_List<T>::operator[](int i) const +{ +    Simple_List_Iterator<T> p(*this); + +    while(--i > 0 && p) +	p++; + +    if (p) +	return *p; +    else +	return *((T *)0); +} + +template<class T>       T &Simple_List<T>::operator[](int i) +{ +    Simple_List_Iterator<T> p(*this); + +    while(--i > 0 && p) +	p++; + +    if (p) +	return *p; +    else +	return *((T *)0); +} + + +template<class T> int Simple_List<T>::size() const +    { +    int i = 0; +    List_Element<T> * p = contents; +    while (p) +	{ +	p = p->tail; +	i++; +	} +    return i; +    } + +template<class T> T &Simple_List<T>::front() const +    { +    return contents->head; +    } + +template<class T> T Simple_List<T>::remove_front() +    { +    List_Element<T> *frunt = contents; +    contents = contents->tail; +    T fruntT = frunt->head; +    frunt->tail = 0; +    delete frunt; +    return fruntT; +    } + +template<class T> void Simple_List<T>::prepend(const T &item) +    { +    contents = new List_Element<T>(item, contents); +    } + + +template<class T> void Simple_List<T>::append(const T &item) +    { +    *(end()) = new List_Element<T>(item, 0); +    } + + +template<class T> void Simple_List<T>::del_front() +    { +    List_Element<T> *e = contents; +    contents = contents->tail; +    e->tail = 0; +    delete e; +    } + + +template<class T> void Simple_List<T>::clear() +    { +    delete contents; +    contents = 0; +    } + +template<class T> void Simple_List<T>::join(Simple_List<T> &consumed) +    { +    List_Element<T> *e = consumed.contents; +    consumed.contents = 0; +    *(end()) = e; +    } + +} // namespace  #endif | 
