Sacado_TemplateIterator.hpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
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, typename 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 
00100     Teuchos::RCP<BaseT> rcp() const {
00101       return *object_iterator;
00102     }
00103 
00104   private:
00105 
00107     Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>* manager;
00108 
00110     typename std::vector< Teuchos::RCP<BaseT> >::iterator object_iterator;
00111     
00112   };
00113 
00122   template <typename TypeSeq, typename BaseT, typename ObjectT>
00123   class ConstTemplateIterator : public std::iterator<std::input_iterator_tag,
00124                                                      BaseT> {
00125   public:
00126 
00128     ConstTemplateIterator(
00129        const Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>& m,
00130        typename std::vector< Teuchos::RCP<BaseT> >::const_iterator p) :
00131       manager(&m), object_iterator(p) {}
00132     
00133     // No default constructor
00134     // Use default copy constructor and copy assignment
00135 
00137     bool operator==(const ConstTemplateIterator& t) const {
00138       return object_iterator == t.objectIterator; 
00139     }
00140 
00142     bool operator!=(const ConstTemplateIterator& t) const {
00143       return object_iterator != t.object_iterator; 
00144     }
00145 
00147     const typename Sacado::ConstTemplateIterator<TypeSeq, BaseT, ObjectT>::reference 
00148     operator*() const {
00149       return *(*object_iterator);
00150     }
00151 
00153     const typename Sacado::ConstTemplateIterator<TypeSeq, BaseT, ObjectT>::pointer 
00154     operator->() const {
00155       return &(*(*object_iterator));
00156     }
00157 
00159     ConstTemplateIterator& operator++() {
00160       ++object_iterator;
00161       return *this;
00162     }
00163 
00165     ConstTemplateIterator operator++(int) {
00166       ConstTemplateIterator tmp = *this;
00167       ++(*this);
00168       return tmp;
00169     }
00170 
00172     Teuchos::RCP<BaseT> rcp() const {
00173       return *object_iterator;
00174     }
00175 
00176   private:
00177 
00179     const Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>* manager;
00180 
00182     typename std::vector< Teuchos::RCP<BaseT> >::const_iterator object_iterator;
00183     
00184   };
00185 
00186 }
00187 
00188 #endif

Generated on Wed May 12 21:39:37 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7