Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TpetraExt_TypeStack.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRAEXT_TYPE_STACK_HPP
43 #define TPETRAEXT_TYPE_STACK_HPP
44 
45 #include "Tpetra_ConfigDefs.hpp"
46 #include <Teuchos_ParameterList.hpp>
47 
49 #define TPETRAEXT_TYPESTACK1(lbl,T1) \
50  typedef Tpetra::Ext::TypeStackBottom<T1> \
51  lbl;
52 
54 #define TPETRAEXT_TYPESTACK2(lbl,T1,T2) \
55  typedef Tpetra::Ext::TypeStack<T1, \
56  T2> \
57  lbl;
58 
60 #define TPETRAEXT_TYPESTACK3(lbl,T1,T2,T3) \
61  typedef Tpetra::Ext::TypeStack<T1, \
62  Tpetra::Ext::TypeStack<T2, \
63  T3> > \
64  lbl;
65 
67 #define TPETRAEXT_TYPESTACK4(lbl,T1,T2,T3,T4) \
68  typedef Tpetra::Ext::TypeStack<T1, \
69  Tpetra::Ext::TypeStack<T2, \
70  Tpetra::Ext::TypeStack<T3, \
71  T4> > > \
72  lbl;
73 
74 namespace Tpetra {
75  namespace Ext {
76 
78  template <class T>
79  struct TypeStackBottom {
80  typedef T type;
81  typedef TypeStackBottom<T> next; // infinite loop; better be watching for bottom
82  enum { bottom = true };
83  enum { height = 1 };
84  };
85 
87  template <class T, class S>
88  struct TypeStack {
89  typedef T type;
90  typedef TypeStackBottom<S> next;
91  enum { bottom = false };
92  enum { height = 2 };
93  };
94 
96  template <class T, class S, class SS>
97  struct TypeStack<T, TypeStack<S,SS> > {
98  typedef T type;
99  typedef TypeStack<S,SS> next;
100  enum { bottom = false };
101  enum { height = 1 + next::height };
102  };
103 
104  template <class TS,class Init>
105  Teuchos::RCP<Teuchos::ParameterList>
106  initStackDB(Teuchos::ParameterList &pl, Init &init)
107  {
108  using Teuchos::ParameterList;
109  using Teuchos::RCP;
110  typedef typename TS::type T;
111  RCP<ParameterList> db = init.template initDB<T>(pl);
112  if (! TS::bottom) {
113  RCP<ParameterList> subdb = initStackDB<typename TS::next>(pl.sublist("child"),init);
114  db->set("child", *subdb);
115  }
116  return db;
117  }
118 
119  } // namespace Tpetra::Ext
120 } // namespace Tpetra
121 
122 
129 #endif // TPETRAEXT_TYPE_STACK_HPP
Implementation of a Tpetra::Ext::TypeStack, supporting the last entry.
Implementation of a Tpetra::Ext::TypeStack, supporting the next to last entry.