|
Teuchos - Trilinos Tools Package
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) 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 // 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 #ifndef TEUCHOS_REDUCTION_OP_HELPERS_HPP 00043 #define TEUCHOS_REDUCTION_OP_HELPERS_HPP 00044 00045 #include "Teuchos_ReductionOp.hpp" 00046 #include "Teuchos_SerializationTraitsHelpers.hpp" 00047 #include "Teuchos_SerializerHelpers.hpp" 00048 00049 namespace Teuchos { 00050 00057 template<typename Ordinal, typename T, typename Serializer> 00058 class CharToValueTypeReductionOpImp : public ValueTypeReductionOp<Ordinal,char> 00059 { 00060 public: 00062 CharToValueTypeReductionOpImp( 00063 const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp, 00064 const RCP<const Serializer>& serializer 00065 ); 00067 void reduce( 00068 const Ordinal charCount 00069 ,const char charInBuffer[] 00070 ,char charInoutBuffer[] 00071 ) const; 00072 private: 00073 RCP<const ValueTypeReductionOp<Ordinal,T> > reductOp_; 00074 RCP<const Serializer> serializer_; 00075 // Not defined and not to be called! 00076 CharToValueTypeReductionOpImp(); 00077 CharToValueTypeReductionOpImp(const CharToValueTypeReductionOpImp&); 00078 CharToValueTypeReductionOpImp& operator=(const CharToValueTypeReductionOpImp&); 00079 }; 00080 00087 template<typename Ordinal, typename T, 00088 typename Serializer = typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00089 class CharToValueTypeReductionOp : 00090 public CharToValueTypeReductionOpImp<Ordinal,T,Serializer> 00091 { 00092 public: 00093 typedef CharToValueTypeReductionOpImp<Ordinal,T,Serializer> Base; 00095 CharToValueTypeReductionOp( 00096 const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp, 00097 const RCP<const Serializer>& serializer 00098 ) : Base(reductOp, serializer) {} 00099 }; 00100 00110 template<typename Ordinal, typename T> 00111 class CharToValueTypeReductionOp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> : 00112 public CharToValueTypeReductionOpImp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00113 { 00114 public: 00115 typedef DefaultSerializer<Ordinal,T> DS; // work around for parsing bug in gcc 4.1-4.2 00116 typedef typename DS::DefaultSerializerType Serializer; 00117 typedef CharToValueTypeReductionOpImp<Ordinal,T,Serializer> Base; 00119 CharToValueTypeReductionOp( 00120 const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp, 00121 const RCP<const Serializer>& serializer = DS::getDefaultSerializerRCP() 00122 ) : Base(reductOp, serializer) {} 00123 }; 00124 00131 template<typename Ordinal, typename T> 00132 class CharToReferenceTypeReductionOp : public ValueTypeReductionOp<Ordinal,char> 00133 { 00134 public: 00136 CharToReferenceTypeReductionOp( 00137 const RCP<const Serializer<Ordinal,T> > &serializer 00138 ,const RCP<const ReferenceTypeReductionOp<Ordinal,T> > &reductOp 00139 ); 00141 void reduce( 00142 const Ordinal charCount 00143 ,const char charInBuffer[] 00144 ,char charInoutBuffer[] 00145 ) const; 00146 private: 00147 RCP<const Serializer<Ordinal,T> > serializer_; 00148 RCP<const ReferenceTypeReductionOp<Ordinal,T> > reductOp_; 00149 // Not defined and not to be called! 00150 CharToReferenceTypeReductionOp(); 00151 CharToReferenceTypeReductionOp(const CharToReferenceTypeReductionOp&); 00152 CharToReferenceTypeReductionOp& operator=(const CharToReferenceTypeReductionOp&); 00153 }; 00154 00155 // ///////////////////////////////////// 00156 // Template implementations 00157 00158 // 00159 // CharToValueTypeReductionOpImp 00160 // 00161 00162 template<typename Ordinal, typename T, typename Serializer> 00163 CharToValueTypeReductionOpImp<Ordinal,T,Serializer>::CharToValueTypeReductionOpImp( 00164 const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp, 00165 const RCP<const Serializer>& serializer 00166 ) 00167 :reductOp_(reductOp), serializer_(serializer) 00168 {} 00169 00170 template<typename Ordinal, typename T, typename Serializer> 00171 void CharToValueTypeReductionOpImp<Ordinal,T,Serializer>::reduce( 00172 const Ordinal charCount 00173 ,const char charInBuffer[] 00174 ,char charInoutBuffer[] 00175 ) const 00176 { 00177 ConstValueTypeDeserializationBuffer<Ordinal,T,Serializer> 00178 inBuffer(charCount,charInBuffer,serializer_); 00179 ValueTypeDeserializationBuffer<Ordinal,T,Serializer> 00180 inoutBuffer(charCount,charInoutBuffer,serializer_); 00181 reductOp_->reduce( 00182 inBuffer.getCount(),inBuffer.getBuffer(),inoutBuffer.getBuffer() 00183 ); 00184 } 00185 00186 // 00187 // CharToReferenceTypeReductionOp 00188 // 00189 00190 template<typename Ordinal, typename T> 00191 CharToReferenceTypeReductionOp<Ordinal,T>::CharToReferenceTypeReductionOp( 00192 const RCP<const Serializer<Ordinal,T> > &serializer 00193 ,const RCP<const ReferenceTypeReductionOp<Ordinal,T> > &reductOp 00194 ) 00195 :serializer_(serializer), reductOp_(reductOp) 00196 {} 00197 00198 template<typename Ordinal, typename T> 00199 void CharToReferenceTypeReductionOp<Ordinal,T>::reduce( 00200 const Ordinal charCount 00201 ,const char charInBuffer[] 00202 ,char charInoutBuffer[] 00203 ) const 00204 { 00205 ConstReferenceTypeDeserializationBuffer<Ordinal,T> 00206 inBuffer(*serializer_,charCount,charInBuffer); 00207 ReferenceTypeDeserializationBuffer<Ordinal,T> 00208 inoutBuffer(*serializer_,charCount,charInoutBuffer); 00209 reductOp_->reduce( 00210 inBuffer.getCount(),inBuffer.getBuffer(),inoutBuffer.getBuffer() 00211 ); 00212 } 00213 00214 } // namespace Teuchos 00215 00216 #endif // TEUCHOS_REDUCTION_OP_HELPERS_HPP
1.7.6.1