Tpetra Matrix/Vector Services Version of the Day
TpetraExt_TypeStack.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //               Tpetra: Templated Linear Algebra Services Package 
00005 //                 Copyright (2008) 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 TPETRAEXT_TYPE_STACK_HPP
00030 #define TPETRAEXT_TYPE_STACK_HPP
00031 
00032 #include "Tpetra_ConfigDefs.hpp"
00033 #include <Teuchos_ParameterList.hpp>
00034 
00036 #define TPETRAEXT_TYPESTACK1(lbl,T1)              \
00037         typedef Tpetra::Ext::TypeStackBottom<T1>  \
00038                                              lbl;
00039 
00041 #define TPETRAEXT_TYPESTACK2(lbl,T1,T2)           \
00042         typedef Tpetra::Ext::TypeStack<T1,        \
00043                                        T2>        \
00044                                        lbl;
00045 
00047 #define TPETRAEXT_TYPESTACK3(lbl,T1,T2,T3)        \
00048         typedef Tpetra::Ext::TypeStack<T1,        \
00049                 Tpetra::Ext::TypeStack<T2,        \
00050                                        T3> >      \
00051                                        lbl;
00052 
00054 #define TPETRAEXT_TYPESTACK4(lbl,T1,T2,T3,T4)     \
00055         typedef Tpetra::Ext::TypeStack<T1,        \
00056                 Tpetra::Ext::TypeStack<T2,        \
00057                 Tpetra::Ext::TypeStack<T3,        \
00058                                        T4> > >    \
00059                                        lbl;
00060 
00061 namespace Tpetra {
00062   namespace Ext {
00063 
00065     template <class T>
00066     struct TypeStackBottom {
00067       typedef T                  type;
00068       typedef TypeStackBottom<T> next; // infinite loop; better be watching for bottom
00069       enum { bottom = true };
00070       enum { height = 1 };
00071     };
00072 
00074     template <class T, class S>
00075     struct TypeStack {
00076       typedef T                  type;
00077       typedef TypeStackBottom<S> next;
00078       enum { bottom = false };
00079       enum { height = 2 };
00080     };
00081 
00083     template <class T, class S, class SS>
00084     struct TypeStack<T, TypeStack<S,SS> > {
00085       typedef T               type;
00086       typedef TypeStack<S,SS> next;
00087       enum { bottom = false };
00088       enum { height = 1 + next::height };
00089     };
00090 
00091     template <class TS,class Init>
00092     RCP<Teuchos::ParameterList>
00093     initStackDB(Teuchos::ParameterList &pl, Init &init)
00094     {
00095       using Teuchos::ParameterList;
00096       typedef typename TS::type T;
00097       RCP<ParameterList> db = init.template initDB<T>(pl);
00098       if (! TS::bottom) {
00099         RCP<ParameterList> subdb = initStackDB<typename TS::next>(pl.sublist("child"),init);
00100         db->set("child", *subdb);
00101       }
00102       return db;
00103     }
00104 
00105   } // namespace Tpetra::Ext
00106 } // namespace Tpetra
00107 
00108 
00115 #endif // TPETRAEXT_TYPE_STACK_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines