|
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_SERIALIZATION_TRAITS_HELPERS_HPP 00043 #define TEUCHOS_SERIALIZATION_TRAITS_HELPERS_HPP 00044 00045 #include "Teuchos_SerializationTraits.hpp" 00046 #include "Teuchos_ArrayView.hpp" 00047 #include "Teuchos_Array.hpp" 00048 00049 namespace Teuchos { 00050 00058 template <typename Ordinal, typename T> 00059 class DefaultSerializer { 00060 public: 00061 00063 typedef SerializationTraits<Ordinal,T> DefaultSerializerType; 00064 00066 static DefaultSerializerType& getDefaultSerializer() { 00067 if (defaultSerializer_ == Teuchos::null) 00068 defaultSerializer_ = Teuchos::rcp(new DefaultSerializerType); 00069 return *defaultSerializer_; 00070 } 00071 00073 static Teuchos::RCP<DefaultSerializerType> getDefaultSerializerRCP() { 00074 if (defaultSerializer_ == Teuchos::null) 00075 defaultSerializer_ = Teuchos::rcp(new DefaultSerializerType); 00076 return defaultSerializer_; 00077 } 00078 00079 private: 00080 00082 static Teuchos::RCP<DefaultSerializerType> defaultSerializer_; 00083 }; 00084 00085 template <typename Ordinal, typename T> 00086 Teuchos::RCP<typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00087 DefaultSerializer<Ordinal,T>::defaultSerializer_ = Teuchos::null; 00088 00096 template <typename Ordinal, typename T, typename Serializer, 00097 bool direct = Serializer::supportsDirectSerialization> 00098 class ValueTypeSerializationBufferImp {}; 00099 00107 template <typename Ordinal, typename T, typename Serializer, 00108 bool direct = Serializer::supportsDirectSerialization> 00109 class ConstValueTypeSerializationBufferImp {}; 00110 00119 template <typename Ordinal, typename T, typename Serializer, 00120 bool direct = Serializer::supportsDirectSerialization> 00121 class ValueTypeDeserializationBufferImp {}; 00122 00131 template <typename Ordinal, typename T, typename Serializer, 00132 bool direct = Serializer::supportsDirectSerialization> 00133 class ConstValueTypeDeserializationBufferImp {}; 00134 00140 template <typename Ordinal, typename T, typename Serializer> 00141 class ValueTypeSerializationBufferImp<Ordinal,T,Serializer,true> { 00142 public: 00144 ValueTypeSerializationBufferImp( 00145 const Ordinal count, T buffer[], 00146 const RCP<const Serializer>& serializer 00147 ); 00151 ~ValueTypeSerializationBufferImp(); 00153 char* getCharBuffer() const; 00155 Ordinal getBytes() const; 00157 const ArrayView<char> getCharBufferView() const; 00158 private: 00159 Ordinal count_; 00160 T *buffer_; 00161 Ordinal bytes_; 00162 char *charBuffer_; 00163 RCP<const Serializer> serializer_; 00164 // Not defined and not to be called 00165 ValueTypeSerializationBufferImp(); 00166 ValueTypeSerializationBufferImp(const ValueTypeSerializationBufferImp&); 00167 ValueTypeSerializationBufferImp& operator=(const ValueTypeSerializationBufferImp&); 00168 }; 00169 00175 template <typename Ordinal, typename T, typename Serializer> 00176 class ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,true> { 00177 public: 00179 ConstValueTypeSerializationBufferImp( 00180 const Ordinal count, const T buffer[], 00181 const RCP<const Serializer>& serializer 00182 ); 00186 ~ConstValueTypeSerializationBufferImp(); 00188 const char* getCharBuffer() const; 00190 Ordinal getBytes() const; 00192 const ArrayView<const char> getCharBufferView() const; 00193 private: 00194 Ordinal count_; 00195 const T *buffer_; 00196 Ordinal bytes_; 00197 const char *charBuffer_; 00198 RCP<const Serializer> serializer_; 00199 // Not defined and not to be called 00200 ConstValueTypeSerializationBufferImp(); 00201 ConstValueTypeSerializationBufferImp(const ConstValueTypeSerializationBufferImp&); 00202 ConstValueTypeSerializationBufferImp& operator=(const ConstValueTypeSerializationBufferImp&); 00203 }; 00204 00211 template <typename Ordinal, typename T, typename Serializer> 00212 class ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true> { 00213 public: 00215 ValueTypeDeserializationBufferImp( 00216 const Ordinal bytes, char charBuffer[], 00217 const RCP<const Serializer>& serializer 00218 ); 00222 ~ValueTypeDeserializationBufferImp(); 00224 T* getBuffer() const; 00226 Ordinal getCount() const; 00227 private: 00228 Ordinal bytes_; 00229 char *charBuffer_; 00230 Ordinal count_; 00231 T *buffer_; 00232 RCP<const Serializer> serializer_; 00233 // Not defined and not to be called 00234 ValueTypeDeserializationBufferImp(); 00235 ValueTypeDeserializationBufferImp(const ValueTypeDeserializationBufferImp&); 00236 ValueTypeDeserializationBufferImp& operator=(const ValueTypeDeserializationBufferImp&); 00237 }; 00238 00245 template <typename Ordinal, typename T, typename Serializer> 00246 class ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true> { 00247 public: 00249 ConstValueTypeDeserializationBufferImp( 00250 const Ordinal bytes, const char charBuffer[], 00251 const RCP<const Serializer>& serializer 00252 ); 00256 ~ConstValueTypeDeserializationBufferImp(); 00258 const T* getBuffer() const; 00260 Ordinal getCount() const; 00261 private: 00262 Ordinal bytes_; 00263 const char *charBuffer_; 00264 Ordinal count_; 00265 const T *buffer_; 00266 RCP<const Serializer> serializer_; 00267 // Not defined and not to be called 00268 ConstValueTypeDeserializationBufferImp(); 00269 ConstValueTypeDeserializationBufferImp(const ConstValueTypeDeserializationBufferImp&); 00270 ConstValueTypeDeserializationBufferImp& operator=(const ConstValueTypeDeserializationBufferImp&); 00271 }; 00272 00278 template <typename Ordinal, typename T, typename Serializer> 00279 class ValueTypeSerializationBufferImp<Ordinal,T,Serializer,false> { 00280 public: 00282 ValueTypeSerializationBufferImp( 00283 const Ordinal count, T buffer[], 00284 const RCP<const Serializer>& serializer 00285 ); 00289 ~ValueTypeSerializationBufferImp(); 00291 char* getCharBuffer() const; 00293 Ordinal getBytes() const; 00295 const ArrayView<char> getCharBufferView() const; 00296 private: 00297 Ordinal count_; 00298 T *buffer_; 00299 Ordinal bytes_; 00300 mutable Array<char> charBuffer_; 00301 RCP<const Serializer> serializer_; 00302 // Not defined and not to be called 00303 ValueTypeSerializationBufferImp(); 00304 ValueTypeSerializationBufferImp(const ValueTypeSerializationBufferImp&); 00305 ValueTypeSerializationBufferImp& operator=(const ValueTypeSerializationBufferImp&); 00306 }; 00307 00313 template <typename Ordinal, typename T, typename Serializer> 00314 class ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,false> { 00315 public: 00317 ConstValueTypeSerializationBufferImp( 00318 const Ordinal count, const T buffer[], 00319 const RCP<const Serializer>& serializer 00320 ); 00324 ~ConstValueTypeSerializationBufferImp(); 00326 const char* getCharBuffer() const; 00328 Ordinal getBytes() const; 00330 const ArrayView<const char> getCharBufferView() const; 00331 private: 00332 Ordinal count_; 00333 const T *buffer_; 00334 Ordinal bytes_; 00335 Array<char> charBuffer_; 00336 RCP<const Serializer> serializer_; 00337 // Not defined and not to be called 00338 ConstValueTypeSerializationBufferImp(); 00339 ConstValueTypeSerializationBufferImp(const ConstValueTypeSerializationBufferImp&); 00340 ConstValueTypeSerializationBufferImp& operator=(const ConstValueTypeSerializationBufferImp&); 00341 }; 00342 00349 template <typename Ordinal, typename T, typename Serializer> 00350 class ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false> { 00351 public: 00353 ValueTypeDeserializationBufferImp( 00354 const Ordinal bytes, char charBuffer[], 00355 const RCP<const Serializer>& serializer 00356 ); 00360 ~ValueTypeDeserializationBufferImp(); 00362 T* getBuffer() const; 00364 Ordinal getCount() const; 00365 private: 00366 Ordinal bytes_; 00367 char *charBuffer_; 00368 Ordinal count_; 00369 mutable Array<T> buffer_; 00370 RCP<const Serializer> serializer_; 00371 // Not defined and not to be called 00372 ValueTypeDeserializationBufferImp(); 00373 ValueTypeDeserializationBufferImp(const ValueTypeDeserializationBufferImp&); 00374 ValueTypeDeserializationBufferImp& operator=(const ValueTypeDeserializationBufferImp&); 00375 }; 00376 00383 template <typename Ordinal, typename T, typename Serializer> 00384 class ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false> { 00385 public: 00387 ConstValueTypeDeserializationBufferImp( 00388 const Ordinal bytes, const char charBuffer[], 00389 const RCP<const Serializer>& serializer 00390 ); 00394 ~ConstValueTypeDeserializationBufferImp(); 00396 const T* getBuffer() const; 00398 Ordinal getCount() const; 00399 private: 00400 Ordinal bytes_; 00401 const char *charBuffer_; 00402 Ordinal count_; 00403 Array<T> buffer_; 00404 RCP<const Serializer> serializer_; 00405 // Not defined and not to be called 00406 ConstValueTypeDeserializationBufferImp(); 00407 ConstValueTypeDeserializationBufferImp(const ConstValueTypeDeserializationBufferImp&); 00408 ConstValueTypeDeserializationBufferImp& operator=(const ConstValueTypeDeserializationBufferImp&); 00409 }; 00410 00411 00415 template <typename Ordinal, typename T, 00416 typename Serializer = typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00417 class ValueTypeSerializationBuffer : 00418 public ValueTypeSerializationBufferImp<Ordinal,T,Serializer> { 00419 public: 00420 typedef ValueTypeSerializationBufferImp<Ordinal,T,Serializer> Base; 00422 ValueTypeSerializationBuffer( 00423 const Ordinal count, T buffer[], 00424 const RCP<const Serializer>& serializer 00425 ) : Base(count,buffer,serializer) {} 00426 }; 00427 00431 template <typename Ordinal, typename T, 00432 typename Serializer = typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00433 class ConstValueTypeSerializationBuffer : 00434 public ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer> { 00435 public: 00436 typedef ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer> Base; 00438 ConstValueTypeSerializationBuffer( 00439 const Ordinal count, const T buffer[], 00440 const RCP<const Serializer>& serializer 00441 ) : Base(count,buffer,serializer) {} 00442 }; 00443 00448 template <typename Ordinal, typename T, 00449 typename Serializer = typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00450 class ValueTypeDeserializationBuffer : 00451 public ValueTypeDeserializationBufferImp<Ordinal,T,Serializer> { 00452 public: 00453 typedef ValueTypeDeserializationBufferImp<Ordinal,T,Serializer> Base; 00455 ValueTypeDeserializationBuffer( 00456 const Ordinal bytes, char charBuffer[], 00457 const RCP<const Serializer>& serializer 00458 ) : Base(bytes,charBuffer,serializer) {} 00459 }; 00460 00465 template <typename Ordinal, typename T, 00466 typename Serializer = typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> 00467 class ConstValueTypeDeserializationBuffer : 00468 public ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer> { 00469 public: 00470 typedef ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer> Base; 00472 ConstValueTypeDeserializationBuffer( 00473 const Ordinal bytes, const char charBuffer[], 00474 const RCP<const Serializer>& serializer 00475 ) : Base(bytes,charBuffer,serializer) {} 00476 }; 00477 00484 template <typename Ordinal, typename T> 00485 class ValueTypeSerializationBuffer<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> : 00486 public ValueTypeSerializationBufferImp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> { 00487 public: 00488 typedef DefaultSerializer<Ordinal,T> DS; // work around for parsing bug in gcc 4.1-4.2 00489 typedef typename DS::DefaultSerializerType Serializer; 00490 typedef ValueTypeSerializationBufferImp<Ordinal,T,Serializer> Base; 00492 ValueTypeSerializationBuffer( 00493 const Ordinal count, T buffer[], 00494 const RCP<const Serializer>& serializer = DS::getDefaultSerializerRCP() 00495 ) : Base(count,buffer,serializer) {} 00496 }; 00497 00504 template <typename Ordinal, typename T> 00505 class ConstValueTypeSerializationBuffer<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> : 00506 public ConstValueTypeSerializationBufferImp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> { 00507 public: 00508 typedef DefaultSerializer<Ordinal,T> DS; // work around for parsing bug in gcc 4.1-4.2 00509 typedef typename DS::DefaultSerializerType Serializer; 00510 typedef ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer> Base; 00512 ConstValueTypeSerializationBuffer( 00513 const Ordinal count, const T buffer[], 00514 const RCP<const Serializer>& serializer = DS::getDefaultSerializerRCP() 00515 ) : Base(count,buffer,serializer) {} 00516 }; 00517 00525 template <typename Ordinal, typename T> 00526 class ValueTypeDeserializationBuffer<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> : 00527 public ValueTypeDeserializationBufferImp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> { 00528 public: 00529 typedef DefaultSerializer<Ordinal,T> DS; // work around for parsing bug in gcc 4.1-4.2 00530 typedef typename DS::DefaultSerializerType Serializer; 00531 typedef ValueTypeDeserializationBufferImp<Ordinal,T,Serializer> Base; 00533 ValueTypeDeserializationBuffer( 00534 const Ordinal bytes, char charBuffer[], 00535 const RCP<const Serializer>& serializer = DS::getDefaultSerializerRCP() 00536 ) : Base(bytes,charBuffer,serializer) {} 00537 }; 00538 00546 template <typename Ordinal, typename T> 00547 class ConstValueTypeDeserializationBuffer<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> : 00548 public ConstValueTypeDeserializationBufferImp<Ordinal,T,typename DefaultSerializer<Ordinal,T>::DefaultSerializerType> { 00549 public: 00550 typedef DefaultSerializer<Ordinal,T> DS; // work around for parsing bug in gcc 4.1-4.2 00551 typedef typename DS::DefaultSerializerType Serializer; 00552 typedef ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer> Base; 00554 ConstValueTypeDeserializationBuffer( 00555 const Ordinal bytes, const char charBuffer[], 00556 const RCP<const Serializer>& serializer = DS::getDefaultSerializerRCP() 00557 ) : Base(bytes,charBuffer,serializer) {} 00558 }; 00559 00560 // ///////////////////////////////////// 00561 // Template implementations for direct serialization 00562 00563 // 00564 // ValueTypeSerializationBufferImp 00565 // 00566 00567 template <typename Ordinal, typename T, typename Serializer> 00568 ValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00569 ValueTypeSerializationBufferImp( 00570 const Ordinal count, T buffer[], const RCP<const Serializer>& serializer 00571 ) 00572 :count_(count), buffer_(buffer), serializer_(serializer) 00573 { 00574 bytes_ = serializer_->fromCountToDirectBytes(count_); 00575 charBuffer_ = serializer_->convertToCharPtr(buffer_); 00576 } 00577 00578 template <typename Ordinal, typename T, typename Serializer> 00579 ValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00580 ~ValueTypeSerializationBufferImp() 00581 { 00582 // There is nothing to do since the type uses direct serialization! 00583 } 00584 00585 template <typename Ordinal, typename T, typename Serializer> 00586 char* ValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00587 getCharBuffer() const 00588 { 00589 return charBuffer_; 00590 } 00591 00592 template <typename Ordinal, typename T, typename Serializer> 00593 Ordinal ValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00594 getBytes() const 00595 { 00596 return bytes_; 00597 } 00598 00599 00600 template <typename Ordinal, typename T, typename Serializer> 00601 const ArrayView<char> 00602 ValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00603 getCharBufferView() const 00604 { 00605 return arrayView(charBuffer_, bytes_); 00606 } 00607 00608 00609 // 00610 // ConstValueTypeSerializationBufferImp 00611 // 00612 00613 template <typename Ordinal, typename T, typename Serializer> 00614 ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00615 ConstValueTypeSerializationBufferImp( 00616 const Ordinal count, const T buffer[], const RCP<const Serializer>& serializer 00617 ) 00618 :count_(count), buffer_(buffer), serializer_(serializer) 00619 { 00620 bytes_ = serializer_->fromCountToDirectBytes(count_); 00621 charBuffer_ = serializer_->convertToCharPtr(buffer_); 00622 } 00623 00624 template <typename Ordinal, typename T, typename Serializer> 00625 ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00626 ~ConstValueTypeSerializationBufferImp() 00627 { 00628 // There is nothing to do since the type uses direct serialization! 00629 } 00630 00631 template <typename Ordinal, typename T, typename Serializer> 00632 const char* ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00633 getCharBuffer() const 00634 { 00635 return charBuffer_; 00636 } 00637 00638 template <typename Ordinal, typename T, typename Serializer> 00639 Ordinal ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00640 getBytes() const 00641 { 00642 return bytes_; 00643 } 00644 00645 template <typename Ordinal, typename T, typename Serializer> 00646 const ArrayView<const char> 00647 ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,true>:: 00648 getCharBufferView() const 00649 { 00650 return arrayView(charBuffer_, bytes_); 00651 } 00652 00653 // 00654 // ValueTypeDeserializationBufferImp 00655 // 00656 00657 template <typename Ordinal, typename T, typename Serializer> 00658 ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00659 ValueTypeDeserializationBufferImp( 00660 const Ordinal bytes, char charBuffer[], const RCP<const Serializer>& serializer 00661 ) 00662 :bytes_(bytes), charBuffer_(charBuffer), serializer_(serializer) 00663 { 00664 count_ = serializer_->fromDirectBytesToCount(bytes_); 00665 buffer_ = serializer_->convertFromCharPtr(charBuffer_); 00666 } 00667 00668 template <typename Ordinal, typename T, typename Serializer> 00669 ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00670 ~ValueTypeDeserializationBufferImp() 00671 { 00672 // There is nothing to do since the type uses direct serialization! 00673 } 00674 00675 template <typename Ordinal, typename T, typename Serializer> 00676 T* ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00677 getBuffer() const 00678 { 00679 return buffer_; 00680 } 00681 00682 template <typename Ordinal, typename T, typename Serializer> 00683 Ordinal ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00684 getCount() const 00685 { 00686 return count_; 00687 } 00688 00689 // 00690 // ConstValueTypeDeserializationBufferImp 00691 // 00692 00693 template <typename Ordinal, typename T, typename Serializer> 00694 ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00695 ConstValueTypeDeserializationBufferImp( 00696 const Ordinal bytes, const char charBuffer[], const RCP<const Serializer>& serializer 00697 ) 00698 :bytes_(bytes), charBuffer_(charBuffer), serializer_(serializer) 00699 { 00700 count_ = serializer_->fromDirectBytesToCount(bytes_); 00701 buffer_ = serializer_->convertFromCharPtr(charBuffer_); 00702 } 00703 00704 template <typename Ordinal, typename T, typename Serializer> 00705 ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00706 ~ConstValueTypeDeserializationBufferImp() 00707 { 00708 // There is nothing to do since the type uses direct serialization! 00709 } 00710 00711 template <typename Ordinal, typename T, typename Serializer> 00712 const T* ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00713 getBuffer() const 00714 { 00715 return buffer_; 00716 } 00717 00718 template <typename Ordinal, typename T, typename Serializer> 00719 Ordinal ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,true>:: 00720 getCount() const 00721 { 00722 return count_; 00723 } 00724 00725 00726 // ///////////////////////////////////// 00727 // Template implementations for indirect specializations 00728 00729 // 00730 // ValueTypeSerializationBufferImp 00731 // 00732 00733 template <typename Ordinal, typename T, typename Serializer> 00734 ValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00735 ValueTypeSerializationBufferImp( 00736 const Ordinal count, T buffer[], const RCP<const Serializer>& serializer 00737 ) 00738 :count_(count), buffer_(buffer), serializer_(serializer) 00739 { 00740 bytes_ = serializer_->fromCountToIndirectBytes(count_, buffer_); 00741 charBuffer_.resize(bytes_); 00742 serializer_->serialize(count_, buffer_, bytes_, &charBuffer_[0]); 00743 } 00744 00745 template <typename Ordinal, typename T, typename Serializer> 00746 ValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00747 ~ValueTypeSerializationBufferImp() 00748 { 00749 serializer_->deserialize(bytes_, &charBuffer_[0], count_, buffer_); 00750 } 00751 00752 template <typename Ordinal, typename T, typename Serializer> 00753 char* ValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00754 getCharBuffer() const 00755 { 00756 return &charBuffer_[0]; 00757 } 00758 00759 template <typename Ordinal, typename T, typename Serializer> 00760 Ordinal ValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00761 getBytes() const 00762 { 00763 return bytes_; 00764 } 00765 00766 template <typename Ordinal, typename T, typename Serializer> 00767 const ArrayView<char> 00768 ValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00769 getCharBufferView() const 00770 { 00771 return charBuffer_.view(0, bytes_); 00772 } 00773 00774 00775 // 00776 // ConstValueTypeSerializationBufferImp 00777 // 00778 00779 template <typename Ordinal, typename T, typename Serializer> 00780 ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00781 ConstValueTypeSerializationBufferImp( 00782 const Ordinal count, const T buffer[], const RCP<const Serializer>& serializer 00783 ) 00784 :count_(count), buffer_(buffer), serializer_(serializer) 00785 { 00786 bytes_ = serializer_->fromCountToIndirectBytes(count_, buffer_); 00787 charBuffer_.resize(bytes_); 00788 serializer_->serialize(count_, buffer_, bytes_, &charBuffer_[0]); 00789 } 00790 00791 template <typename Ordinal, typename T, typename Serializer> 00792 ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00793 ~ConstValueTypeSerializationBufferImp() 00794 { 00795 } 00796 00797 template <typename Ordinal, typename T, typename Serializer> 00798 const char* ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00799 getCharBuffer() const 00800 { 00801 return &charBuffer_[0]; 00802 } 00803 00804 template <typename Ordinal, typename T, typename Serializer> 00805 Ordinal ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00806 getBytes() const 00807 { 00808 return bytes_; 00809 } 00810 00811 template <typename Ordinal, typename T, typename Serializer> 00812 const ArrayView<const char> 00813 ConstValueTypeSerializationBufferImp<Ordinal,T,Serializer,false>:: 00814 getCharBufferView() const 00815 { 00816 return charBuffer_.view(0, bytes_); 00817 } 00818 00819 // 00820 // ValueTypeDeserializationBufferImp 00821 // 00822 00823 template <typename Ordinal, typename T, typename Serializer> 00824 ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00825 ValueTypeDeserializationBufferImp( 00826 const Ordinal bytes, char charBuffer[], const RCP<const Serializer>& serializer 00827 ) 00828 :bytes_(bytes), charBuffer_(charBuffer), serializer_(serializer) 00829 { 00830 count_ = serializer_->fromIndirectBytesToCount(bytes_, charBuffer_); 00831 buffer_.resize(count_); 00832 serializer_->deserialize(bytes_, charBuffer_, count_, &buffer_[0]); 00833 } 00834 00835 template <typename Ordinal, typename T, typename Serializer> 00836 ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00837 ~ValueTypeDeserializationBufferImp() 00838 { 00839 serializer_->serialize(count_, &buffer_[0], bytes_, charBuffer_); 00840 } 00841 00842 template <typename Ordinal, typename T, typename Serializer> 00843 T* ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00844 getBuffer() const 00845 { 00846 return &buffer_[0]; 00847 } 00848 00849 template <typename Ordinal, typename T, typename Serializer> 00850 Ordinal ValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00851 getCount() const 00852 { 00853 return count_; 00854 } 00855 00856 // 00857 // ConstValueTypeDeserializationBufferImp 00858 // 00859 00860 template <typename Ordinal, typename T, typename Serializer> 00861 ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00862 ConstValueTypeDeserializationBufferImp( 00863 const Ordinal bytes, const char charBuffer[], const RCP<const Serializer>& serializer 00864 ) 00865 :bytes_(bytes), charBuffer_(charBuffer), serializer_(serializer) 00866 { 00867 count_ = serializer_->fromIndirectBytesToCount(bytes_, charBuffer_); 00868 buffer_.resize(count_); 00869 serializer_->deserialize(bytes_, charBuffer_, count_, &buffer_[0]); 00870 } 00871 00872 template <typename Ordinal, typename T, typename Serializer> 00873 ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00874 ~ConstValueTypeDeserializationBufferImp() 00875 { 00876 } 00877 00878 template <typename Ordinal, typename T, typename Serializer> 00879 const T* ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00880 getBuffer() const 00881 { 00882 return &buffer_[0]; 00883 } 00884 00885 template <typename Ordinal, typename T, typename Serializer> 00886 Ordinal ConstValueTypeDeserializationBufferImp<Ordinal,T,Serializer,false>:: 00887 getCount() const 00888 { 00889 return count_; 00890 } 00891 00892 } // namespace Teuchos 00893 00894 #endif // TEUCHOS_SERIALIZATION_TRAITS_HELPERS_HPP
1.7.6.1