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 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 
00030 
00031 #ifndef RTOPPACK_TYPES_HPP
00032 #define RTOPPACK_TYPES_HPP
00033 
00034 
00035 #include "RTOp_ConfigDefs.hpp"
00036 #include "Teuchos_Array.hpp"
00037 #include "Teuchos_RCP.hpp"
00038 #include "Teuchos_ArrayRCP.hpp"
00039 #include "Teuchos_Range1D.hpp"
00040 #include "Teuchos_ScalarTraits.hpp"
00041 #include "Teuchos_TypeNameTraits.hpp"
00042 #include "Teuchos_TestForException.hpp"
00043 #include "Teuchos_implicit_cast.hpp"
00044 
00045 
00046 namespace RTOpPack {
00047 
00048 
00049 //
00050 // Basic types
00051 //
00052 
00054 typedef Teuchos_Ordinal Ordinal;
00056 RTOP_DEPRECATED typedef Teuchos_Index Index;
00058 using Teuchos::Ptr;
00060 using Teuchos::RCP;
00062 using Teuchos::ArrayRCP;
00064 using Teuchos::ArrayView;
00066 using Teuchos::Array;
00068 using Teuchos::Range1D;
00070 using Teuchos::ScalarTraits;
00072 using Teuchos::TypeNameTraits;
00073 
00075 typedef Teuchos_Index index_type;
00077 typedef char  char_type;
00078 
00079 
00080 //
00081 // Exceptions
00082 //
00083 
00084 
00086 class UnknownError : public std::logic_error
00087 {public: UnknownError(const std::string& what_arg) : std::logic_error(what_arg) {}};
00089 class InvalidUsage : public std::logic_error
00090 {public: InvalidUsage(const std::string& what_arg) : std::logic_error(what_arg) {}};
00092 class InvalidNumVecs : public std::logic_error
00093 {public: InvalidNumVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00095 class InvalidNumTargVecs : public std::logic_error
00096 {public: InvalidNumTargVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00098 class IncompatibleVecs : public std::logic_error
00099 {public: IncompatibleVecs(const std::string& what_arg) : std::logic_error(what_arg) {}};
00101 class IncompatibleReductObj : public std::logic_error
00102 {public: IncompatibleReductObj(const std::string& what_arg) : std::logic_error(what_arg) {}};
00103 
00104 
00105 //
00106 // VectorBase subviews
00107 //
00108 
00109 
00129 template<class Scalar>
00130 class ConstSubVectorView {
00131 public:
00133   ConstSubVectorView() : globalOffset_(0), subDim_(0), stride_(0) {}
00135   ConstSubVectorView(const ArrayRCP<const Scalar> &values_in)
00136     :globalOffset_(0), subDim_(0), stride_(0)
00137     { initialize(0, values_in.size(), values_in, 1); }
00139   ConstSubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00140     const ArrayRCP<const Scalar> &values_in, ptrdiff_t stride_in)
00141     :globalOffset_(0), subDim_(0), stride_(0)
00142     { initialize(globalOffset_in, subDim_in, values_in, stride_in); }
00144   ConstSubVectorView( const ConstSubVectorView<Scalar>& sv )
00145     :globalOffset_(sv.globalOffset()), subDim_(sv.subDim()),
00146      values_(sv.values()), stride_(sv.stride()) 
00147     {}
00149   void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00150     const ArrayRCP<const Scalar> &values_in, ptrdiff_t stride_in)
00151     {
00152 #ifdef TEUCHOS_DEBUG
00153       TEUCHOS_ASSERT(globalOffset_in >= 0);
00154       if (!is_null(values_in)) {
00155         TEUCHOS_ASSERT(subDim_in >= 0);
00156         TEUCHOS_ASSERT(stride_in != 0);
00157         TEUCHOS_ASSERT(
00158           subDim_in*std::abs(Teuchos::as<int>(stride_in)) - 1 <= values_in.upperOffset());
00159         TEUCHOS_ASSERT(values_in.lowerOffset() <= 0);
00160       }
00161       else {
00162         TEUCHOS_ASSERT(stride_in == 0);
00163         TEUCHOS_ASSERT(subDim_in==0);
00164       }
00165 #endif
00166       globalOffset_=globalOffset_in;
00167       subDim_=subDim_in;
00168       values_=values_in;
00169       stride_=stride_in;
00170     }
00172   void uninitialize()
00173     { globalOffset_ = 0; subDim_=0; values_ = Teuchos::null; stride_ = 0; }
00175   void setGlobalOffset(Ordinal globalOffset_in)
00176     {
00177 #ifdef TEUCHOS_DEBUG
00178       TEUCHOS_ASSERT(globalOffset_in >= 0);
00179 #endif
00180       globalOffset_ = globalOffset_in;
00181     } 
00183   Ordinal globalOffset() const { return globalOffset_; }
00185   Ordinal subDim() const { return subDim_; }
00187   const ArrayRCP<const Scalar>  values() const { return values_; }
00189   ptrdiff_t stride() const { return stride_; }
00192   const Scalar& operator[](Ordinal i) const
00193     {
00194 #ifdef TEUCHOS_DEBUG
00195       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, subDim_);
00196 #endif
00197       return valuesBegin()[stride_*i];
00198     }
00201   const Scalar& operator()(Ordinal i) const { return (*this)[i]; }
00202 private:
00203   Ordinal globalOffset_;
00204   Ordinal subDim_;
00205   ArrayRCP<const Scalar> values_;
00206   ptrdiff_t stride_;
00207   const typename ArrayRCP<const Scalar>::iterator valuesBegin() const
00208     {
00209       if (stride_ > 0)
00210         return values_.begin();
00211       return values_.begin() + (subDim_*std::abs(Teuchos::as<int>(stride_)) - 1);
00212     } 
00213 public:
00215   RTOP_DEPRECATED ConstSubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00216     const Scalar values_in[], ptrdiff_t stride_in)
00217     :globalOffset_(globalOffset_in), subDim_(subDim_in),
00218      values_(values_in,0,subDim_in*stride_in,false), stride_(stride_in) 
00219     {}
00221   RTOP_DEPRECATED void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00222     const Scalar values_in[], ptrdiff_t stride_in)
00223     {
00224       globalOffset_=globalOffset_in; subDim_=subDim_in;
00225       values_=Teuchos::arcp(values_in, 0,
00226         subDim_in*std::abs(Teuchos::as<int>(stride_in)), false);
00227       stride_=stride_in;
00228     }
00230   RTOP_DEPRECATED void set_uninitialized()
00231     { uninitialize(); }
00232 };
00233 
00234 
00251 template<class Scalar>
00252 class SubVectorView : public ConstSubVectorView<Scalar> {
00253 public:
00255   SubVectorView() {}
00257   SubVectorView(const ArrayRCP<Scalar> &values_in)
00258     :ConstSubVectorView<Scalar>(values_in)
00259     {}
00261   SubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00262     const ArrayRCP<Scalar> &values_in, ptrdiff_t stride_in)
00263     :ConstSubVectorView<Scalar>(globalOffset_in, subDim_in, values_in, stride_in)
00264     {}
00266   SubVectorView(Ordinal subDim_in)
00267     :ConstSubVectorView<Scalar>(0, subDim_in, Teuchos::arcp<Scalar>(subDim_in), 1)
00268     {}
00270   SubVectorView(const SubVectorView<Scalar> & sv)
00271     :ConstSubVectorView<Scalar>(sv)
00272     {}
00274   void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00275     const ArrayRCP<Scalar> &values_in, ptrdiff_t stride_in)
00276     { ConstSubVectorView<Scalar>::initialize(globalOffset_in, subDim_in, values_in, stride_in); }
00278   const ArrayRCP<Scalar> values() const
00279     { return Teuchos::arcp_const_cast<Scalar>(ConstSubVectorView<Scalar>::values());  }
00282   Scalar& operator[](Ordinal i) const
00283     { return const_cast<Scalar&>(ConstSubVectorView<Scalar>::operator[](i)); }
00286   Scalar& operator()(Ordinal i) const { return (*this)[i]; }
00287 public:
00289   RTOP_DEPRECATED SubVectorView(Ordinal globalOffset_in, Ordinal subDim_in,
00290     Scalar values_in[], ptrdiff_t stride_in)
00291     :ConstSubVectorView<Scalar>(globalOffset_in, subDim_in, values_in, stride_in)
00292     {}
00294   RTOP_DEPRECATED void initialize(Ordinal globalOffset_in, Ordinal subDim_in,
00295     Scalar values_in[], ptrdiff_t stride_in)
00296     { ConstSubVectorView<Scalar>::initialize(globalOffset_in, subDim_in, values_in, stride_in); }
00297 };
00298 
00299 
00301 template<class Scalar>
00302 void assign_entries( const Ptr<const SubVectorView<Scalar> > &msv,
00303   const ConstSubVectorView<Scalar> &sv )
00304 {
00305 #ifdef TEUCHOS_DEBUG
00306   TEUCHOS_ASSERT_EQUALITY(msv->subDim(), sv.subDim());
00307 #endif
00308   for( int i = 0; i < sv.subDim(); ++i ) {
00309     (*msv)(i) = sv(i);
00310   }
00311 }
00312 
00313 
00318 template<class Scalar>
00319 std::ostream& operator<<(std::ostream &out, const ConstSubVectorView<Scalar> &sv)
00320 {
00321   out
00322     << "{"
00323     << "globalOffset="<<sv.globalOffset()
00324     << ",subDim="<<sv.subDim()
00325     << ",values="<<sv.values()
00326     << ",stride="<<sv.stride()
00327     << "}";
00328   return out;
00329 }
00330 
00331 
00332 //
00333 // MultiVectorBase subviews
00334 //
00335 
00336 
00358 template<class Scalar>
00359 class ConstSubMultiVectorView {
00360 public:
00362   ConstSubMultiVectorView()
00363     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
00364      leadingDim_(0)
00365     {}
00367   ConstSubMultiVectorView(
00368     Ordinal globalOffset_in, Ordinal subDim_in,
00369     Ordinal colOffset_in, Ordinal numSubCols_in,
00370     const ArrayRCP<const Scalar> &values_in, Ordinal leadingDim_in
00371     )
00372     :globalOffset_(0), subDim_(0), colOffset_(0), numSubCols_(0),
00373      leadingDim_(0)
00374     {
00375       initialize(globalOffset_in, subDim_in, colOffset_in, numSubCols_in, values_in,
00376         leadingDim_in);
00377     }
00379   ConstSubMultiVectorView( const ConstSubMultiVectorView<Scalar>& smv )
00380     :globalOffset_(smv.globalOffset()), subDim_(smv.subDim()),
00381      colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols()),
00382      values_(smv.values()), leadingDim_(smv.leadingDim())
00383     {}
00385   void initialize(
00386     Ordinal globalOffset_in, Ordinal subDim_in,
00387     Ordinal colOffset_in, Ordinal numSubCols_in,
00388     const ArrayRCP<const Scalar> &values_in, Ordinal leadingDim_in
00389     )
00390     {
00391 #ifdef TEUCHOS_DEBUG
00392       TEUCHOS_ASSERT(globalOffset_in >= 0);
00393       TEUCHOS_ASSERT(colOffset_in >= 0);
00394       if (!is_null(values_in)) {
00395         TEUCHOS_ASSERT(subDim_in >= 0);
00396         TEUCHOS_ASSERT(leadingDim_in >= subDim_in);
00397         TEUCHOS_ASSERT(numSubCols_in*leadingDim_in - 1 <= values_in.upperOffset());
00398         TEUCHOS_ASSERT(values_in.lowerOffset() <= 0);
00399       }
00400       else {
00401         TEUCHOS_ASSERT(subDim_in == 0);
00402         TEUCHOS_ASSERT(leadingDim_in == 0);
00403         TEUCHOS_ASSERT(numSubCols_in == 0);
00404       }
00405 #endif
00406       globalOffset_=globalOffset_in;
00407       subDim_=subDim_in;
00408       colOffset_=colOffset_in;
00409       numSubCols_=numSubCols_in;
00410       values_=values_in;
00411       leadingDim_=leadingDim_in;
00412     }
00414   void uninitialize()
00415     {
00416       globalOffset_ = 0; subDim_=0; colOffset_=0, numSubCols_=0;
00417       values_=Teuchos::null; leadingDim_=0;
00418     }
00420   void setGlobalOffset(Ordinal globalOffset_in)
00421     {
00422 #ifdef TEUCHOS_DEBUG
00423       TEUCHOS_ASSERT(globalOffset_in >= 0);
00424 #endif
00425       globalOffset_ = globalOffset_in;
00426     } 
00428   Ordinal globalOffset() const { return globalOffset_; }
00430   Ordinal subDim() const { return subDim_; }
00432   Ordinal colOffset() const { return colOffset_; }
00434   Ordinal numSubCols() const { return numSubCols_; }
00436   const ArrayRCP<const Scalar> values() const { return values_; }
00438   Ordinal leadingDim() const { return leadingDim_; }
00442   const Scalar& operator()(Ordinal i, Ordinal j) const
00443     {
00444 #ifdef TEUCHOS_DEBUG
00445       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, subDim_);
00446       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, numSubCols_ );
00447 #endif
00448       return values_[ i + leadingDim_*j ];
00449     }
00453   ConstSubVectorView<Scalar> col( const Ordinal j ) const
00454     {
00455 #ifdef TEUCHOS_DEBUG
00456       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, numSubCols_ );
00457 #endif
00458       return ConstSubVectorView<Scalar>(
00459         globalOffset(), subDim(), values().persistingView(j*leadingDim(),subDim()), 1 );
00460     }
00461 private:
00462   Ordinal globalOffset_;
00463   Ordinal subDim_;
00464   Ordinal colOffset_;
00465   Ordinal numSubCols_;
00466   ArrayRCP<const Scalar> values_;
00467   Ordinal leadingDim_;
00468 public:
00470   RTOP_DEPRECATED ConstSubMultiVectorView(
00471     Ordinal globalOffset_in, Ordinal subDim_in,
00472     Ordinal colOffset_in, Ordinal numSubCols_in,
00473     const Scalar values_in[], Ordinal leadingDim_in
00474     )
00475     :globalOffset_(globalOffset_in), subDim_(subDim_in),
00476      colOffset_(colOffset_in), numSubCols_(numSubCols_in),
00477      values_(values_in,0,numSubCols_in*leadingDim_in,false),
00478      leadingDim_(leadingDim_in)
00479     {}
00481   RTOP_DEPRECATED void initialize(
00482     Ordinal globalOffset_in, Ordinal subDim_in,
00483     Ordinal colOffset_in, Ordinal numSubCols_in,
00484     const Scalar values_in[], Ordinal leadingDim_in
00485     )
00486     {
00487       globalOffset_=globalOffset_in; subDim_=subDim_in; colOffset_=colOffset_in;
00488       numSubCols_=numSubCols_in;
00489       values_=Teuchos::arcp(values_in,0,numSubCols_in*leadingDim_in,false);
00490       leadingDim_=leadingDim_in;
00491     }
00493   RTOP_DEPRECATED void set_uninitialized()
00494     { uninitialize(); }
00495 };
00496 
00497 
00514 template<class Scalar>
00515 class SubMultiVectorView : public ConstSubMultiVectorView<Scalar> {
00516 public:
00518   SubMultiVectorView() {}
00520   SubMultiVectorView(
00521     Ordinal numRows_in, Ordinal numCols_in
00522     )
00523     :ConstSubMultiVectorView<Scalar>(0, numRows_in, 0, numCols_in,
00524       Teuchos::arcp<Scalar>(numRows_in*numCols_in), numRows_in)
00525     {}
00527   SubMultiVectorView(
00528     Ordinal globalOffset_in, Ordinal subDim_in,
00529     Ordinal colOffset_in, Ordinal numSubCols_in,
00530     const ArrayRCP<Scalar> &values_in, Ordinal leadingDim_in
00531     )
00532     :ConstSubMultiVectorView<Scalar>(globalOffset_in, subDim_in,
00533       colOffset_in, numSubCols_in, values_in, leadingDim_in)
00534     {}
00536   SubMultiVectorView( const SubMultiVectorView<Scalar> & smv)
00537     :ConstSubMultiVectorView<Scalar>(smv)
00538     {}
00540  void initialize(
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    {
00546      ConstSubMultiVectorView<Scalar>::initialize(globalOffset_in,
00547        subDim_in, colOffset_in, numSubCols_in, values_in, leadingDim_in);
00548    }
00550   const ArrayRCP<Scalar> values() const
00551     {
00552       return Teuchos::arcp_const_cast<Scalar>(
00553         ConstSubMultiVectorView<Scalar>::values());
00554     }
00558   Scalar& operator()(Ordinal i, Ordinal j) const
00559     { return const_cast<Scalar&>(ConstSubMultiVectorView<Scalar>::operator()(i,j)); }
00563   SubVectorView<Scalar> col( const Ordinal j ) const
00564     {
00565 #ifdef TEUCHOS_DEBUG
00566       TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(j, 0, this->numSubCols());
00567 #endif
00568       return SubVectorView<Scalar>(this->globalOffset(), this->subDim(),
00569         values().persistingView(j*this->leadingDim(),this->subDim()), 1);
00570     }
00571 public:
00573   RTOP_DEPRECATED SubMultiVectorView(
00574     Ordinal globalOffset_in, Ordinal subDim_in,
00575     Ordinal colOffset_in, Ordinal numSubCols_in,
00576     Scalar values_in[], Ordinal leadingDim_in
00577     )
00578     :ConstSubMultiVectorView<Scalar>(globalOffset_in, subDim_in,
00579        colOffset_in, numSubCols_in, values_in, leadingDim_in)
00580     {}
00582  RTOP_DEPRECATED void initialize(
00583    Ordinal globalOffset_in, Ordinal subDim_in,
00584    Ordinal colOffset_in, Ordinal numSubCols_in,
00585    Scalar values_in[], Ordinal leadingDim_in
00586    )
00587    {
00588      ConstSubMultiVectorView<Scalar>::initialize(globalOffset_in,
00589        subDim_in, colOffset_in, numSubCols_in, values_in, leadingDim_in);
00590    }
00591 };
00592 
00593 
00595 template<class Scalar>
00596 void assign_entries( const Ptr<const SubMultiVectorView<Scalar> > &msmv,
00597   const ConstSubMultiVectorView<Scalar> &smv )
00598 {
00599 #ifdef TEUCHOS_DEBUG
00600   TEUCHOS_ASSERT_EQUALITY(msmv->subDim(), smv.subDim());
00601   TEUCHOS_ASSERT_EQUALITY(msmv->numSubCols(), smv.numSubCols());
00602 #endif
00603   for( Ordinal j = 0; j < smv.numSubCols(); ++j ) {
00604     for( Ordinal i = 0; i < smv.subDim(); ++i ) {
00605       (*msmv)(i,j) = smv(i,j);
00606     }
00607   }
00608 }
00609 
00610 
00611 //
00612 // Primitive Type Traits
00613 //
00614 
00615 
00626 template <class Scalar, class ConcreteObj>
00627 class PrimitiveTypeTraits {
00628 public:
00630   typedef Scalar primitiveType;
00632   static int numPrimitiveObjs()
00633     { return Scalar::this_type_is_missing_a_specialization(); }
00635   static int numIndexObjs()
00636     { return Scalar::this_type_is_missing_a_specialization(); }
00638   static int numCharObjs()
00639     { return Scalar::this_type_is_missing_a_specialization(); }
00641   static void extractPrimitiveObjs(
00642     const Scalar &obj,
00643     const ArrayView<primitiveType> &primitiveObjs,
00644     const ArrayView<index_type> &indexObjs,
00645     const ArrayView<char> &charObjs
00646     )
00647     {
00648       Scalar::this_type_is_missing_a_specialization(obj);
00649     }
00651   static void loadPrimitiveObjs(
00652     const ArrayView<const primitiveType> &primitiveObjs,
00653     const ArrayView<const index_type> &indexObjs,
00654     const ArrayView<const char> &charObjs,
00655     const Ptr<Scalar> &obj
00656     )
00657     {
00658       *obj = Scalar::this_type_is_missing_a_specialization();
00659     }
00660 };
00661 
00662 
00663 
00667 template <class Scalar>
00668 class PrimitiveTypeTraits<Scalar, Scalar> {
00669 public:
00671   typedef Scalar primitiveType;
00673   static int numPrimitiveObjs() { return 1; }
00675   static int numIndexObjs() { return 0; }
00677   static int numCharObjs() { return 0; }
00679   static void extractPrimitiveObjs(
00680     const Scalar &obj,
00681     const ArrayView<primitiveType> &primitiveObjs,
00682     const ArrayView<index_type> &indexObjs,
00683     const ArrayView<char> &charObjs
00684     )
00685     {
00686       assertInput(primitiveObjs, indexObjs, charObjs);
00687       primitiveObjs[0] = obj;
00688     }
00690   static void loadPrimitiveObjs(
00691     const ArrayView<const primitiveType> &primitiveObjs,
00692     const ArrayView<const index_type> &indexObjs,
00693     const ArrayView<const char> &charObjs,
00694     const Ptr<Scalar> &obj
00695     )
00696     {
00697       assertInput(primitiveObjs, indexObjs, charObjs);
00698       *obj = primitiveObjs[0];
00699     }
00700 private:
00701   static void assertInput(
00702     const ArrayView<const primitiveType> &primitiveObjs,
00703     const ArrayView<const index_type> &indexObjs,
00704     const ArrayView<const char> &charObjs
00705     )
00706     {
00707 #ifdef TEUCHOS_DEBUG
00708       TEST_FOR_EXCEPT( primitiveObjs.size()!=1 || indexObjs.size()!=0
00709         || charObjs.size()!=0 );
00710 #endif
00711     }
00712 };
00713 
00714 
00716 template <class Scalar>
00717 class PrimitiveTypeTraits<Scalar, index_type> {
00718 public:
00720   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00722   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00724   static int numPrimitiveObjs() { return 0; }
00726   static int numIndexObjs() { return 1; }
00728   static int numCharObjs() { return 0; }
00730   static void extractPrimitiveObjs(
00731     const index_type &obj,
00732     const ArrayView<primitiveType> &primitiveObjs,
00733     const ArrayView<index_type> &indexObjs,
00734     const ArrayView<char> &charObjs
00735     )
00736     {
00737       assertInput(primitiveObjs, indexObjs, charObjs);
00738       indexObjs[0] = obj;
00739     }
00741   static void loadPrimitiveObjs(
00742     const ArrayView<const primitiveType> &primitiveObjs,
00743     const ArrayView<const index_type> &indexObjs,
00744     const ArrayView<const char> &charObjs,
00745     const Ptr<index_type> &obj
00746     )
00747     {
00748       assertInput(primitiveObjs, indexObjs, charObjs);
00749       *obj = indexObjs[0];
00750     }
00751 private:
00752   static void assertInput(
00753     const ArrayView<const primitiveType> &primitiveObjs,
00754     const ArrayView<const index_type> &indexObjs,
00755     const ArrayView<const char> &charObjs
00756     )
00757     {
00758 #ifdef TEUCHOS_DEBUG
00759       TEST_FOR_EXCEPT( primitiveObjs.size()!=0 || indexObjs.size()!=1
00760         || charObjs.size()!=0 );
00761 #endif
00762     }
00763 };
00764 
00765 
00766 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00767 
00768 
00772 template <class Scalar>
00773 class PrimitiveTypeTraits<std::complex<Scalar>, std::complex<Scalar> > {
00774 public:
00776   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00778   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00780   static int numPrimitiveObjs()
00781     { return 2*ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
00783   static int numIndexObjs() { return 0; }
00785   static int numCharObjs() { return 0; }
00787   static void extractPrimitiveObjs(
00788     const std::complex<Scalar> &obj,
00789     const ArrayView<primitiveType> &primitiveObjs,
00790     const ArrayView<index_type> &indexObjs,
00791     const ArrayView<char> &charObjs
00792     )
00793     {
00794       using Teuchos::null;
00795       const int numScalarPrimitiveObjs =
00796         ScalarPrimitiveTypeTraits::numPrimitiveObjs();
00797       assertInput(primitiveObjs, indexObjs, charObjs);
00798       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00799         obj.real(), primitiveObjs(0,numScalarPrimitiveObjs), null, null );
00800       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00801         obj.imag(), primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null );
00802     }
00804   static void loadPrimitiveObjs(
00805     const ArrayView<const primitiveType> &primitiveObjs,
00806     const ArrayView<const index_type> &indexObjs,
00807     const ArrayView<const char> &charObjs,
00808     const Ptr<std::complex<Scalar> > &obj
00809     )
00810     {
00811       using Teuchos::null;
00812       using Teuchos::outArg;
00813       assertInput(primitiveObjs, indexObjs, charObjs);
00814       const int numScalarPrimitiveObjs =
00815         ScalarPrimitiveTypeTraits::numPrimitiveObjs();
00816       Scalar real, imag;
00817       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00818         primitiveObjs(0,numScalarPrimitiveObjs), null, null,
00819         outArg(real) );
00820       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00821         primitiveObjs(numScalarPrimitiveObjs,numScalarPrimitiveObjs), null, null,
00822         outArg(imag) );
00823       *obj = std::complex<Scalar>( real, imag );
00824     }
00825 private:
00826   static void assertInput(
00827     const ArrayView<const primitiveType> &primitiveObjs,
00828     const ArrayView<const index_type> &indexObjs,
00829     const ArrayView<const char> &charObjs
00830     )
00831     {
00832 #ifdef TEUCHOS_DEBUG
00833       TEST_FOR_EXCEPT(
00834         primitiveObjs.size()!=2*ScalarPrimitiveTypeTraits::numPrimitiveObjs()
00835         || indexObjs.size()!=0
00836         || charObjs.size()!=0 );
00837 #endif
00838     }
00839 };
00840 
00841 
00845 template <class Scalar>
00846 class PrimitiveTypeTraits<std::complex<Scalar>, Scalar> {
00847 public:
00849   typedef PrimitiveTypeTraits<Scalar,Scalar> ScalarPrimitiveTypeTraits;
00851   typedef typename ScalarPrimitiveTypeTraits::primitiveType primitiveType;
00853   static int numPrimitiveObjs()
00854     { return ScalarPrimitiveTypeTraits::numPrimitiveObjs(); }
00856   static int numIndexObjs() { return 0; }
00858   static int numCharObjs() { return 0; }
00860   static void extractPrimitiveObjs(
00861     const Scalar &obj,
00862     const ArrayView<primitiveType> &primitiveObjs,
00863     const ArrayView<index_type> &indexObjs,
00864     const ArrayView<char> &charObjs
00865     )
00866     {
00867       using Teuchos::null;
00868       assertInput(primitiveObjs, indexObjs, charObjs);
00869       ScalarPrimitiveTypeTraits::extractPrimitiveObjs(
00870         obj, primitiveObjs, null, null );
00871     }
00873   static void loadPrimitiveObjs(
00874     const ArrayView<const primitiveType> &primitiveObjs,
00875     const ArrayView<const index_type> &indexObjs,
00876     const ArrayView<const char> &charObjs,
00877     const Ptr<Scalar > &obj
00878     )
00879     {
00880       using Teuchos::null;
00881       assertInput(primitiveObjs, indexObjs, charObjs);
00882       ScalarPrimitiveTypeTraits::loadPrimitiveObjs(
00883         primitiveObjs, null, null, obj );
00884     }
00885 private:
00886   static void assertInput(
00887     const ArrayView<const primitiveType> &primitiveObjs,
00888     const ArrayView<const index_type> &indexObjs,
00889     const ArrayView<const char> &charObjs
00890     )
00891     {
00892 #ifdef TEUCHOS_DEBUG
00893       TEST_FOR_EXCEPT(
00894         primitiveObjs.size()!=ScalarPrimitiveTypeTraits::numPrimitiveObjs()
00895         || indexObjs.size()!=0
00896         || charObjs.size()!=0 );
00897 #endif
00898     }
00899 };
00900 
00901 
00902 #endif // defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00903 
00904 
00905 
00906 //
00907 // Forward declaration for templated types
00908 //
00909 
00910 
00912 template<class Scalar>  class RTOpT;
00913 
00914 
00915 } // namespace RTOpPack
00916 
00917 
00918 #endif // RTOPPACK_TYPES_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines