ConstContainerIterator.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 //   This program is free software: you can redistribute it and/or modify
00008 //   it under the terms of the GNU General Public License as published by
00009 //   the Free Software Foundation, version 3 of the Licence.
00010 //
00011 //   This program is distributed in the hope that it will be useful,
00012 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //   GNU General Public License for more details.
00015 //
00016 //   You should have received a copy of the GNU General Public License
00017 //   along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 #ifndef CONST_CONTAINER_ITERATOR_H_
00020 #define CONST_CONTAINER_ITERATOR_H_
00021 
00022 #include "VariableDefs.h"
00023 
00024 template <class T> class VariableContainerBase;
00025 template<class T, class IT> class VariableContainer;
00026 
00028 template <class T> class ConstContainerIterator
00029 {
00030  protected:
00031   typedef std::vector<T> TVector;
00032   typedef std::vector<typename T::const_iterator> TIteratorVector;
00033 
00034   std::vector<typename T::const_iterator> iterator_vector;
00035   std::vector<typename T::const_iterator> begin_iterator_vector;
00036   std::vector<typename T::const_iterator> end_iterator_vector;
00037 
00038  static ConstContainerIterator begin(const TVector &v)
00039   {
00040     ConstContainerIterator i;
00041     for (typename TVector::const_iterator it = v.begin(); 
00042    it != v.end(); ++it)
00043       {
00044   i.iterator_vector.push_back(it->begin());
00045   i.begin_iterator_vector.push_back(it->begin());
00046   i.end_iterator_vector.push_back(it->end());
00047       }
00048     return i;
00049   };
00050   static ConstContainerIterator end(const TVector &v)
00051   {
00052     ConstContainerIterator i;
00053     for (typename TVector::const_iterator it = v.begin(); 
00054    it != v.end(); ++it)
00055       {
00056   i.iterator_vector.push_back(it->end());
00057   i.begin_iterator_vector.push_back(it->begin());
00058   i.end_iterator_vector.push_back(it->end());
00059       }
00060     return i;
00061   };
00062 
00063  public:  
00065   ConstContainerIterator(void)
00066   {}
00067 
00069   ConstContainerIterator(const ConstContainerIterator &another):
00070    iterator_vector(another.iterator_vector),
00071    begin_iterator_vector(another.begin_iterator_vector),
00072    end_iterator_vector(another.end_iterator_vector)
00073    {};
00074 
00076   virtual ~ConstContainerIterator(void) {};
00077 
00079   ConstContainerIterator &operator=(const ConstContainerIterator &another)
00080    { 
00081      if (this != &another)
00082        {
00083    iterator_vector = another.iterator_vector;
00084    begin_iterator_vector = another.begin_iterator_vector; 
00085    end_iterator_vector = another.end_iterator_vector; 
00086        }
00087      return *this;
00088    };
00089 
00091   bool operator==(const ConstContainerIterator &another) const
00092    { return iterator_vector == another.iterator_vector; };
00093 
00095   bool operator!=(const ConstContainerIterator &another) const
00096   { return not (*this == another); };
00097 
00099   virtual int operator++(void)
00100    {
00101      bool found_a_non_final_iterator = false;
00102      for (size_t i = 0 ; i < iterator_vector.size(); ++i)
00103        {
00104    if (iterator_vector.at(i) + 1 == end_iterator_vector.at(i))
00105      { iterator_vector.at(i) = begin_iterator_vector.at(i); }
00106    else
00107      { 
00108        ++iterator_vector.at(i);
00109        found_a_non_final_iterator = true; 
00110        break;
00111      }
00112        }
00113      if (not found_a_non_final_iterator)
00114        { iterator_vector = end_iterator_vector; }
00115      return 1;
00116    };
00117 
00119   ConstContainerIterator operator+(size_t i) const
00120   { 
00121     ConstContainerIterator it(*this);
00122     for (size_t n = 0; n < i; ++n) { ++it; }
00123     return it;
00124   };
00125 
00127   void set_values(VariableValueMap * vvm) const
00128   {
00129     for (typename TIteratorVector::const_iterator it = 
00130      iterator_vector.begin();
00131    it != iterator_vector.end(); 
00132    ++it)
00133       { it->set_values(vvm); }
00134   }
00135   
00139   TVector operator*(void)
00140     { return TVector(); }
00141 
00142   friend class VariableContainerBase<T>;
00143   template<class X,class Y> friend class VariableContainer;
00144 };
00145 
00146 #endif // CONST_CONTAINER_ITERATOR_H_
 All Classes Files Functions Typedefs Enumerations Defines
Generated on Wed Dec 15 01:11:58 2010 for hfst-twolc (documentation under construction) by  doxygen 1.6.3