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 
00034 namespace Teuchos {
00035 
00039 template <typename Ordinal, typename T>
00040 class ValueTypeSerializationBuffer {
00041 public:
00043   ValueTypeSerializationBuffer(
00044     const Ordinal count, T buffer[] 
00045     );
00049   ~ValueTypeSerializationBuffer();
00051   char* getCharBuffer() const;
00053   Ordinal getBytes() const;
00054 private:
00055   Ordinal    count_;
00056   T          *buffer_;
00057   Ordinal    bytes_;
00058   char       *charBuffer_;
00059   // Not defined and not to be called
00060   ValueTypeSerializationBuffer();
00061   ValueTypeSerializationBuffer(const ValueTypeSerializationBuffer&);
00062   ValueTypeSerializationBuffer& operator=(const ValueTypeSerializationBuffer&);
00063 };
00064 
00068 template <typename Ordinal, typename T>
00069 class ConstValueTypeSerializationBuffer {
00070 public:
00072   ConstValueTypeSerializationBuffer(
00073     const Ordinal count, const T buffer[]
00074     );
00078   ~ConstValueTypeSerializationBuffer();
00080   const char* getCharBuffer() const;
00082   Ordinal getBytes() const;
00083 private:
00084   Ordinal    count_;
00085   const T    *buffer_;
00086   Ordinal    bytes_;
00087   const char *charBuffer_;
00088   // Not defined and not to be called
00089   ConstValueTypeSerializationBuffer();
00090   ConstValueTypeSerializationBuffer(const ConstValueTypeSerializationBuffer&);
00091   ConstValueTypeSerializationBuffer& operator=(const ConstValueTypeSerializationBuffer&);
00092 };
00093 
00098 template <typename Ordinal, typename T>
00099 class ValueTypeDeserializationBuffer {
00100 public:
00102   ValueTypeDeserializationBuffer(
00103     const Ordinal bytes, char charBuffer[] 
00104     );
00108   ~ValueTypeDeserializationBuffer();
00110   T* getBuffer() const;
00112   Ordinal getCount() const;
00113 private:
00114   Ordinal    bytes_;
00115   char       *charBuffer_;
00116   Ordinal    count_;
00117   T          *buffer_;
00118   // Not defined and not to be called
00119   ValueTypeDeserializationBuffer();
00120   ValueTypeDeserializationBuffer(const ValueTypeDeserializationBuffer&);
00121   ValueTypeDeserializationBuffer& operator=(const ValueTypeDeserializationBuffer&);
00122 };
00123 
00128 template <typename Ordinal, typename T>
00129 class ConstValueTypeDeserializationBuffer {
00130 public:
00132   ConstValueTypeDeserializationBuffer(
00133     const Ordinal bytes, const char charBuffer[]
00134     );
00138   ~ConstValueTypeDeserializationBuffer();
00140   const T* getBuffer() const;
00142   Ordinal getCount() const;
00143 private:
00144   Ordinal    bytes_;
00145   const char *charBuffer_;
00146   Ordinal    count_;
00147   const T    *buffer_;
00148   // Not defined and not to be called
00149   ConstValueTypeDeserializationBuffer();
00150   ConstValueTypeDeserializationBuffer(const ConstValueTypeDeserializationBuffer&);
00151   ConstValueTypeDeserializationBuffer& operator=(const ConstValueTypeDeserializationBuffer&);
00152 };
00153 
00154 // /////////////////////////////////////
00155 // Template implementations
00156 
00157 //
00158 // ValueTypeSerializationBuffer
00159 //
00160 // ToDo: Update this implementation to handle objects with indirect
00161 // serialization when needed!
00162 //
00163 
00164 template <typename Ordinal, typename T>
00165 ValueTypeSerializationBuffer<Ordinal,T>::ValueTypeSerializationBuffer(
00166   const Ordinal count, T buffer[]
00167   )
00168   :count_(count), buffer_(buffer)
00169 {
00170   typedef SerializationTraits<Ordinal,T> SerT;
00171   bytes_ = SerT::fromCountToDirectBytes(count_);
00172   charBuffer_ = SerT::convertToCharPtr(buffer_);
00173   // ToDo: Handle indirect serailization!
00174 }
00175 
00176 template <typename Ordinal, typename T>
00177 ValueTypeSerializationBuffer<Ordinal,T>::~ValueTypeSerializationBuffer()
00178 {
00179   // There is nothing to do since the type uses direct serialization!
00180   // ToDo: Handle indirect serailization!
00181 }
00182 
00183 template <typename Ordinal, typename T>
00184 char* ValueTypeSerializationBuffer<Ordinal,T>::getCharBuffer() const
00185 {
00186   return charBuffer_;
00187 }
00188 
00189 template <typename Ordinal, typename T>
00190 Ordinal ValueTypeSerializationBuffer<Ordinal,T>::getBytes() const
00191 {
00192   return bytes_;
00193 }
00194 
00195 //
00196 // ConstValueTypeSerializationBuffer
00197 //
00198 // ToDo: Update this implementation to handle objects with indirect
00199 // serialization when needed!
00200 //
00201 
00202 template <typename Ordinal, typename T>
00203 ConstValueTypeSerializationBuffer<Ordinal,T>::ConstValueTypeSerializationBuffer(
00204   const Ordinal count, const T buffer[]
00205   )
00206   :count_(count), buffer_(buffer)
00207 {
00208   typedef SerializationTraits<Ordinal,T> SerT;
00209   bytes_ = SerT::fromCountToDirectBytes(count_);
00210   charBuffer_ = SerT::convertToCharPtr(buffer_);
00211   // ToDo: Handle indirect serailization!
00212 }
00213 
00214 template <typename Ordinal, typename T>
00215 ConstValueTypeSerializationBuffer<Ordinal,T>::~ConstValueTypeSerializationBuffer()
00216 {
00217   // There is nothing to do since the type uses direct serialization!
00218   // ToDo: Handle indirect serailization!
00219 }
00220 
00221 template <typename Ordinal, typename T>
00222 const char* ConstValueTypeSerializationBuffer<Ordinal,T>::getCharBuffer() const
00223 {
00224   return charBuffer_;
00225 }
00226 
00227 template <typename Ordinal, typename T>
00228 Ordinal ConstValueTypeSerializationBuffer<Ordinal,T>::getBytes() const
00229 {
00230   return bytes_;
00231 }
00232 
00233 //
00234 // ValueTypeDeserializationBuffer
00235 //
00236 // ToDo: Update this implementation to handle objects with indirect
00237 // serialization when needed!
00238 //
00239 
00240 template <typename Ordinal, typename T>
00241 ValueTypeDeserializationBuffer<Ordinal,T>::ValueTypeDeserializationBuffer(
00242   const Ordinal bytes, char charBuffer[]
00243   )
00244   :bytes_(bytes), charBuffer_(charBuffer)
00245 {
00246   typedef SerializationTraits<Ordinal,T> SerT;
00247   count_ = SerT::fromDirectBytesToCount(bytes_);
00248   buffer_ = SerT::convertFromCharPtr(charBuffer_);
00249   // ToDo: Handle indirect serailization!
00250 }
00251 
00252 template <typename Ordinal, typename T>
00253 ValueTypeDeserializationBuffer<Ordinal,T>::~ValueTypeDeserializationBuffer()
00254 {
00255   // There is nothing to do since the type uses direct serialization!
00256   // ToDo: Handle indirect serailization!
00257 }
00258 
00259 template <typename Ordinal, typename T>
00260 T* ValueTypeDeserializationBuffer<Ordinal,T>::getBuffer() const
00261 {
00262   return buffer_;
00263 }
00264 
00265 template <typename Ordinal, typename T>
00266 Ordinal ValueTypeDeserializationBuffer<Ordinal,T>::getCount() const
00267 {
00268   return count_;
00269 }
00270 
00271 //
00272 // ConstValueTypeDeserializationBuffer
00273 //
00274 // ToDo: Update this implementation to handle objects with indirect
00275 // serialization when needed!
00276 //
00277 
00278 template <typename Ordinal, typename T>
00279 ConstValueTypeDeserializationBuffer<Ordinal,T>::ConstValueTypeDeserializationBuffer(
00280   const Ordinal bytes, const char charBuffer[]
00281   )
00282   :bytes_(bytes), charBuffer_(charBuffer)
00283 {
00284   typedef SerializationTraits<Ordinal,T> SerT;
00285   count_ = SerT::fromDirectBytesToCount(bytes_);
00286   buffer_ = SerT::convertFromCharPtr(charBuffer_);
00287   // ToDo: Handle indirect serailization!
00288 }
00289 
00290 template <typename Ordinal, typename T>
00291 ConstValueTypeDeserializationBuffer<Ordinal,T>::~ConstValueTypeDeserializationBuffer()
00292 {
00293   // There is nothing to do since the type uses direct serialization!
00294   // ToDo: Handle indirect serailization!
00295 }
00296 
00297 template <typename Ordinal, typename T>
00298 const T* ConstValueTypeDeserializationBuffer<Ordinal,T>::getBuffer() const
00299 {
00300   return buffer_;
00301 }
00302 
00303 template <typename Ordinal, typename T>
00304 Ordinal ConstValueTypeDeserializationBuffer<Ordinal,T>::getCount() const
00305 {
00306   return count_;
00307 }
00308 
00309 } // namespace Teuchos
00310 
00311 #endif // TEUCHOS_SERIALIZATION_TRAITS_HELPERS_HPP

Generated on Thu Sep 18 12:30:30 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1