RTOp Package Browser (Single Doxygen Collection) Version of the Day
RTOpPack_Types.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
00005 //       Operations
00006 //                Copyright (2006) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 
00043 
00044 #ifndef RTOPPACK_TYPES_HPP
00045 #define RTOPPACK_TYPES_HPP
00046 
00047 
00048 #include "RTOp_ConfigDefs.hpp"
00049 #include "Teuchos_Array.hpp"
00050 #include "Teuchos_RCP.hpp"
00051 #include "Teuchos_ArrayRCP.hpp"
00052 #include "Teuchos_Range1D.hpp"
00053 #include "Teuchos_ScalarTraits.hpp"
00054 #include "Teuchos_TypeNameTraits.hpp"
00055 #include "Teuchos_TestForException.hpp"
00056 #include "Teuchos_implicit_cast.hpp"
00057 
00058 
00059 namespace RTOpPack {
00060 
00061 
00062 //
00063 // Basic types
00064 //
00065 
00067 typedef Teuchos_Ordinal Ordinal;
00069 RTOP_DEPRECATED typedef Teuchos_Index Index;
00071 using Teuchos::Ptr;
00073 using Teuchos::RCP;
00075 using Teuchos::ArrayRCP;
00077 using Teuchos::ArrayView;
00079 using Teuchos::Array;
00081 using Teuchos::Range1D;
00083 using Teuchos::ScalarTraits;
00085 using Teuchos::TypeNameTraits;
00086 
00088 typedef Teuchos_Index index_type;
00090 typedef char  char_type;
00091 
00092 
00093 //
00094 // Exceptions
00095 //
00096 
00097 
00099 class UnknownError : public std::logic_error
00100 {public: UnknownError(const std::string& what_arg) : std::logic_error(what_arg) {}};
00102 class InvalidUsage : public std::logic_error
00103 {public: InvalidUsage(const std::string& what_arg) : std::logic_error(what_arg) {}};
00105 class InvalidNumVecs : public std::logic_error
00106 {public: InvalidNumVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00108 class InvalidNumTargVecs : public std::logic_error
00109 {public: InvalidNumTargVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00111 class IncompatibleVecs : public std::logic_error
00112 {public: IncompatibleVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00114 class IncompatibleReductObj : public std::logic_error
00115 {public: IncompatibleReductObj(const std::string& what_arg) : std::logic_error(what_arg) {}};
00116 
00117 
00118 //
00119 // VectorBase subviews
00120 //
00121 
00122 
00142 template<class Scalar>
00143 class ConstSubVectorView {
00144 public:
00146   ConstSubVectorView() : globalOffset_(0), subDim_(0), stride_(0) {}
00148   ConstSubVectorView(const ArrayRCP<const Scalar> &values_in)
00149     :globalOffset_(0), subDim_(0), stride_(0)
00150     { initialize(0, values_in.size(), values_in, 1); }
00152   ConstSubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00153     const ArrayRCP<const Scalar> &values_in, ptrdiff_t stride_in)
00154     :globalOffset_(0), subDim_(0), stride_(0)
00155     { initialize(globalOffset_in, subDim_in, values_in, stride_in); }
00157   ConstSubVectorView( const ConstSubVectorView<Scalar>& sv )
00158     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()),
00159      values_(sv.values()), stride_(sv.stride()) 
00160     {}
00162   void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00163     const ArrayRCP<const Scalar> &values_in, ptrdiff_t stride_in)
00164     {
00165 #ifdef TEUCHOS_DEBUG
00166       TEUCHOS_ASSERT(globalOffset_in >= 0);
00167       if (!is_null(values_in)) {
00168         TEUCHOS_ASSERT(subDim_in >= 0);
00169         TEUCHOS_ASSERT(stride_in != 0);
00170         TEUCHOS_ASSERT(
00171           subDim_in*std::abs(Teuchos::as<int>(stride_in)) - 1 <= values_in.upperOffset());
00172         TEUCHOS_ASSERT(values_in.lowerOffset() <= 0);
00173       }
00174       else {
00175         TEUCHOS_ASSERT(stride_in == 0);
00176         TEUCHOS_ASSERT(subDim_in==0);
00177       }
00178 #endif
00179       globalOffset_=globalOffset_in;
00180       subDim_=subDim_in;
00181       values_=values_in;
00182       stride_=stride_in;
00183     }
00185   void uninitialize()
00186     { globalOffset_ = 0; subDim_=0; values_ = Teuchos::null; stride_ = 0; }
00188   void setGlobalOffset(Ordinal globalOffset_in)
00189     {
00190 #ifdef TEUCHOS_DEBUG
00191       TEUCHOS_ASSERT(globalOffset_in >= 0);
00192 #endif
00193       globalOffset_ = globalOffset_in;
00194     } 
00196   Ordinal globalOffset() const { return globalOffset_; }
00198   Ordinal subDim() const { return subDim_; }
00200   const ArrayRCP<const Scalar>  values() const { return values_; }
00202   ptrdiff_t stride() const { return stride_; }
00205   const Scalar& operator[](Ordinal i) const
00206     {
00207 #ifdef TEUCHOS_DEBUG
00208       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, subDim_);
00209 #endif
00210       return valuesBegin()[stride_*i];
00211     }
00214   const Scalar& operator()(Ordinal i) const { return (*this)[i]; }
00215 private:
00216   Ordinal globalOffset_;
00217   Ordinal subDim_;
00218   ArrayRCP<const Scalar> values_;
00219   ptrdiff_t stride_;
00220   const typename ArrayRCP<const Scalar>::iterator valuesBegin() const
00221     {
00222       if (stride_ > 0)
00223         return values_.begin();
00224       return values_.begin() + (subDim_*std::abs(Teuchos::as<int>(stride_)) - 1);
00225     } 
00226 public:
00228   RTOP_DEPRECATED ConstSubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00229     const Scalar values_in[], ptrdiff_t stride_in)
00230     :globalOffset_(globalOffset_in), subDim_(subDim_in),
00231      values_(values_in,0,subDim_in*stride_in,false), stride_(stride_in) 
00232     {}
00234   RTOP_DEPRECATED void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00235     const Scalar values_in[], ptrdiff_t stride_in)
00236     {
00237       globalOffset_=globalOffset_in; subDim_=subDim_in;
00238       values_=Teuchos::arcp(values_in, 0,
00239         subDim_in*std::abs(Teuchos::as<int>(stride_in)), false);
00240       stride_=stride_in;
00241     }
00243   RTOP_DEPRECATED void set_uninitialized()
00244     { uninitialize(); }
00245 };
00246 
00247 
00264 template<class Scalar>
00265 class SubVectorView : public ConstSubVectorView<Scalar> {
00266 public:
00268   SubVectorView() {}
00270   SubVectorView(const ArrayRCP<Scalar> &values_in)
00271     :ConstSubVectorView<Scalar>(values_in)
00272     {}
00274   SubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00275     const ArrayRCP<Scalar> &values_in, ptrdiff_t stride_in)
00276     :ConstSubVectorView<Scalar>(globalOffset_in, subDim_in, values_in, stride_in)
00277     {}
00279   SubVectorView(Ordinal subDim_in)
00280     :ConstSubVectorView<Scalar>(0, subDim_in, Teuchos::arcp<Scalar>(subDim_in), 1)
00281     {}
00283   SubVectorView(const SubVectorView<Scalar> & sv)
00284     :ConstSubVectorView<Scalar>(sv)
00285     {}
00287   void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00288     const ArrayRCP<Scalar> &values_in, ptrdiff_t stride_in)
00289     { ConstSubVectorView<Scalar>::initialize(globalOffset_in, subDim_in, values_in, stride_in); }
00291   const ArrayRCP<Scalar> values() const
00292     { return Teuchos::arcp_const_cast<Scalar>(ConstSubVectorView<Scalar>::values());  }
00295   Scalar& operator[](Ordinal i) const
00296     { return const_cast<Scalar&>(ConstSubVectorView<Scalar>::operator[](i)); }
00299   Scalar& operator()(Ordinal i) const { return (*this)[i]; }
00300 public:
00302   RTOP_DEPRECATED SubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00303     Scalar values_in[], ptrdiff_t stride_in)
00304     :ConstSubVectorView<Scalar>(globalOffset_in, subDim_in, values_in, stride_in)
00305     {}
00307   RTOP_DEPRECATED void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00308     Scalar values_in[], ptrdiff_t stride_in)
00309     { ConstSubVectorView<Scalar>::initialize(globalOffset_in, subDim_in, values_in, stride_in); }
00310 };
00311 
00312 
00314 template<class Scalar>
00315 void assign_entries( const Ptr<const SubVectorView<Scalar> > &msv,
00316   const ConstSubVectorView<Scalar> &sv )
00317 {
00318 #ifdef TEUCHOS_DEBUG
00319   TEUCHOS_ASSERT_EQUALITY(msv->subDim(), sv.subDim());
00320 #endif
00321   for( int i = 0; i < sv.subDim(); ++i ) {
00322     (*msv)(i) = sv(i);
00323   }
00324 }
00325 
00326 
00331 template<class Scalar>
00332 std::ostream& operator<<(std::ostream &out, const ConstSubVectorView<Scalar> &sv)
00333 {
00334   out
00335     << "{"
00336     << "globalOffset="<<sv.globalOffset()
00337     << ",subDim="<<sv.subDim()
00338     << ",values="<<sv.values()
00339     << ",stride="<<sv.stride()
00340     << "}";
00341   return out;
00342 }
00343 
00344 
00345 //
00346 // MultiVectorBase subviews
00347 //
00348 
00349 
00371 template<class Scalar>
00372 class ConstSubMultiVectorView {
00373 public:
00375   ConstSubMultiVectorView()
00376     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
00377      leadingDim_(0)
00378     {}
00380   ConstSubMultiVectorView(
00381     Ordinal globalOffset_in, Ordinal subDim_in,
00382     Ordinal colOffset_in, Ordinal numSubCols_in,
00383     const ArrayRCP<const Scalar> &values_in, Ordinal leadingDim_in
00384     )
00385     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
00386      leadingDim_(0)
00387     {
00388       initialize(globalOffset_in, subDim_in, colOffset_in, numSubCols_in, values_in,
00389         leadingDim_in);
00390     }
00392   ConstSubMultiVectorView( const ConstSubMultiVectorView<Scalar>& smv )
00393     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim()),
00394      colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols()),
00395      values_(smv.values()), leadingDim_(smv.leadingDim())
00396     {}
00398   void initialize(
00399     Ordinal globalOffset_in, Ordinal subDim_in,
00400     Ordinal colOffset_in, Ordinal numSubCols_in,
00401     const ArrayRCP<const Scalar> &values_in, Ordinal leadingDim_in
00402     )
00403     {
00404 #ifdef TEUCHOS_DEBUG
00405       TEUCHOS_ASSERT(globalOffset_in >= 0);
00406       TEUCHOS_ASSERT(colOffset_in >= 0);
00407       if (!is_null(values_in)) {
00408         TEUCHOS_ASSERT(subDim_in >= 0);
00409         TEUCHOS_ASSERT(leadingDim_in >= subDim_in);
00410         TEUCHOS_ASSERT(numSubCols_in*leadingDim_in - 1 <= values_in.upperOffset());
00411         TEUCHOS_ASSERT(values_in.lowerOffset() <= 0);
00412       }
00413       else {
00414         TEUCHOS_ASSERT(subDim_in == 0);
00415         TEUCHOS_ASSERT(leadingDim_in == 0);
00416         TEUCHOS_ASSERT(numSubCols_in == 0);
00417       }
00418 #endif
00419       globalOffset_=globalOffset_in;
00420       subDim_=subDim_in;
00421       colOffset_=colOffset_in;
00422       numSubCols_=numSubCols_in;
00423       values_=values_in;
00424       leadingDim_=leadingDim_in;
00425     }
00427   void uninitialize()
00428     {
00429       globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0;
00430       values_=Teuchos::null; leadingDim_=0;
00431     }
00433   void setGlobalOffset(Ordinal globalOffset_in)
00434     {
00435 #ifdef TEUCHOS_DEBUG
00436       TEUCHOS_ASSERT(globalOffset_in >= 0);
00437 #endif
00438       globalOffset_ = globalOffset_in;
00439     } 
00441   Ordinal globalOffset() const { return globalOffset_; }
00443   Ordinal subDim() const { return subDim_; }
00445   Ordinal colOffset() const { return colOffset_; }
00447   Ordinal numSubCols() const { return numSubCols_; }
00449   const ArrayRCP<const Scalar> values() const { return values_; }
00451   Ordinal leadingDim() const { return leadingDim_; }
00455   const Scalar& operator()(Ordinal i, Ordinal j) const
00456     {
00457 #ifdef TEUCHOS_DEBUG
00458       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, subDim_);
00459       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, numSubCols_ );
00460 #endif
00461       return values_[ i + leadingDim_*j ];
00462     }
00466   ConstSubVectorView<Scalar> col( const Ordinal j ) const
00467     {
00468 #ifdef TEUCHOS_DEBUG
00469       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, numSubCols_ );
00470 #endif
00471       return ConstSubVectorView<Scalar>(
00472         globalOffset(), subDim(), values().persistingView(j*leadingDim(),subDim()), 1 );
00473     }
00474 private:
00475   Ordinal globalOffset_;
00476   Ordinal subDim_;
00477   Ordinal colOffset_;
00478   Ordinal numSubCols_;
00479   ArrayRCP<const Scalar> values_;
00480   Ordinal leadingDim_;
00481 public:
00483   RTOP_DEPRECATED ConstSubMultiVectorView(
00484     Ordinal globalOffset_in, Ordinal subDim_in,
00485     Ordinal colOffset_in, Ordinal numSubCols_in,
00486     const Scalar values_in[], Ordinal leadingDim_in
00487     )
00488     :globalOffset_(globalOffset_in), subDim_(subDim_in),
00489      colOffset_(colOffset_in), numSubCols_(numSubCols_in),
00490      values_(values_in,0,numSubCols_in*leadingDim_in,false),
00491      leadingDim_(leadingDim_in)
00492     {}
00494   RTOP_DEPRECATED void initialize(
00495     Ordinal globalOffset_in, Ordinal subDim_in,
00496     Ordinal colOffset_in, Ordinal numSubCols_in,
00497     const Scalar values_in[], Ordinal leadingDim_in
00498     )
00499     {
00500       globalOffset_=globalOffset_in; subDim_=subDim_in; colOffset_=colOffset_in;
00501       numSubCols_=numSubCols_in;
00502       values_=Teuchos::arcp(values_in,0,numSubCols_in*leadingDim_in,false);
00503       leadingDim_=leadingDim_in;
00504     }
00506   RTOP_DEPRECATED void set_uninitialized()
00507     { uninitialize(); }
00508 };
00509 
00510 
00527 template<class Scalar>
00528 class SubMultiVectorView : public ConstSubMultiVectorView<Scalar> {
00529 public:
00531   SubMultiVectorView() {}
00533   SubMultiVectorView(
00534     Ordinal numRows_in, Ordinal numCols_in
00535     )
00536     :ConstSubMultiVectorView<Scalar>(0, numRows_in, 0, numCols_in,
00537       Teuchos::arcp<Scalar>(numRows_in*numCols_in), numRows_in)
00538     {}
00540   SubMultiVectorView(
00541     Ordinal globalOffset_in, Ordinal subDim_in,
00542     Ordinal colOffset_in, Ordinal numSubCols_in,
00543     const ArrayRCP<Scalar> &values_in, Ordinal leadingDim_in
00544     )
00545     :ConstSubMultiVectorView<Scalar>(globalOffset_in, subDim_in,
00546       colOffset_in, numSubCols_in, values_in, leadingDim_in)
00547     {}
00549   SubMultiVectorView( const SubMultiVectorView<Scalar> & smv)
00550     :ConstSubMultiVectorView<Scalar>(smv)
00551     {}
00553  void initialize(
00554    Ordinal globalOffset_in, Ordinal subDim_in,
00555    Ordinal colOffset_in, Ordinal numSubCols_in,
00556    const ArrayRCP<Scalar> &values_in, Ordinal leadingDim_in
00557    )
00558    {
00559      ConstSubMultiVectorView<Scalar>::initialize(globalOffset_in,
00560        subDim_in, colOffset_in, numSubCols_in, values_in, leadingDim_in);
00561    }
00563   const ArrayRCP<Scalar> values() const
00564     {
00565       return Teuchos::arcp_const_cast<Scalar>(
00566         ConstSubMultiVectorView<Scalar>::values());
00567     }
00571   Scalar& operator()(Ordinal i, Ordinal j) const
00572     { return const_cast<Scalar&>(ConstSubMultiVectorView<Scalar>::operator()(i,j)); }
00576   SubVectorView<Scalar> col( const Ordinal j ) const
00577     {
00578 #ifdef TEUCHOS_DEBUG
00579       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->numSubCols());
00580 #endif
00581       return SubVectorView<Scalar>(this->globalOffset(), this->subDim(),
00582         values().persistingView(j*this->leadingDim(),this->subDim()), 1);
00583     }
00584 public:
00586   RTOP_DEPRECATED SubMultiVectorView(
00587     Ordinal globalOffset_in, Ordinal subDim_in,
00588     Ordinal colOffset_in, Ordinal numSubCols_in,
00589     Scalar values_in[], Ordinal leadingDim_in
00590     )
00591     :ConstSubMultiVectorView<Scalar>(globalOffset_in, subDim_in,
00592        colOffset_in, numSubCols_in, values_in, leadingDim_in)
00593     {}
00595  RTOP_DEPRECATED void initialize(
00596    Ordinal globalOffset_in, Ordinal subDim_in,
00597    Ordinal colOffset_in, Ordinal numSubCols_in,
00598    Scalar values_in[], Ordinal leadingDim_in
00599    )
00600    {
00601      ConstSubMultiVectorView<Scalar>::initialize(globalOffset_in,
00602        subDim_in, colOffset_in, numSubCols_in, values_in, leadingDim_in);
00603    }
00604 };
00605 
00606 
00608 template<class Scalar>
00609 void assign_entries( const Ptr<const SubMultiVectorView<Scalar> > &msmv,
00610   const ConstSubMultiVectorView<Scalar> &smv )
00611 {
00612 #ifdef TEUCHOS_DEBUG
00613   TEUCHOS_ASSERT_EQUALITY(msmv->subDim(), smv.subDim());
00614   TEUCHOS_ASSERT_EQUALITY(msmv->numSubCols(), smv.numSubCols());
00615 #endif
00616   for( Ordinal j = 0; j < smv.numSubCols(); ++j ) {
00617     for( Ordinal i = 0; i < smv.subDim(); ++i ) {
00618       (*msmv)(i,j) = smv(i,j);
00619     }
00620   }
00621 }
00622 
00623 
00624 //
00625 // Primitive Type Traits
00626 //
00627 
00628 
00639 template <class Scalar, class ConcreteObj>
00640 class PrimitiveTypeTraits {
00641 public:
00643   typedef Scalar primitiveType;
00645   static int numPrimitiveObjs()
00646     { return Scalar::this_type_is_missing_a_specialization(); }
00648   static int numIndexObjs()
00649     { return Scalar::this_type_is_missing_a_specialization(); }
00651   static int numCharObjs()
00652     { return Scalar::this_type_is_missing_a_specialization(); }
00654   static void extractPrimitiveObjs(
00655     const Scalar &obj,
00656     const ArrayView<primitiveType> &primitiveObjs,
00657     const ArrayView<index_type> &indexObjs,
00658     const ArrayView<char> &charObjs
00659     )
00660     {
00661       Scalar::this_type_is_missing_a_specialization(obj);
00662     }
00664   static void loadPrimitiveObjs(
00665     const ArrayView<const primitiveType> &primitiveObjs,
00666     const ArrayView<const index_type> &indexObjs,
00667     const ArrayView<const char> &charObjs,
00668     const Ptr<Scalar> &obj
00669     )
00670     {
00671       *obj = Scalar::this_type_is_missing_a_specialization();
00672     }
00673 };
00674 
00675 
00676 
00680 template <class Scalar>
00681 class PrimitiveTypeTraits<Scalar, Scalar> {
00682 public:
00684   typedef Scalar primitiveType;
00686   static int numPrimitiveObjs() { return 1; }
00688   static int numIndexObjs() { return 0; }
00690   static int numCharObjs() { return 0; }
00692   static void extractPrimitiveObjs(
00693     const Scalar &obj,
00694     const ArrayView<primitiveType> &primitiveObjs,
00695     const ArrayView<index_type> &indexObjs,
00696     const ArrayView<char> &charObjs
00697     )
00698     {
00699       assertInput(primitiveObjs, indexObjs, charObjs);
00700       primitiveObjs[0] = obj;
00701     }
00703   static void loadPrimitiveObjs(
00704     const ArrayView<const primitiveType> &primitiveObjs,
00705     const ArrayView<const index_type> &indexObjs,
00706     const ArrayView<const char> &charObjs,
00707     const Ptr<Scalar> &obj
00708     )
00709     {
00710       assertInput(primitiveObjs, indexObjs, charObjs);
00711       *obj = primitiveObjs[0];
00712     }
00713 private:
00714   static void assertInput(
00715     const ArrayView<const primitiveType> &primitiveObjs,
00716     const ArrayView<const index_type> &indexObjs,
00717     const ArrayView<const char> &charObjs
00718     )
00719     {
00720 #ifdef TEUCHOS_DEBUG
00721       TEST_FOR_EXCEPT( primitiveObjs.size()!=1 || indexObjs.size()!=0
00722         || charObjs.size()!=0 );
00723 #endif
00724     }
00725 };
00726 
00727 
00729 template <class Scalar>
00730 class PrimitiveTypeTraits<Scalar, index_type> {
00731 public:
00733   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00735   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00737   static int numPrimitiveObjs() { return 0; }
00739   static int numIndexObjs() { return 1; }
00741   static int numCharObjs() { return 0; }
00743   static void extractPrimitiveObjs(
00744     const index_type &obj,
00745     const ArrayView<primitiveType> &primitiveObjs,
00746     const ArrayView<index_type> &indexObjs,
00747     const ArrayView<char> &charObjs
00748     )
00749     {
00750       assertInput(primitiveObjs, indexObjs, charObjs);
00751       indexObjs[0] = obj;
00752     }
00754   static void loadPrimitiveObjs(
00755     const ArrayView<const primitiveType> &primitiveObjs,
00756     const ArrayView<const index_type> &indexObjs,
00757     const ArrayView<const char> &charObjs,
00758     const Ptr<index_type> &obj
00759     )
00760     {
00761       assertInput(primitiveObjs, indexObjs, charObjs);
00762       *obj = indexObjs[0];
00763     }
00764 private:
00765   static void assertInput(
00766     const ArrayView<const primitiveType> &primitiveObjs,
00767     const ArrayView<const index_type> &indexObjs,
00768     const ArrayView<const char> &charObjs
00769     )
00770     {
00771 #ifdef TEUCHOS_DEBUG
00772       TEST_FOR_EXCEPT( primitiveObjs.size()!=0 || indexObjs.size()!=1
00773         || charObjs.size()!=0 );
00774 #endif
00775     }
00776 };
00777 
00778 
00779 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00780 
00781 
00785 template <class Scalar>
00786 class PrimitiveTypeTraits<std::complex<Scalar>, std::complex<Scalar> > {
00787 public:
00789   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00791   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00793   static int numPrimitiveObjs()
00794     { return 2*ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
00796   static int numIndexObjs() { return 0; }
00798   static int numCharObjs() { return 0; }
00800   static void extractPrimitiveObjs(
00801     const std::complex<Scalar> &obj,
00802     const ArrayView<primitiveType> &primitiveObjs,
00803     const ArrayView<index_type> &indexObjs,
00804     const ArrayView<char> &charObjs
00805     )
00806     {
00807       using Teuchos::null;
00808       const int numScalarPrimitiveObjs =
00809         ScalarPrimitiveTypeTraits::numPrimitiveObjs();
00810       assertInput(primitiveObjs, indexObjs, charObjs);
00811       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00812         obj.real(), primitiveObjs(0,numScalarPrimitiveObjs), null, null );
00813       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00814         obj.imag(), primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null );
00815     }
00817   static void loadPrimitiveObjs(
00818     const ArrayView<const primitiveType> &primitiveObjs,
00819     const ArrayView<const index_type> &indexObjs,
00820     const ArrayView<const char> &charObjs,
00821     const Ptr<std::complex<Scalar> > &obj
00822     )
00823     {
00824       using Teuchos::null;
00825       using Teuchos::outArg;
00826       assertInput(primitiveObjs, indexObjs, charObjs);
00827       const int numScalarPrimitiveObjs =
00828         ScalarPrimitiveTypeTraits::numPrimitiveObjs();
00829       Scalar real, imag;
00830       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00831         primitiveObjs(0,numScalarPrimitiveObjs), null, null,
00832         outArg(real) );
00833       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00834         primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null,
00835         outArg(imag) );
00836       *obj = std::complex<Scalar>( real, imag );
00837     }
00838 private:
00839   static void assertInput(
00840     const ArrayView<const primitiveType> &primitiveObjs,
00841     const ArrayView<const index_type> &indexObjs,
00842     const ArrayView<const char> &charObjs
00843     )
00844     {
00845 #ifdef TEUCHOS_DEBUG
00846       TEST_FOR_EXCEPT(
00847         primitiveObjs.size()!=2*ScalarPrimitiveTypeTraits::numPrimitiveObjs()
00848         || indexObjs.size()!=0
00849         || charObjs.size()!=0 );
00850 #endif
00851     }
00852 };
00853 
00854 
00858 template <class Scalar>
00859 class PrimitiveTypeTraits<std::complex<Scalar>, Scalar> {
00860 public:
00862   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00864   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00866   static int numPrimitiveObjs()
00867     { return ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
00869   static int numIndexObjs() { return 0; }
00871   static int numCharObjs() { return 0; }
00873   static void extractPrimitiveObjs(
00874     const Scalar &obj,
00875     const ArrayView<primitiveType> &primitiveObjs,
00876     const ArrayView<index_type> &indexObjs,
00877     const ArrayView<char> &charObjs
00878     )
00879     {
00880       using Teuchos::null;
00881       assertInput(primitiveObjs, indexObjs, charObjs);
00882       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00883         obj, primitiveObjs, null, null );
00884     }
00886   static void loadPrimitiveObjs(
00887     const ArrayView<const primitiveType> &primitiveObjs,
00888     const ArrayView<const index_type> &indexObjs,
00889     const ArrayView<const char> &charObjs,
00890     const Ptr<Scalar > &obj
00891     )
00892     {
00893       using Teuchos::null;
00894       assertInput(primitiveObjs, indexObjs, charObjs);
00895       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00896         primitiveObjs, null, null, obj );
00897     }
00898 private:
00899   static void assertInput(
00900     const ArrayView<const primitiveType> &primitiveObjs,
00901     const ArrayView<const index_type> &indexObjs,
00902     const ArrayView<const char> &charObjs
00903     )
00904     {
00905 #ifdef TEUCHOS_DEBUG
00906       TEST_FOR_EXCEPT(
00907         primitiveObjs.size()!=ScalarPrimitiveTypeTraits::numPrimitiveObjs()
00908         || indexObjs.size()!=0
00909         || charObjs.size()!=0 );
00910 #endif
00911     }
00912 };
00913 
00914 
00915 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00916 
00917 
00918 
00919 //
00920 // Forward declaration for templated types
00921 //
00922 
00923 
00925 template<class Scalar>  class RTOpT;
00926 
00927 
00928 } // namespace RTOpPack
00929 
00930 
00931 #endif // RTOPPACK_TYPES_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines