Usermode/libc++ - Starting on a hacky STL implementation
[tpg/acess2.git] / Usermode / Libraries / libc++.so_src / include_exp / list
1 /*
2  * Acess2 C++ Library
3  * - By John Hodge (thePowersGang)
4  *
5  * list (header)
6  * - List container
7  */
8 #ifndef _LIBCXX_LIST_
9 #define _LIBCXX_LIST_
10
11 #include <cstddef>
12
13 namespace std {
14
15 namespace _bits {
16 template <class T> class list_iterator;
17 template <class T> class list_item;
18 }
19
20 template <class T>
21 class list
22 {
23         friend class ::std::_bits::list_iterator<T>;
24         
25         typedef ::std::_bits::list_item<T>      item_type;
26         item_type       *m_start;
27         item_type       *m_end;
28 public:
29         typedef T value_type;
30         typedef value_type& reference;
31         typedef const value_type& const_reference;
32         typedef _bits::list_iterator<value_type>        iterator;
33         typedef _bits::list_iterator<const value_type>  const_iterator;
34         
35         list():
36                 m_start(0), m_end(0)
37         {
38         }
39         list(size_t n, const value_type& val = value_type());
40         list(const list& x);
41         ~list() {
42                 clear();
43         }
44         
45         list& operator =(const list& x);
46         
47         iterator begin() {
48                 return iterator(m_start);
49         }
50         const_iterator begin() const {
51                 return const_iterator(m_start);
52         }
53
54         iterator end() {
55                 return iterator(0);
56         }
57         const_iterator end() const {
58                 return const_iterator(0);
59         }
60         
61         bool empty() const {
62                 return !m_start;
63         }
64         size_t size() const;
65         size_t max_size() const;
66         
67         T& front();
68         const T& front() const;
69         T& back();
70         const T& back() const;
71         
72         void clear() {
73                 while( m_start ) {
74                         item_type* item = m_start;
75                         m_start = m_start->next;
76                         delete item;
77                 }
78         }
79 };
80
81
82 namespace _bits {
83
84 template <class T>
85 struct list_item
86 {
87         list_item<T>    *next;
88         list_item<T>    *prev;
89         T       value;
90 };
91
92 template <class T>
93 class list_iterator//:
94         //public bidirectional_iterator_tag;
95 {
96         friend class list<T>;
97
98         list_item<T>    *cur;
99 public:
100         bool operator == (const list_iterator& other) const {
101                 return cur == other.cur;
102         }
103         bool operator != (const list_iterator& other) const {
104                 return cur != other.cur;
105         }
106         
107         T& operator * () {
108                 return cur->value;
109         }
110         T& operator -> () {
111                 return cur->value;
112         }
113         list_iterator& operator ++ () {
114                 cur = cur->next;
115         }
116         list_iterator& operator -- () {
117                 cur = cur->prev;
118         }
119
120 private:
121         list_iterator(list_item<T> *item):
122                 cur(item)
123         {
124         }
125 };
126
127 };      // namespace _bits
128
129 };      // namespace std
130
131 #endif
132
133 // vim: ft=cpp
134

UCC git Repository :: git.ucc.asn.au