From ad1cadf3512f3dd789151983e5c93af411f929db Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 17 Sep 2016 19:27:15 +0000 Subject: restructure --- omegalib/omega_lib/include/basic/List.h | 95 +++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 omegalib/omega_lib/include/basic/List.h (limited to 'omegalib/omega_lib/include/basic/List.h') diff --git a/omegalib/omega_lib/include/basic/List.h b/omegalib/omega_lib/include/basic/List.h new file mode 100644 index 0000000..c6fc062 --- /dev/null +++ b/omegalib/omega_lib/include/basic/List.h @@ -0,0 +1,95 @@ +#if ! defined _List_h +#define _List_h 1 + +/* + * Linked lists with an interface like a bit of libg++'s SLList class + */ + + +#if 0 +#include /* List requires assert which needs Exit which */ +#endif /* needs List! just include assert in List.c */ +#include // for NULL +#include +#include +#include + +namespace omega { + +template class List_Iterator; + +// +// indexing of Lists starts at 1, index == 0 means not there +// + +template class List : public Sequence { +public: + List(const List &l) + { contents = l.contents ? new List_Element(*l.contents) : 0; } + List() { contents = 0; } + virtual ~List() { delete contents; } + + Iterator *new_iterator(); + const T &operator[](int) const; + T &operator[](int); + + int index(const T &) const; + + int size() const; + int length() const { return size(); } + bool empty() const { return size() == 0; } + + T &front() const; + +// insertion/deletion on a list invalidates any iterators +// that are on/after the element added/removed + + T remove_front(); + + void prepend(const T &item); + void append(const T &item); + void ins_after(List_Iterator i, const T &item); + + void del_front(); + void del_after(List_Iterator i); + void clear(); + + void join(List &consumed); + +private: + friend class List_Iterator; + List_Element **end() + { + List_Element **e = &contents; + while (*e) + e = &((*e)->tail); + return e; + } + + List_Element *contents; +}; + + +template class List_Iterator : public List_Element_Iterator { +public: + List_Iterator(List &l); + List_Iterator(const List &l); + List_Iterator(); +private: + List_Element &element() { return *List_Element_Iterator::i; } ; + friend class List; +}; + +} // namespace + +#if ! defined DONT_INCLUDE_TEMPLATE_CODE +#include +#endif + +#define instantiate_List(T) template class List; \ + template class List_Iterator; \ + instantiate_Only_List_Element(T) \ + instantiate_Sequence(T) + + +#endif -- cgit v1.2.3-70-g09d2