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 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_TEMPLATEMANAGER_HPP
11 #define SACADO_TEMPLATEMANAGER_HPP
12 
13 #include <vector>
14 #include <typeinfo>
15 
16 #include "Teuchos_RCP.hpp"
17 
18 #include "Sacado_mpl_size.hpp"
19 #include "Sacado_mpl_find.hpp"
20 #include "Sacado_mpl_for_each.hpp"
21 #include "Sacado_mpl_apply.hpp"
22 
24 
25 namespace Sacado {
26 
28 
48  template <typename TypeSeq, typename BaseT, typename ObjectT>
50 
52  struct type_info_less {
53  bool operator() (const std::type_info* a, const std::type_info* b) {
54  return a->before(*b);
55  }
56  };
57 
58  template <typename BuilderOpT>
59  struct BuildObject {
60  std::vector< Teuchos::RCP<BaseT> >* objects;
61  const BuilderOpT& builder;
62  BuildObject(std::vector< Teuchos::RCP<BaseT> >& objects_,
63  const BuilderOpT& builder_) :
64  objects(&objects_), builder(builder_) {}
65  template <typename T> void operator()(T) const {
67  (*objects)[idx] = builder.template build<T>();
68  }
69  };
70 
71  public:
72 
75 
78 
81 
83  template<class ScalarT>
85  typedef typename Sacado::mpl::apply<ObjectT,ScalarT>::type type;
86  return Teuchos::rcp( dynamic_cast<BaseT*>( new type ) );
87  }
88 
89  };
90 
93 
96 
98  template <typename BuilderOpT>
99  void buildObjects(const BuilderOpT& builder);
100 
102  void buildObjects();
103 
105  template<typename ScalarT>
107 
109  template<typename ScalarT>
111 
113  template<typename ScalarT>
115 
117  template<typename ScalarT>
119 
122 
125  begin() const;
126 
129 
132  end() const;
133 
134  private:
135 
137  std::vector< Teuchos::RCP<BaseT> > objects;
138 
139  };
140 
141 }
142 
143 // Include template definitions
145 
146 #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:553
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.