00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 # ifndef TPL_DLIST_H
00045 # define TPL_DLIST_H
00046
00047 # include <tpl_dnode.H>
00048
00049 using namespace Aleph;
00050
00051 namespace Aleph {
00052
00059 template <typename T>
00060 class Dlist_Node : public Dnode<T>
00061 {
00062
00063 public:
00064
00065 Dlist_Node() : Dnode<T>() { }
00066
00067 Dlist_Node(const T & _data) : Dnode<T>(_data) { }
00068 };
00069
00076 template <typename T>
00077 class Dlist_Node_Vtl : public Dlist_Node<T>
00078 {
00079
00080 public:
00081
00082 Dlist_Node_Vtl() : Dlist_Node<T>() { }
00083
00084 virtual ~Dlist_Node_Vtl() { }
00085
00086 Dlist_Node_Vtl(const T & _data) : Dlist_Node<T>(_data) { }
00087 };
00088 template <template <class> class Node, typename T>
00089 class MetaDlistNode : public Node<T>
00090 {
00091
00092 public:
00093
00094 MetaDlistNode() { }
00095
00096 MetaDlistNode(const T& _data) : Node<T>(_data) { }
00097
00098 MetaDlistNode(const MetaDlistNode<Node, T> & node) : Node<T>(node)
00099 { }
00100
00101 MetaDlistNode<Node, T> *& get_next()
00102 {
00103 return reinterpret_cast<MetaDlistNode<Node, T> *&>(Node<T>::get_next());
00104 }
00105
00106 MetaDlistNode<Node, T> *& get_prev()
00107 {
00108 return reinterpret_cast<MetaDlistNode<Node, T> *&>(Node<T>::get_prev());
00109 }
00110 };
00125 template <template <class> class Node_Type, typename T>
00126 class GenDlist : public MetaDlistNode<Node_Type, T>
00127 {
00128
00129 public:
00130
00132 typedef MetaDlistNode<Node_Type,T> Node;
00140 Node * get_first() throw(std::exception, std::underflow_error)
00141 {
00142 if (this->is_empty())
00143 throw std::underflow_error ("List is empty");
00144
00145 return this->get_next();
00146 }
00147
00155 Node * get_last() throw(std::exception, std::underflow_error)
00156 {
00157 if (this->is_empty())
00158 throw std::underflow_error ("List is empty");
00159
00160 return this->get_prev();
00161 }
00170 Node * remove_first() throw(std::exception, std::underflow_error)
00171 {
00172 if (this->is_empty())
00173 throw std::underflow_error ("List is empty");
00174
00175 Node* retValue = this->get_next();
00176 retValue->del();
00177
00178 return retValue;
00179 }
00180
00189 Node* remove_last() throw(std::exception, std::underflow_error)
00190 {
00191 if (this->is_empty())
00192 throw std::underflow_error ("List is empty");
00193
00194 Node* retValue = this->get_prev();
00195 retValue->del();
00196
00197 return retValue;
00198 }
00204 class Iterator : public Node::Iterator
00205 {
00206
00207 public:
00208
00210 Iterator(GenDlist<Node_Type, T> & list) : Dnode<T>::Iterator(&list)
00211 {
00212
00213 }
00214
00216 Iterator(GenDlist<Node_Type, T> & list, GenDlist<Node_Type, T> * curr)
00217 : Dnode<T>::Iterator(&list, curr)
00218 {
00219
00220 }
00221
00222
00224 Iterator() : Dnode<T>::Iterator() { }
00225
00227 Iterator(const Iterator & it) : Dnode<T>::Iterator(it) { }
00228
00230 Iterator & operator = (const Iterator & it)
00231 {
00232 if (this == &it)
00233 return *this;
00234
00235 Dnode<T>::Iterator::operator = (it);
00236
00237 return *this;
00238 }
00239
00240 Node * get_current()
00241 {
00242 return static_cast<Node*>(Dnode<T>::Iterator::get_current());
00243 }
00244
00246 Node * del() { return static_cast<Node*>(Dnode<T>::Iterator::del()); }
00247 };
00248 };
00254 template <typename T>
00255 class Dlist : public GenDlist<Dlist_Node, T>
00256 {
00257
00258 public:
00259
00261 typedef typename GenDlist<Dlist_Node, T>::Node Node;
00262
00264 typedef typename GenDlist<Dlist_Node, T>::Iterator Iterator;
00265 };
00266
00272 template <typename T>
00273 class DlistVtl : public GenDlist<Dlist_Node_Vtl, T>
00274 {
00275
00276 public:
00277
00279 typedef typename GenDlist<Dlist_Node_Vtl, T>::Node Node;
00280
00282 typedef typename GenDlist<Dlist_Node_Vtl, T>::Iterator Iterator ;
00283 };
00284
00285 }
00286
00287 # endif
00288