Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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"
43#include "Sacado_mpl_apply.hpp"
44
46
47namespace Sacado {
48
50
70 template <typename TypeSeq, typename BaseT, typename ObjectT>
72
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>
106 Teuchos::RCP<BaseT> build() const {
107 typedef typename Sacado::mpl::apply<ObjectT,ScalarT>::type type;
108 return Teuchos::rcp( dynamic_cast<BaseT*>( new type ) );
109 }
110
111 };
112
115
118
120 template <typename BuilderOpT>
121 void buildObjects(const BuilderOpT& builder);
122
124 void buildObjects();
125
127 template<typename ScalarT>
128 Teuchos::RCP<BaseT> getAsBase();
129
131 template<typename ScalarT>
132 Teuchos::RCP<const BaseT> getAsBase() const;
133
135 template<typename ScalarT>
136 Teuchos::RCP< typename Sacado::mpl::apply<ObjectT,ScalarT>::type > getAsObject();
137
139 template<typename ScalarT>
140 Teuchos::RCP< const typename Sacado::mpl::apply<ObjectT,ScalarT>::type > getAsObject() const;
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
#define T
Definition: Sacado_rad.hpp:573
Container class to manager template instantiations of a template class.
Teuchos::RCP< typename Sacado::mpl::apply< ObjectT, ScalarT >::type > getAsObject()
Get RCP to object corrensponding to ScalarT as ObjectT<ScalarT>
Sacado::TemplateManager< TypeSeq, BaseT, ObjectT >::iterator end()
Return an iterator that points one past the last type object.
TemplateManager()
Default constructor.
Sacado::TemplateManager< TypeSeq, BaseT, ObjectT >::iterator begin()
Return an iterator that points to the first type object.
TemplateIterator< BaseT > iterator
Typedef for iterator.
ConstTemplateIterator< BaseT > const_iterator
Typedef for const_iterator.
std::vector< Teuchos::RCP< BaseT > > objects
Stores array of rcp's to objects of each type.
Teuchos::RCP< BaseT > getAsBase()
Get RCP to object corrensponding to ScalarT as BaseT.
void buildObjects()
Build objects for each ScalarT using default builder.
std::vector< Teuchos::RCP< BaseT > > * objects
BuildObject(std::vector< Teuchos::RCP< BaseT > > &objects_, const BuilderOpT &builder_)
The default builder class for building objects for each ScalarT.
Teuchos::RCP< BaseT > build() const
Returns a new rcp for an object of type ObjectT<ScalarT>
Implementation of < for type_info objects.
bool operator()(const std::type_info *a, const std::type_info *b)
F::template apply< A1, A2, A3, A4, A5 >::type type