00001
00002 #ifndef __MIX_NODELIST_H_
00003 #define __MIX_NODELIST_H_
00004
00005 #include "classes.h"
00006
00007 #include <list>
00008
00009 namespace MiX{
00016 template <class charT,class traitsT>
00017 class NodeList : public std::list<Node<charT,traitsT>* >{
00018 public:
00019 typedef Node<charT,traitsT>* value_type;
00020 typedef NodeList<charT,traitsT> this_type;
00021 typedef typename std::list<value_type>::iterator iterator;
00022 typedef typename std::list<value_type>::const_iterator const_iterator;
00023
00024 #ifdef MiX_COMPILER_SUPPORT_MEMBER_TEMPLATE
00025
00034 template <class NodeT>
00035 class Iterator{
00036 typedef NodeT* pointer;
00037 typedef NodeT& reference;
00038
00039 typedef NodeList<charT,traitsT> container_type;
00040 typedef container_type::iterator basic_iterator;
00041 typedef Iterator<NodeT> this_type;
00042
00043 basic_iterator it_;
00044 container_type* container_;
00045
00047 Iterator(container_type* container,basic_iterator it){
00048 container_ = container;
00049 it_ = it;
00050 };
00051 public:
00057 Iterator(){
00058 container_ = NULL;
00059 };
00061 reference operator*(){
00062 return dynamic_cast<NodeT&>(**it_);
00063 };
00065 pointer operator->(){
00066 return dynamic_cast<NodeT*>(*it_);
00067 };
00069 this_type operator++(){
00070 basic_iterator itEnd=container_->end();
00071 ++it_;
00072 while(it_!=itEnd){
00073 if((*it_)->getType()==NodeT::type()) break;
00074 ++it_;
00075 }
00076 return *this;
00077 };
00079 this_type operator--(){
00080 basic_iterator itBegin=container_->begin();
00081 while(it_!=itBegin){
00082 --it_;
00083 if((*it_)->getType()==NodeT::type()) break;
00084 }
00085 return *this;
00086 };
00093 this_type operator++(int dmy){
00094 this_type ret = *this;
00095 ++(*this);
00096 return ret;
00097 };
00104 this_type operator--(int dmy){
00105 this_type ret = *this;
00106 --(*this);
00107 return ret;
00108 };
00109
00110 bool operator==(this_type& r)const{
00111 return it_==r.it_;
00112 };
00113
00114 bool operator!=(this_type& r)const{
00115 return !(*this==r);
00116 };
00117
00118 friend class NodeList<charT,traitsT>;
00119 };
00123 template <class NodeT>
00124 class ConstIterator{
00125 typedef const NodeT* pointer;
00126 typedef const NodeT& reference;
00127
00128 typedef NodeList<charT,traitsT> container_type;
00129 typedef container_type::const_iterator basic_iterator;
00130 typedef ConstIterator<NodeT> this_type;
00131
00132 basic_iterator it_;
00133 container_type* container_;
00134
00136 ConstIterator(container_type* container,basic_iterator it){
00137 container_ = container;
00138 it_ = it;
00139 };
00140 public:
00146 ConstIterator(){ container_ = NULL; };
00148 pointer operator->(){return dynamic_cast<pointer>(*it_); };
00150 reference operator*(){return dynamic_cast<reference>(**it_);};
00152 this_type operator++(){
00153 basic_iterator itEnd=container_->end();
00154 ++it_;
00155 while(it_!=itEnd){
00156 if((*it_)->getType()==NodeT::type()) break;
00157 ++it_;
00158 }
00159 return *this;
00160 };
00162 this_type operator--(){
00163 basic_iterator itBegin=container_->begin();
00164 while(it_!=itBegin){
00165 --it_;
00166 if((*it_)->getType()==NodeT::type()) break;
00167 }
00168 return *this;
00169 };
00176 this_type operator++(int dmy){
00177 this_type ret = *this;
00178 ++(*this);
00179 return ret;
00180 };
00187 this_type operator--(int dmy){
00188 this_type ret = *this;
00189 --(*this);
00190 return ret;
00191 };
00192
00193 bool operator==(this_type& r)const{
00194 return it_==r.it_;
00195 };
00196
00197 bool operator!=(this_type& r)const{
00198 return !(*this==r);
00199 };
00200
00201 friend class NodeList<charT,traitsT>;
00202 };
00203
00204 public:
00206 template <class NodeT>
00207 Iterator<NodeT> Begin(){
00208 this_type::Iterator<NodeT> ret = this_type::Iterator<NodeT>(this,begin());
00209 if((*(ret.it_))->getType()!=NodeT::type()) ++ret;
00210 return ret;
00211 };
00213 template <class NodeT>
00214 ConstIterator<NodeT> Begin()const{
00215 this_type::ConstIterator<NodeT> ret = this_type::ConstIterator<NodeT>(this,begin());
00216 if((*(ret.it_))->getType()!=NodeT::type()) ++ret;
00217 return ret;
00218 };
00220 template <class NodeT>
00221 Iterator<NodeT> End(){
00222 return this_type::Iterator<NodeT>(this,end());
00223 };
00225 template <class NodeT>
00226 ConstIterator<NodeT> End()const{
00227 return this_type::ConstIterator<NodeT>(this,end());
00228 };
00229 #endif
00230 };
00231 }
00232
00233
00234 #endif