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_SLIST_H
00045 # define TPL_SLIST_H
00046
00047 # include <ahDefs.H>
00048 # include <tpl_snode.H>
00049
00050 using namespace Aleph;
00051
00052 namespace Aleph {
00053
00062 template <typename T>
00063 class Slist : public Snode<T>
00064 {
00065
00066 public:
00067
00068 typedef Snode<T> Node;
00070 Slist() { }
00078 void insert_first(Node * node)
00079 {
00080
00081 I(node not_eq NULL);
00082 I(node->is_empty());
00083
00084 this->insert_next(node);
00085 }
00093 Node * remove_first() throw(std::exception, std::underflow_error)
00094 {
00095
00096 if (this->is_empty())
00097 throw std::underflow_error ("list is empty");
00098
00099 return this->remove_next();
00100 }
00102 Node * get_first() const Exception_Prototypes(std::underflow_error)
00103 {
00104
00105 if (this->is_empty())
00106 throw std::underflow_error ("list is empty");
00107
00108 return this->get_next();
00109 }
00118 class Iterator
00119 {
00120
00121 private:
00122
00123 Slist * list;
00124 Node * current;
00125
00126 public:
00127
00134 Iterator(Slist & _list) : list(&_list), current(list->get_first())
00135 {
00136
00137 }
00138
00140 bool has_current() const { return current != list; }
00141
00148 Node * get_current() throw(std::exception, std::overflow_error)
00149 {
00150
00151 if (not this->has_current())
00152 throw std::overflow_error ("");
00153
00154 return current;
00155 }
00156
00167 void next() throw(std::exception, std::overflow_error)
00168 {
00169
00170 if (not this->has_current())
00171 throw std::overflow_error ("");
00172
00173 current = current->get_next();
00174 }
00175
00177 void reset_first() { current = list->get_next(); }
00178 Iterator & operator = (Node * node)
00179 {
00180 if (this == node)
00181 return *this;
00182
00183 current = node;
00184 return *this;
00185 }
00186 };
00187 };
00188
00189 }
00190
00191 # endif
00192