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 Char,class Traits,class XMLTraits>
00017 class NodeList : public MiX_STD::list<Node<Char,Traits,XMLTraits>* >{
00018 public:
00019 typedef MiX_STD::list<Node<Char,Traits,XMLTraits>* >::iterator iterator;
00020 typedef MiX_STD::list<Node<Char,Traits,XMLTraits>* >::const_iterator const_iterator;
00021 #ifdef MiX_COMPILER_SUPPORT_MEMBER_TEMPLATE
00022
00032 template <class NodeT>
00033 class Iterator{
00034 typedef NodeT* pointer;
00035 typedef NodeT& reference;
00036
00037 typedef NodeList<Char,Traits,XMLTraits> container_type;
00038 typedef container_type::iterator basic_iterator;
00039 typedef Iterator<NodeT> this_type;
00040
00041 basic_iterator it_;
00042 this_type* container_;
00043
00045 Iterator(container_type* container,basic_iterator it){
00046 container_ = container;
00047 it_ = it;
00048 };
00049 public:
00055 Iterator(){
00056 container_ = NULL;
00057 };
00059 reference operator*(){
00060 return dynamic_cast<NodeT&>(**it_);
00061 };
00063 pointer operator->(){
00064 return dynamic_cast<NodeT*>(*it_);
00065 };
00067 this_type operator++(){
00068 basic_iterator itEnd=container_->end();
00069 ++it_;
00070 while(it_!=itEnd){
00071 if((*it_)->getType()==NodeT::type()) break;
00072 ++it_;
00073 }
00074 return *this;
00075 };
00077 this_type operator--(){
00078 basic_iterator itBegin=container_->begin();
00079 while(it_!=itBegin){
00080 --it_;
00081 if((*it_)->getType()==NodeT::type()) break;
00082 }
00083 return *this;
00084 };
00091 this_type operator++(int dmy){
00092 this_type ret = *this;
00093 ++(*this);
00094 return ret;
00095 };
00102 this_type operator--(int dmy){
00103 this_type ret = *this;
00104 --(*this);
00105 return ret;
00106 };
00107
00108 bool operator==(this_type& r)const{
00109 return it_==r.it_;
00110 };
00111
00112 bool operator!=(this_type& r)const{
00113 return !(*this==r);
00114 };
00115
00116 friend class NodeList<Char,Traits,XMLTraits>;
00117 };
00121 template <class NodeT>
00122 class ConstIterator{
00123 typedef const NodeT* pointer;
00124 typedef const NodeT& reference;
00125
00126 typedef NodeList<Char,Traits,XMLTraits> container_type;
00127 typedef container_type::const_iterator basic_iterator;
00128 typedef ConstIterator<NodeT> this_type;
00129
00130 basic_iterator it_;
00131 this_type* container_;
00132
00134 ConstIterator(container_type* container,basic_iterator it){
00135 container_ = container;
00136 it_ = it;
00137 };
00138 public:
00144 ConstIterator(){ container_ = NULL; };
00146 pointer operator->(){return dynamic_cast<pointer>(*it_); };
00148 reference operator*(){return dynamic_cast<reference>(**it_);};
00150 this_type operator++(){
00151 basic_iterator itEnd=container_->end();
00152 ++it_;
00153 while(it_!=itEnd){
00154 if((*it_)->getType()==NodeT::type()) break;
00155 ++it_;
00156 }
00157 return *this;
00158 };
00160 this_type operator--(){
00161 basic_iterator itBegin=container_->begin();
00162 while(it_!=itBegin){
00163 --it_;
00164 if((*it_)->getType()==NodeT::type()) break;
00165 }
00166 return *this;
00167 };
00174 this_type operator++(int dmy){
00175 this_type ret = *this;
00176 ++(*this);
00177 return ret;
00178 };
00185 this_type operator--(int dmy){
00186 this_type ret = *this;
00187 --(*this);
00188 return ret;
00189 };
00190
00191 bool operator==(this_type& r)const{
00192 return it_==r.it_;
00193 };
00194
00195 bool operator!=(this_type& r)const{
00196 return !(*this==r);
00197 };
00198
00199 friend class NodeList<Char,Traits,XMLTraits>;
00200 };
00201
00202 public:
00204 template <class NodeT>
00205 Iterator<NodeT> Begin(){
00206 NodeList<Char,Traits,XMLTraits>::Iterator<NodeT> ret = NodeList<Char,Traits,XMLTraits>::Iterator<NodeT>(this,begin());
00207 if((*(ret.m_it))->getType()!=NodeT::type()) ++ret;
00208 return ret;
00209 };
00211 template <class NodeT>
00212 ConstIterator<NodeT> Begin()const{
00213 NodeList<Char,Traits,XMLTraits>::ConstIterator<NodeT> ret = NodeList<Char,Traits,XMLTraits>::ConstIterator<NodeT>(this,begin());
00214 if((*(ret.m_it))->getType()!=NodeT::type()) ++ret;
00215 return ret;
00216 };
00218 template <class NodeT>
00219 Iterator<NodeT> End(){
00220 return NodeList<Char,Traits,XMLTraits>::Iterator<NodeT>(this,end());
00221 };
00223 template <class NodeT>
00224 ConstIterator<NodeT> End()const{
00225 return NodeList<Char,Traits,XMLTraits>::ConstIterator<NodeT>(this,end());
00226 };
00227 #endif
00228 };
00229 }
00230
00231 #ifndef MIX_NODELIST_CPP_
00232 #include "NodeList.cpp"
00233 #endif
00234
00235 #endif