Teuchos_SerializationTraitsHelpers.hpp

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 // 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 #ifndef TEUCHOS_SERIALIZATION_TRAITS_HELPERS_HPP
00030 #define TEUCHOS_SERIALIZATION_TRAITS_HELPERS_HPP
00031 
00032 #include "Teuchos_SerializationTraits.hpp"
00033 #include "Teuchos_ArrayView.hpp"
00034 
00035 namespace Teuchos {
00036 
00040 template <typename Ordinal, typename T>
00041 class ValueTypeSerializationBuffer {
00042 public:
00044   ValueTypeSerializationBuffer(
00045     const Ordinal count, T buffer[] 
00046     );
00050   ~ValueTypeSerializationBuffer();
00052   char* getCharBuffer() const;
00054   Ordinal getBytes() const;
00056   const ArrayView<char> getCharBufferView() const;
00057 private:
00058   Ordinal    count_;
00059   T          *buffer_;
00060   Ordinal    bytes_;
00061   char       *charBuffer_;
00062   // Not defined and not to be called
00063   ValueTypeSerializationBuffer();
00064   ValueTypeSerializationBuffer(const ValueTypeSerializationBuffer&);
00065   ValueTypeSerializationBuffer& operator=(const ValueTypeSerializationBuffer&);
00066 };
00067 
00071 template <typename Ordinal, typename T>
00072 class ConstValueTypeSerializationBuffer {
00073 public:
00075   ConstValueTypeSerializationBuffer(
00076     const Ordinal count, const T buffer[]
00077     );
00081   ~ConstValueTypeSerializationBuffer();
00083   const char* getCharBuffer() const;
00085   Ordinal getBytes() const;
00087   const ArrayView<const char> getCharBufferView() const;
00088 private:
00089   Ordinal    count_;
00090   const T    *buffer_;
00091   Ordinal    bytes_;
00092   const char *charBuffer_;
00093   // Not defined and not to be called
00094   ConstValueTypeSerializationBuffer();
00095   ConstValueTypeSerializationBuffer(const ConstValueTypeSerializationBuffer&);
00096   ConstValueTypeSerializationBuffer& operator=(const ConstValueTypeSerializationBuffer&);
00097 };
00098 
00103 template <typename Ordinal, typename T>
00104 class ValueTypeDeserializationBuffer {
00105 public:
00107   ValueTypeDeserializationBuffer(
00108     const Ordinal bytes, char charBuffer[] 
00109     );
00113   ~ValueTypeDeserializationBuffer();
00115   T* getBuffer() const;
00117   Ordinal getCount() const;
00118 private:
00119   Ordinal    bytes_;
00120   char       *charBuffer_;
00121   Ordinal    count_;
00122   T          *buffer_;
00123   // Not defined and not to be called
00124   ValueTypeDeserializationBuffer();
00125   ValueTypeDeserializationBuffer(const ValueTypeDeserializationBuffer&);
00126   ValueTypeDeserializationBuffer& operator=(const ValueTypeDeserializationBuffer&);
00127 };
00128 
00133 template <typename Ordinal, typename T>
00134 class ConstValueTypeDeserializationBuffer {
00135 public:
00137   ConstValueTypeDeserializationBuffer(
00138     const Ordinal bytes, const char charBuffer[]
00139     );
00143   ~ConstValueTypeDeserializationBuffer();
00145   const T* getBuffer() const;
00147   Ordinal getCount() const;
00148 private:
00149   Ordinal    bytes_;
00150   const char *charBuffer_;
00151   Ordinal    count_;
00152   const T    *buffer_;
00153   // Not defined and not to be called
00154   ConstValueTypeDeserializationBuffer();
00155   ConstValueTypeDeserializationBuffer(const ConstValueTypeDeserializationBuffer&);
00156   ConstValueTypeDeserializationBuffer& operator=(const ConstValueTypeDeserializationBuffer&);
00157 };
00158 
00159 // /////////////////////////////////////
00160 // Template implementations
00161 
00162 //
00163 // ValueTypeSerializationBuffer
00164 //
00165 // ToDo: Update this implementation to handle objects with indirect
00166 // serialization when needed!
00167 //
00168 
00169 template <typename Ordinal, typename T>
00170 ValueTypeSerializationBuffer<Ordinal,T>::ValueTypeSerializationBuffer(
00171   const Ordinal count, T buffer[]
00172   )
00173   :count_(count), buffer_(buffer)
00174 {
00175   typedef SerializationTraits<Ordinal,T> SerT;
00176   bytes_ = SerT::fromCountToDirectBytes(count_);
00177   charBuffer_ = SerT::convertToCharPtr(buffer_);
00178   // ToDo: Handle indirect serailization!
00179 }
00180 
00181 template <typename Ordinal, typename T>
00182 ValueTypeSerializationBuffer<Ordinal,T>::~ValueTypeSerializationBuffer()
00183 {
00184   // There is nothing to do since the type uses direct serialization!
00185   // ToDo: Handle indirect serailization!
00186 }
00187 
00188 template <typename Ordinal, typename T>
00189 char* ValueTypeSerializationBuffer<Ordinal,T>::getCharBuffer() const
00190 {
00191   return charBuffer_;
00192 }
00193 
00194 template <typename Ordinal, typename T>
00195 Ordinal ValueTypeSerializationBuffer<Ordinal,T>::getBytes() const
00196 {
00197   return bytes_;
00198 }
00199 
00200 
00201 template <typename Ordinal, typename T>
00202 const ArrayView<char>
00203 ValueTypeSerializationBuffer<Ordinal,T>::getCharBufferView() const
00204 {
00205   return arrayView(charBuffer_, bytes_);
00206 }
00207 
00208 
00209 //
00210 // ConstValueTypeSerializationBuffer
00211 //
00212 // ToDo: Update this implementation to handle objects with indirect
00213 // serialization when needed!
00214 //
00215 
00216 template <typename Ordinal, typename T>
00217 ConstValueTypeSerializationBuffer<Ordinal,T>::ConstValueTypeSerializationBuffer(
00218   const Ordinal count, const T buffer[]
00219   )
00220   :count_(count), buffer_(buffer)
00221 {
00222   typedef SerializationTraits<Ordinal,T> SerT;
00223   bytes_ = SerT::fromCountToDirectBytes(count_);
00224   charBuffer_ = SerT::convertToCharPtr(buffer_);
00225   // ToDo: Handle indirect serailization!
00226 }
00227 
00228 template <typename Ordinal, typename T>
00229 ConstValueTypeSerializationBuffer<Ordinal,T>::~ConstValueTypeSerializationBuffer()
00230 {
00231   // There is nothing to do since the type uses direct serialization!
00232   // ToDo: Handle indirect serailization!
00233 }
00234 
00235 template <typename Ordinal, typename T>
00236 const char* ConstValueTypeSerializationBuffer<Ordinal,T>::getCharBuffer() const
00237 {
00238   return charBuffer_;
00239 }
00240 
00241 template <typename Ordinal, typename T>
00242 Ordinal ConstValueTypeSerializationBuffer<Ordinal,T>::getBytes() const
00243 {
00244   return bytes_;
00245 }
00246 
00247 template <typename Ordinal, typename T>
00248 const ArrayView<const char>
00249 ConstValueTypeSerializationBuffer<Ordinal,T>::getCharBufferView() const
00250 {
00251   return arrayView(charBuffer_, bytes_);
00252 }
00253 
00254 //
00255 // ValueTypeDeserializationBuffer
00256 //
00257 // ToDo: Update this implementation to handle objects with indirect
00258 // serialization when needed!
00259 //
00260 
00261 template <typename Ordinal, typename T>
00262 ValueTypeDeserializationBuffer<Ordinal,T>::ValueTypeDeserializationBuffer(
00263   const Ordinal bytes, char charBuffer[]
00264   )
00265   :bytes_(bytes), charBuffer_(charBuffer)
00266 {
00267   typedef SerializationTraits<Ordinal,T> SerT;
00268   count_ = SerT::fromDirectBytesToCount(bytes_);
00269   buffer_ = SerT::convertFromCharPtr(charBuffer_);
00270   // ToDo: Handle indirect serailization!
00271 }
00272 
00273 template <typename Ordinal, typename T>
00274 ValueTypeDeserializationBuffer<Ordinal,T>::~ValueTypeDeserializationBuffer()
00275 {
00276   // There is nothing to do since the type uses direct serialization!
00277   // ToDo: Handle indirect serailization!
00278 }
00279 
00280 template <typename Ordinal, typename T>
00281 T* ValueTypeDeserializationBuffer<Ordinal,T>::getBuffer() const
00282 {
00283   return buffer_;
00284 }
00285 
00286 template <typename Ordinal, typename T>
00287 Ordinal ValueTypeDeserializationBuffer<Ordinal,T>::getCount() const
00288 {
00289   return count_;
00290 }
00291 
00292 //
00293 // ConstValueTypeDeserializationBuffer
00294 //
00295 // ToDo: Update this implementation to handle objects with indirect
00296 // serialization when needed!
00297 //
00298 
00299 template <typename Ordinal, typename T>
00300 ConstValueTypeDeserializationBuffer<Ordinal,T>::ConstValueTypeDeserializationBuffer(
00301   const Ordinal bytes, const char charBuffer[]
00302   )
00303   :bytes_(bytes), charBuffer_(charBuffer)
00304 {
00305   typedef SerializationTraits<Ordinal,T> SerT;
00306   count_ = SerT::fromDirectBytesToCount(bytes_);
00307   buffer_ = SerT::convertFromCharPtr(charBuffer_);
00308   // ToDo: Handle indirect serailization!
00309 }
00310 
00311 template <typename Ordinal, typename T>
00312 ConstValueTypeDeserializationBuffer<Ordinal,T>::~ConstValueTypeDeserializationBuffer()
00313 {
00314   // There is nothing to do since the type uses direct serialization!
00315   // ToDo: Handle indirect serailization!
00316 }
00317 
00318 template <typename Ordinal, typename T>
00319 const T* ConstValueTypeDeserializationBuffer<Ordinal,T>::getBuffer() const
00320 {
00321   return buffer_;
00322 }
00323 
00324 template <typename Ordinal, typename T>
00325 Ordinal ConstValueTypeDeserializationBuffer<Ordinal,T>::getCount() const
00326 {
00327   return count_;
00328 }
00329 
00330 } // namespace Teuchos
00331 
00332 #endif // TEUCHOS_SERIALIZATION_TRAITS_HELPERS_HPP

Generated on Tue Jul 13 09:23:00 2010 for Teuchos - Trilinos Tools Package by  doxygen 1.4.7