Aleph-w  1.5a.2
Biblioteca general de algoritmos y estructuras de datos
 Todo Clases Archivos Funciones Variables 'typedefs' Enumeraciones Amigas Grupos Páginas
tpl_slist_modified.H
1 
2 /*
3  This file is part of Aleph system
4 
5  Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
6  UNIVERSITY LOS ANDES (ULA) Merida - REPÚBLICA BOLIVARIANA DE VENEZUELA
7 
8  - Center of Studies in Microelectronics & Distributed Systems (CEMISID)
9  - ULA Computer Science Department
10 
11  PERMISSION TO USE, COPY, MODIFY AND DISTRIBUTE THIS SOFTWARE AND ITS
12  DOCUMENTATION IS HEREBY GRANTED, PROVIDED THAT BOTH THE COPYRIGHT
13  NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES OF THE
14  SOFTWARE, DERIVATIVE WORKS OR MODIFIED VERSIONS, AND ANY PORTIONS
15  THEREOF, AND THAT BOTH NOTICES APPEAR IN SUPPORTING DOCUMENTATION.
16 
17  Aleph is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19  or FITNESS FOR A PARTICULAR PURPOSE.
20 
21  UNIVERSIDAD DE LOS ANDES requests users of this software to return to
22 
23  Leandro Rabindranath Leon
24  CEMISID
25  Ed La Hechicera
26  3er piso, ala sur
27  Facultad de Ingenieria
28  Universidad de Los Andes
29  Merida - REPÚBLICA BOLIVARIANA DE VENEZUELA or
30 
31  lrleon@ula.ve
32  leandro.r.leon@gmail.com
33 
34  any improvements or extensions that they make and grant Universidad
35  de Los Andes (ULA) the rights to redistribute these changes.
36 */
37 
38 
39 # ifndef TPL_SLIST_H
40 # define TPL_SLIST_H
41 
42 # include <ahDefs.H>
43 # include <tpl_snode.H>
44 
45 using namespace Aleph;
46 
47 namespace Aleph
48 {
49 
50 template <typename T>
51 class Slist_Node : public Snode<T>
52 {
53 public:
54 
55  Slist_Node() : Snode<T>()
56  {
57  /* Empty */
58  }
59 
60  Slist_Node(const T & _data) : Snode<T>(_data)
61  {
62  /* Empty */
63  }
64 };
65 
66 template <typename T>
67 class Slist_Node_Vtl : public Snode<T>
68 {
69 public:
71  {
72  /* Empty */
73  }
74 
75  Slist_Node_Vtl(const T & _data) : Snode<T>(_data)
76  {
77  /* Empty */
78  }
79 
80  virtual ~Slist_Node_Vtl()
81  {
82  /* Empty */
83  }
84 };
85 
86 template <template <typename> class Node, typename T>
87 class MetaSlistNode : public Node<T>
88 {
89 
90 public:
91 
92  MetaSlistNode() : Node<T>()
93  {
94  /* Empty */
95  }
96 
97  MetaSlistNode(const T & _data) : Node<T>(_data)
98  {
99  /* Empty */
100  }
101 
102  MetaSlistNode * get_next()
103  {
104  return static_cast<MetaSlistNode*>(Node<T>::get_next());
105  }
106 
107  MetaSlistNode * remove_next()
108  {
109  return static_cast<MetaSlistNode*>(Node<T>::remove_next());
110  }
111 };
112 
113  template <template <typename> class Node_Type, typename T>
114 class GenSlist : public MetaSlistNode<Node_Type, T>
115 {
116 
117 public:
118 
120 
121  GenSlist() { /* empty */ }
122 
123  void insert_first(Node * node)
124  {
125  I(node not_eq NULL);
126  I(node->is_empty());
127  this->insert_next(node);
128  }
129 
130  Node * remove_first() throw(std::exception, std::underflow_error)
131  {
132  if (this->is_empty())
133  throw std::underflow_error ("list is empty");
134 
135  return this->remove_next();
136  }
137 
138  Node * get_first() throw(std::exception, std::underflow_error)
139  {
140  if (this->is_empty())
141  throw std::underflow_error ("list is empty");
142 
143  return this->get_next();
144  }
145 
146  class Iterator
147  {
148 
149  private:
150 
151  GenSlist * list;
152  Node * current;
153 
154  public:
155 
158 
159  Iterator(GenSlist & _list)
160  : list(&_list), current(list->get_first()) { /* Empty */ }
161 
162  bool has_current() const { return current != list; }
163 
164  Node * get_current() throw(std::exception, std::overflow_error)
165  {
166  if (not this->has_current())
167  throw std::overflow_error ("");
168 
169  return current;
170  }
171 
172  void next() throw(std::exception, std::overflow_error)
173  {
174  if (not this->has_current())
175  throw std::overflow_error ("");
176 
177  current = current->get_next();
178  }
179 
180  void reset_first() { current = list->get_next(); }
181 
182  Iterator & operator = (Node * node)
183  {
184  if (this == node)
185  return *this;
186 
187  current = node;
188  return *this;
189  }
190  };
191 };
192 
193 template <typename T>
194 class Slist : public GenSlist<Slist_Node, T>
195 {
196 
197 public:
198 
199  typedef typename GenSlist<Slist_Node, T>::Node Node;
200  typedef typename GenSlist<Slist_Node, T>::Iterator Iterator;
201 };
202 
203 template <typename T>
204 class SlistVtl : public GenSlist<Slist_Node_Vtl, T>
205 {
206 
207 public:
208 
209  typedef typename GenSlist<Slist_Node_Vtl, T>::Node Node;
210  typedef typename GenSlist<Slist_Node_Vtl, T>::Iterator Iterator;
211 };
212 
213 } // end namespace Aleph
214 # endif /* TPL_SLIST_H */
Definition: tpl_slist_modified.H:51
Definition: tpl_snode.H:22
Definition: tpl_slist_modified.H:146
Definition: tpl_slist.H:20
Definition: tpl_slist_modified.H:114
Definition: tpl_slist_modified.H:204
Definition: tpl_slist_modified.H:67
Definition: List.H:23
Definition: tpl_slist_modified.H:87

Leandro Rabindranath León