Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_TemplateManager.hpp
Go to the documentation of this file.
1 // $Id$
2 // $Source$
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Sacado Package
7 // Copyright (2006) Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // This library is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as
14 // published by the Free Software Foundation; either version 2.1 of the
15 // License, or (at your option) any later version.
16 //
17 // This library is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 // Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
25 // USA
26 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27 // (etphipp@sandia.gov).
28 //
29 // ***********************************************************************
30 // @HEADER
31 
32 #ifndef SACADO_TEMPLATEMANAGER_HPP
33 #define SACADO_TEMPLATEMANAGER_HPP
34 
35 #include <vector>
36 #include <typeinfo>
37 
38 #include "Teuchos_RCP.hpp"
39 
40 #include "Sacado_mpl_size.hpp"
41 #include "Sacado_mpl_find.hpp"
42 #include "Sacado_mpl_for_each.hpp"
43 #include "Sacado_mpl_apply.hpp"
44 
46 
47 namespace Sacado {
48 
50 
70  template <typename TypeSeq, typename BaseT, typename ObjectT>
72 
74  struct type_info_less {
75  bool operator() (const std::type_info* a, const std::type_info* b) {
76  return a->before(*b);
77  }
78  };
79 
80  template <typename BuilderOpT>
81  struct BuildObject {
82  std::vector< Teuchos::RCP<BaseT> >* objects;
83  const BuilderOpT& builder;
84  BuildObject(std::vector< Teuchos::RCP<BaseT> >& objects_,
85  const BuilderOpT& builder_) :
86  objects(&objects_), builder(builder_) {}
87  template <typename T> void operator()(T) const {
89  (*objects)[idx] = builder.template build<T>();
90  }
91  };
92 
93  public:
94 
97 
100 
103 
105  template<class ScalarT>
107  typedef typename Sacado::mpl::apply<ObjectT,ScalarT>::type type;
108  return Teuchos::rcp( dynamic_cast<BaseT*>( new type ) );
109  }
110 
111  };
112 
114  TemplateManager();
115 
118 
120  template <typename BuilderOpT>
121  void buildObjects(const BuilderOpT& builder);
122 
124  void buildObjects();
125 
127  template<typename ScalarT>
129 
131  template<typename ScalarT>
133 
135  template<typename ScalarT>
137 
139  template<typename ScalarT>
141 
144 
147  begin() const;
148 
151 
154  end() const;
155 
156  private:
157 
159  std::vector< Teuchos::RCP<BaseT> > objects;
160 
161  };
162 
163 }
164 
165 // Include template definitions
167 
168 #endif
ConstTemplateIterator< BaseT > const_iterator
Typedef for const_iterator.
std::vector< Teuchos::RCP< BaseT > > objects
Stores array of rcp&#39;s to objects of each type.
std::vector< Teuchos::RCP< BaseT > > * objects
Teuchos::RCP< typename Sacado::mpl::apply< ObjectT, ScalarT >::type > getAsObject()
Get RCP to object corrensponding to ScalarT as ObjectT&lt;ScalarT&gt;
TemplateManager()
Default constructor.
F::template apply< A1, A2, A3, A4, A5 >::type type
void buildObjects()
Build objects for each ScalarT using default builder.
Container class to manager template instantiations of a template class.
TemplateIterator< BaseT > iterator
Typedef for iterator.
The default builder class for building objects for each ScalarT.
#define T
Definition: Sacado_rad.hpp:573
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< BaseT > getAsBase()
Get RCP to object corrensponding to ScalarT as BaseT.
Sacado::TemplateManager< TypeSeq, BaseT, ObjectT >::iterator end()
Return an iterator that points one past the last type object.
BuildObject(std::vector< Teuchos::RCP< BaseT > > &objects_, const BuilderOpT &builder_)
bool operator()(const std::type_info *a, const std::type_info *b)
Teuchos::RCP< BaseT > build() const
Returns a new rcp for an object of type ObjectT&lt;ScalarT&gt;
Implementation of &lt; for type_info objects.
Sacado::TemplateManager< TypeSeq, BaseT, ObjectT >::iterator begin()
Return an iterator that points to the first type object.