|
EpetraExt
Development
|
00001 //@HEADER 00002 // *********************************************************************** 00003 // 00004 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00005 // Copyright (2011) Sandia Corporation 00006 // 00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00008 // the U.S. Government retains certain rights in this software. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 //@HEADER 00041 00042 //----------------------------------------------------------------------- 00043 // EpetraExt_Transform.h 00044 //----------------------------------------------------------------------- 00045 00046 #ifndef EPETRAEXT_TRANSFORM_H 00047 #define EPETRAEXT_TRANSFORM_H 00048 00049 #include <EpetraExt_ConfigDefs.h> 00050 00051 #include <Teuchos_RCP.hpp> 00052 00053 namespace EpetraExt { 00054 00056 00063 template<typename T, typename U> 00064 class Transform 00065 { 00066 public: 00067 00070 00071 typedef T OriginalType; 00072 typedef T* OriginalTypePtr; 00073 typedef Teuchos::RCP<T> OriginalTypeRCP; 00074 typedef T& OriginalTypeRef; 00075 00076 typedef U NewType; 00077 typedef U* NewTypePtr; 00078 typedef Teuchos::RCP<U> NewTypeRCP; 00079 typedef U& NewTypeRef; 00080 00082 00084 virtual ~Transform() {} 00085 00088 00090 00106 virtual NewTypeRef operator()( OriginalTypeRef orig ) = 0; 00107 00109 00124 virtual bool fwd() = 0; 00125 00127 00141 virtual bool rvs() = 0; 00142 00144 00148 00150 00166 virtual bool analyze( OriginalTypeRef orig ); 00167 00169 00182 virtual NewTypeRef construct(); 00183 00185 00199 virtual bool isConstructed(); 00200 00202 00203 protected: 00204 00206 00211 Transform() 00212 : origObj_(0), 00213 newObj_(0) 00214 {} 00215 00216 OriginalTypePtr origObj_; 00217 00218 NewTypePtr newObj_; 00219 00220 private: 00221 Transform(const Transform<T,U>& src) 00222 :origObj_(src.origObj_), newObj_(src.newObj_) {} 00223 00224 Transform<T,U>& operator=(const Transform<T,U>& src) 00225 { 00226 //not currently supported 00227 abort(); 00228 return(*this); 00229 } 00230 00231 }; // end class Transform 00232 00233 template<typename T,typename U> 00234 bool 00235 Transform<T,U>:: 00236 analyze( OriginalTypeRef orig ) 00237 { 00238 origObj_ = &orig; 00239 newObj_ = &((*this)( *origObj_ )); 00240 return true; 00241 } 00242 00243 template<typename T,typename U> 00244 typename Transform<T,U>::NewTypeRef 00245 Transform<T,U>:: 00246 construct() 00247 { 00248 return *newObj_; 00249 } 00250 00251 template<typename T,typename U> 00252 bool 00253 Transform<T,U>:: 00254 isConstructed() 00255 { 00256 return ( newObj_ != 0 ); 00257 } 00258 00259 template<typename T, typename U> 00260 class StructuralTransform : public Transform<T,U> 00261 { 00262 public: 00263 bool fwd() { return true; } 00264 bool rvs() { return true; } 00265 00266 virtual ~StructuralTransform() {} 00267 }; 00268 00269 template<typename T> 00270 class SameTypeTransform : public Transform<T,T> 00271 { 00272 public: 00273 typedef T TransformType; 00274 typedef T* TransformTypePtr; 00275 typedef T& TransformTypeRef; 00276 00277 virtual ~SameTypeTransform() {} 00278 }; 00279 00280 template<typename T> 00281 class StructuralSameTypeTransform : public SameTypeTransform<T> 00282 { 00283 public: 00284 bool fwd() { return true; } 00285 bool rvs() { return true; } 00286 00287 virtual ~StructuralSameTypeTransform() {} 00288 }; 00289 00290 template<typename T> 00291 class InPlaceTransform : public SameTypeTransform<T> 00292 { 00293 public: 00294 typename Transform<T,T>::NewTypeRef 00295 operator() 00296 ( typename Transform<T,T>::OriginalTypeRef orig ) 00297 { this->origObj_ = &orig; 00298 this->newObj_ = &orig; 00299 return orig; 00300 } 00301 00302 virtual ~InPlaceTransform() {} 00303 }; 00304 00305 template<typename T> 00306 class ViewTransform : public SameTypeTransform<T> 00307 { 00308 public: 00309 bool fwd() { return true; } 00310 bool rvs() { return true; } 00311 00312 virtual ~ViewTransform() {} 00313 }; 00314 00315 } //namespace EpetraExt 00316 00317 #endif //EPETRAEXT_TRANSFORM_H
1.7.6.1