Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ReductionOpHelpers.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_REDUCTION_OP_HELPERS_HPP
43 #define TEUCHOS_REDUCTION_OP_HELPERS_HPP
44 
45 #include "Teuchos_ReductionOp.hpp"
48 
49 namespace Teuchos {
50 
57 template<typename Ordinal, typename T, typename Serializer>
59 {
60 public:
63  const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp,
64  const RCP<const Serializer>& serializer
65  );
67  void reduce(
68  const Ordinal charCount
69  ,const char charInBuffer[]
70  ,char charInoutBuffer[]
71  ) const;
72 private:
75  // Not defined and not to be called!
79 };
80 
87 template<typename Ordinal, typename T,
90  public CharToValueTypeReductionOpImp<Ordinal,T,Serializer>
91 {
92 public:
96  const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp,
97  const RCP<const Serializer>& serializer
98  ) : Base(reductOp, serializer) {}
99 };
100 
110 template<typename Ordinal, typename T>
111 class CharToValueTypeReductionOp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> :
112  public CharToValueTypeReductionOpImp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType>
113 {
114 public:
115  typedef DefaultSerializer<Ordinal,T> DS; // work around for parsing bug in gcc 4.1-4.2
120  const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp,
121  const RCP<const Serializer>& serializer = DS::getDefaultSerializerRCP()
122  ) : Base(reductOp, serializer) {}
123 };
124 
131 template<typename Ordinal, typename T>
133 {
134 public:
137  const RCP<const Serializer<Ordinal,T> > &serializer
138  ,const RCP<const ReferenceTypeReductionOp<Ordinal,T> > &reductOp
139  );
141  void reduce(
142  const Ordinal charCount
143  ,const char charInBuffer[]
144  ,char charInoutBuffer[]
145  ) const;
146 private:
149  // Not defined and not to be called!
153 };
154 
155 // /////////////////////////////////////
156 // Template implementations
157 
158 //
159 // CharToValueTypeReductionOpImp
160 //
161 
162 template<typename Ordinal, typename T, typename Serializer>
164  const RCP<const ValueTypeReductionOp<Ordinal,T> > &reductOp,
165  const RCP<const Serializer>& serializer
166  )
167  :reductOp_(reductOp), serializer_(serializer)
168 {}
169 
170 template<typename Ordinal, typename T, typename Serializer>
172  const Ordinal charCount
173  ,const char charInBuffer[]
174  ,char charInoutBuffer[]
175  ) const
176 {
178  inBuffer(charCount,charInBuffer,serializer_);
180  inoutBuffer(charCount,charInoutBuffer,serializer_);
181  reductOp_->reduce(
182  inBuffer.getCount(),inBuffer.getBuffer(),inoutBuffer.getBuffer()
183  );
184 }
185 
186 //
187 // CharToReferenceTypeReductionOp
188 //
189 
190 template<typename Ordinal, typename T>
192  const RCP<const Serializer<Ordinal,T> > &serializer
193  ,const RCP<const ReferenceTypeReductionOp<Ordinal,T> > &reductOp
194  )
195  :serializer_(serializer), reductOp_(reductOp)
196 {}
197 
198 template<typename Ordinal, typename T>
200  const Ordinal charCount
201  ,const char charInBuffer[]
202  ,char charInoutBuffer[]
203  ) const
204 {
206  inBuffer(*serializer_,charCount,charInBuffer);
208  inoutBuffer(*serializer_,charCount,charInoutBuffer);
209  reductOp_->reduce(
210  inBuffer.getCount(),inBuffer.getBuffer(),inoutBuffer.getBuffer()
211  );
212 }
213 
214 } // namespace Teuchos
215 
216 #endif // TEUCHOS_REDUCTION_OP_HELPERS_HPP
A class for instantiating a default serialization object.
Strategy interface for the indirect serializing and deserializing objects of a given type handled usi...
void reduce(const Ordinal charCount, const char charInBuffer[], char charInoutBuffer[]) const
Encapsulate how an array of non-const objects with reference sematics is deserialized from a char[] a...
CharToValueTypeReductionOp(const RCP< const ValueTypeReductionOp< Ordinal, T > > &reductOp, const RCP< const Serializer > &serializer)
Encapsulate how an array of onst objects with reference sematics is deserialized from a char[] array ...
void reduce(const Ordinal charCount, const char charInBuffer[], char charInoutBuffer[]) const
Decorator class that uses traits to convert to and from char[] to typed buffers for objects that use ...
CharToValueTypeReductionOpImp & operator=(const CharToValueTypeReductionOpImp &)
Base interface class for user-defined reduction operations for objects that use value semantics...
RCP< const ReferenceTypeReductionOp< Ordinal, T > > reductOp_
Decorator class that uses a strategy object to convert to and from char[] to typed buffers for object...
RCP< const ValueTypeReductionOp< Ordinal, T > > reductOp_
RCP< const Serializer< Ordinal, T > > serializer_
CharToValueTypeReductionOp(const RCP< const ValueTypeReductionOp< Ordinal, T > > &reductOp, const RCP< const Serializer > &serializer=DS::getDefaultSerializerRCP())
Serialization traits class for types T that use value semantics.
Base interface class for user-defined reduction operations for objects that use reference semantics...
CharToValueTypeReductionOpImp< Ordinal, T, Serializer > Base
CharToReferenceTypeReductionOp & operator=(const CharToReferenceTypeReductionOp &)
Smart reference counting pointer class for automatic garbage collection.
Encapsulate how an array of non-const serialized objects with value sematics stored in a char[] array...
Encapsulate how an array of non-const serialized objects with value sematics stored in a char[] array...
Decorator class that uses traits to convert to and from char[] to typed buffers for objects that use ...