|
EpetraExt Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2001) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 //@HEADER 00028 00029 //----------------------------------------------------------------------- 00030 // EpetraExt_Transform.h 00031 //----------------------------------------------------------------------- 00032 00033 #ifndef EPETRAEXT_TRANSFORM_H 00034 #define EPETRAEXT_TRANSFORM_H 00035 00036 #include <EpetraExt_ConfigDefs.h> 00037 00038 namespace EpetraExt { 00039 00041 00048 template<typename T, typename U> 00049 class Transform 00050 { 00051 public: 00052 00055 00056 typedef T OriginalType; 00057 typedef T* OriginalTypePtr; 00058 typedef T& OriginalTypeRef; 00059 00060 typedef U NewType; 00061 typedef U* NewTypePtr; 00062 typedef U& NewTypeRef; 00063 00065 00067 virtual ~Transform() {} 00068 00071 00073 00089 virtual NewTypeRef operator()( OriginalTypeRef orig ) = 0; 00090 00092 00107 virtual bool fwd() = 0; 00108 00110 00124 virtual bool rvs() = 0; 00125 00127 00131 00133 00149 virtual bool analyze( OriginalTypeRef orig ); 00150 00152 00165 virtual NewTypeRef construct(); 00166 00168 00182 virtual bool isConstructed(); 00183 00185 00186 protected: 00187 00189 00194 Transform() 00195 : origObj_(0), 00196 newObj_(0) 00197 {} 00198 00199 OriginalTypePtr origObj_; 00200 00201 NewTypePtr newObj_; 00202 00203 private: 00204 Transform(const Transform<T,U>& src) 00205 :origObj_(src.origObj_), newObj_(src.newObj_) {} 00206 00207 Transform<T,U>& operator=(const Transform<T,U>& src) 00208 { 00209 //not currently supported 00210 abort(); 00211 return(*this); 00212 } 00213 00214 }; // end class Transform 00215 00216 template<typename T,typename U> 00217 bool 00218 Transform<T,U>:: 00219 analyze( OriginalTypeRef orig ) 00220 { 00221 origObj_ = &orig; 00222 newObj_ = &((*this)( *origObj_ )); 00223 return true; 00224 } 00225 00226 template<typename T,typename U> 00227 typename Transform<T,U>::NewTypeRef 00228 Transform<T,U>:: 00229 construct() 00230 { 00231 return *newObj_; 00232 } 00233 00234 template<typename T,typename U> 00235 bool 00236 Transform<T,U>:: 00237 isConstructed() 00238 { 00239 return ( newObj_ != 0 ); 00240 } 00241 00242 template<typename T, typename U> 00243 class StructuralTransform : public Transform<T,U> 00244 { 00245 public: 00246 bool fwd() { return true; } 00247 bool rvs() { return true; } 00248 00249 virtual ~StructuralTransform() {} 00250 }; 00251 00252 template<typename T> 00253 class SameTypeTransform : public Transform<T,T> 00254 { 00255 public: 00256 typedef T TransformType; 00257 typedef T* TransformTypePtr; 00258 typedef T& TransformTypeRef; 00259 00260 virtual ~SameTypeTransform() {} 00261 }; 00262 00263 template<typename T> 00264 class StructuralSameTypeTransform : public SameTypeTransform<T> 00265 { 00266 public: 00267 bool fwd() { return true; } 00268 bool rvs() { return true; } 00269 00270 virtual ~StructuralSameTypeTransform() {} 00271 }; 00272 00273 template<typename T> 00274 class InPlaceTransform : public SameTypeTransform<T> 00275 { 00276 public: 00277 typename Transform<T,T>::NewTypeRef 00278 operator() 00279 ( typename Transform<T,T>::OriginalTypeRef orig ) 00280 { this->origObj_ = &orig; 00281 this->newObj_ = &orig; 00282 return orig; 00283 } 00284 00285 virtual ~InPlaceTransform() {} 00286 }; 00287 00288 template<typename T> 00289 class ViewTransform : public SameTypeTransform<T> 00290 { 00291 public: 00292 bool fwd() { return true; } 00293 bool rvs() { return true; } 00294 00295 virtual ~ViewTransform() {} 00296 }; 00297 00298 } //namespace EpetraExt 00299 00300 #endif //EPETRAEXT_TRANSFORM_H
1.7.4