Sacado_TemplateIterator.hpp

Go to the documentation of this file.
00001 // $Id: Sacado_TemplateIterator.hpp,v 1.2.2.2 2007/08/14 00:19:08 etphipp Exp $ 
00002 // $Source: /space/CVS/Trilinos/packages/sacado/src/template/Sacado_TemplateIterator.hpp,v $ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #ifndef SACADO_TEMPLATEITERATOR_HPP
00033 #define SACADO_TEMPLATEITERATOR_HPP
00034 
00035 #include <vector>
00036 #include <iterator>
00037 
00038 #include "Sacado_TemplateManager.hpp"
00039 
00040 namespace Sacado {
00041 
00050   template <typename TypeSeq, typename BaseT, template<typename> class ObjectT>
00051   class TemplateIterator : public std::iterator<std::input_iterator_tag,
00052             BaseT> {
00053   public:
00054 
00056     TemplateIterator(
00057       Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>& m,
00058       typename std::vector< Teuchos::RCP<BaseT> >::iterator p) :
00059       manager(&m), object_iterator(p) {}
00060     
00061     // No default constructor
00062     // Use default copy constructor and copy assignment
00063 
00065     bool operator==(const TemplateIterator& t) const {
00066       return object_iterator == t.objectIterator; 
00067     }
00068 
00070     bool operator!=(const TemplateIterator& t) const {
00071       return object_iterator != t.object_iterator; 
00072     }
00073 
00075     typename Sacado::TemplateIterator<TypeSeq, BaseT, ObjectT>::reference 
00076     operator*() const {
00077       return *(*object_iterator);
00078     }
00079 
00081     typename Sacado::TemplateIterator<TypeSeq, BaseT, ObjectT>::pointer 
00082     operator->() const {
00083       return &(*(*object_iterator));
00084     }
00085 
00087     TemplateIterator& operator++() {
00088       ++object_iterator;
00089       return *this;
00090     }
00091 
00093     TemplateIterator operator++(int) {
00094       TemplateIterator tmp = *this;
00095       ++(*this);
00096       return tmp;
00097     }
00098 
00099   private:
00100 
00102     Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>* manager;
00103 
00105     typename std::vector< Teuchos::RCP<BaseT> >::iterator object_iterator;
00106     
00107   };
00108 
00117   template <typename TypeSeq, typename BaseT, template<typename> class ObjectT>
00118   class ConstTemplateIterator : public std::iterator<std::input_iterator_tag,
00119                  BaseT> {
00120   public:
00121 
00123     ConstTemplateIterator(
00124        const Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>& m,
00125        typename std::vector< Teuchos::RCP<BaseT> >::const_iterator p) :
00126       manager(&m), object_iterator(p) {}
00127     
00128     // No default constructor
00129     // Use default copy constructor and copy assignment
00130 
00132     bool operator==(const ConstTemplateIterator& t) const {
00133       return object_iterator == t.objectIterator; 
00134     }
00135 
00137     bool operator!=(const ConstTemplateIterator& t) const {
00138       return object_iterator != t.object_iterator; 
00139     }
00140 
00142     const typename Sacado::ConstTemplateIterator<TypeSeq, BaseT, ObjectT>::reference 
00143     operator*() const {
00144       return *(*object_iterator);
00145     }
00146 
00148     const typename Sacado::ConstTemplateIterator<TypeSeq, BaseT, ObjectT>::pointer 
00149     operator->() const {
00150       return &(*(*object_iterator));
00151     }
00152 
00154     ConstTemplateIterator& operator++() {
00155       ++object_iterator;
00156       return *this;
00157     }
00158 
00160     ConstTemplateIterator operator++(int) {
00161       ConstTemplateIterator tmp = *this;
00162       ++(*this);
00163       return tmp;
00164     }
00165 
00166   private:
00167 
00169     const Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>* manager;
00170 
00172     typename std::vector< Teuchos::RCP<BaseT> >::const_iterator object_iterator;
00173     
00174   };
00175 
00176 }
00177 
00178 #endif

Generated on Tue Oct 20 12:55:07 2009 for Sacado Package Browser (Single Doxygen Collection) by doxygen 1.4.7