|
Sacado Package Browser (Single Doxygen Collection) Version of the Day
|
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 namespace Sacado { 00039 00048 template <typename BaseT> 00049 class TemplateIterator : public std::iterator<std::input_iterator_tag, 00050 BaseT> { 00051 public: 00052 00054 TemplateIterator( 00055 typename std::vector< Teuchos::RCP<BaseT> >::iterator p) : 00056 object_iterator(p) {} 00057 00058 // No default constructor 00059 // Use default copy constructor and copy assignment 00060 00062 bool operator==(const TemplateIterator& t) const { 00063 return object_iterator == t.objectIterator; 00064 } 00065 00067 bool operator!=(const TemplateIterator& t) const { 00068 return object_iterator != t.object_iterator; 00069 } 00070 00072 typename Sacado::TemplateIterator<BaseT>::reference 00073 operator*() const { 00074 return *(*object_iterator); 00075 } 00076 00078 typename Sacado::TemplateIterator<BaseT>::pointer 00079 operator->() const { 00080 return &(*(*object_iterator)); 00081 } 00082 00084 TemplateIterator& operator++() { 00085 ++object_iterator; 00086 return *this; 00087 } 00088 00090 TemplateIterator operator++(int) { 00091 TemplateIterator tmp = *this; 00092 ++(*this); 00093 return tmp; 00094 } 00095 00097 Teuchos::RCP<BaseT> rcp() const { 00098 return *object_iterator; 00099 } 00100 00101 private: 00102 00104 typename std::vector< Teuchos::RCP<BaseT> >::iterator object_iterator; 00105 00106 }; 00107 00116 template <typename BaseT> 00117 class ConstTemplateIterator : public std::iterator<std::input_iterator_tag, 00118 BaseT> { 00119 public: 00120 00122 ConstTemplateIterator( 00123 typename std::vector< Teuchos::RCP<BaseT> >::const_iterator p) : 00124 object_iterator(p) {} 00125 00126 // No default constructor 00127 // Use default copy constructor and copy assignment 00128 00130 bool operator==(const ConstTemplateIterator& t) const { 00131 return object_iterator == t.objectIterator; 00132 } 00133 00135 bool operator!=(const ConstTemplateIterator& t) const { 00136 return object_iterator != t.object_iterator; 00137 } 00138 00140 typename Sacado::ConstTemplateIterator<BaseT>::reference 00141 operator*() const { 00142 return *(*object_iterator); 00143 } 00144 00146 typename Sacado::ConstTemplateIterator<BaseT>::pointer 00147 operator->() const { 00148 return &(*(*object_iterator)); 00149 } 00150 00152 ConstTemplateIterator& operator++() { 00153 ++object_iterator; 00154 return *this; 00155 } 00156 00158 ConstTemplateIterator operator++(int) { 00159 ConstTemplateIterator tmp = *this; 00160 ++(*this); 00161 return tmp; 00162 } 00163 00165 Teuchos::RCP<BaseT> rcp() const { 00166 return *object_iterator; 00167 } 00168 00169 private: 00170 00172 typename std::vector< Teuchos::RCP<BaseT> >::const_iterator object_iterator; 00173 00174 }; 00175 00176 } 00177 00178 #endif
1.7.4