メインページ   名前空間一覧   クラス階層   構成   ファイル一覧   名前空間メンバ   構成メンバ   ファイルメンバ  

NodeList.h

解説を見る。
00001 // -*- mode: C++ -*-
00002 #ifndef __MIX_NODELIST_H_
00003 #define __MIX_NODELIST_H_
00004 
00005 #include "classes.h"
00006 
00007 #include <list>
00008  
00009 namespace MiX{
00010 
00011   template <class charT,class char_traits,class xml_traits>
00012   class NodeList : public std::list<Node<charT,char_traits,xml_traits>* >{
00013   public:
00014     typedef std::list<Node<charT,char_traits,xml_traits>* > super_type;
00015     typedef Node<charT,char_traits,xml_traits>* value_type;
00016     typedef NodeList<charT,char_traits,xml_traits> this_type;
00017     typedef typename std::list<value_type>::iterator iterator;
00018     typedef typename std::list<value_type>::const_iterator const_iterator;
00019 
00020     NodeList() : super_type(){ };
00021     NodeList(const NodeList& src) : super_type(src){ };
00022 
00032     template <class NodeT>
00033     class Iterator{
00034       typedef NodeT* pointer;
00035       typedef NodeT& reference;
00036 
00037       typedef NodeList<charT,char_traits,xml_traits> container_type;
00038       typedef container_type::iterator basic_iterator;
00039       typedef Iterator<NodeT> this_type;
00040 
00041       basic_iterator it_;
00042       container_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<charT,char_traits,xml_traits>;
00117     };
00121     template <class NodeT>
00122     class ConstIterator{
00123       typedef const NodeT* pointer;
00124       typedef const NodeT& reference;
00125 
00126       typedef NodeList<charT,char_traits,xml_traits> container_type;
00127       typedef container_type::const_iterator basic_iterator;
00128       typedef ConstIterator<NodeT> this_type;
00129 
00130       basic_iterator it_;
00131       container_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<charT,char_traits,xml_traits>;
00200     };
00201 
00202   public:
00204     template <class NodeT>
00205     Iterator<NodeT> End(){
00206       return this_type::Iterator<NodeT>(this,end());
00207     }
00209     template <class NodeT>
00210     ConstIterator<NodeT> End()const{
00211       return this_type::ConstIterator<NodeT>(this,end());
00212     }
00213 
00215     template <class NodeT>
00216     Iterator<NodeT> Begin(){
00217       if( empty() ) {
00218         return End<NodeT>();
00219       } else {
00220         this_type::Iterator<NodeT> ret = this_type::Iterator<NodeT>(this,begin());
00221         if((*(ret.it_))->getType()!=NodeT::type()) ++ret;
00222         return ret;
00223       }
00224     }
00226     template <class NodeT>
00227     ConstIterator<NodeT> Begin()const{
00228       if( empty() ) {
00229         return End<NodeT>();
00230       } else {
00231         this_type::ConstIterator<NodeT> ret = this_type::ConstIterator<NodeT>(this,begin());
00232         if((*(ret.it_))->getType()!=NodeT::type()) ++ret;
00233         return ret;
00234       }
00235     }
00236   };
00237 }
00238 
00239 
00240 #endif

MiXに対してThu Sep 4 05:11:11 2003に生成されました。 doxygen1.2.18