00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef PHX_TEMPLATEMANAGER_HPP
00035 #define PHX_TEMPLATEMANAGER_HPP
00036
00037 #include "Phalanx_ConfigDefs.hpp"
00038
00039 #include "Teuchos_RCP.hpp"
00040
00041 #include "Sacado_mpl_size.hpp"
00042 #include "Sacado_mpl_find.hpp"
00043 #include "Sacado_mpl_for_each.hpp"
00044
00045 #include "boost/mpl/apply.hpp"
00046
00047 namespace PHX {
00048
00049
00050 template <typename TypeSeq, typename BaseT, typename ObjectT>
00051 class TemplateIterator;
00052 template <typename TypeSeq, typename BaseT, typename ObjectT>
00053 class ConstTemplateIterator;
00054
00056
00076 template <typename TypeSeq, typename BaseT, typename ObjectT>
00077 class TemplateManager {
00078
00080 struct type_info_less {
00081 bool operator() (const std::type_info* a, const std::type_info* b) {
00082 return a->before(*b);
00083 }
00084 };
00085
00086 template <typename BuilderOpT>
00087 struct BuildObject {
00088 mutable std::vector< Teuchos::RCP<BaseT> >& objects;
00089 const BuilderOpT& builder;
00090 BuildObject(std::vector< Teuchos::RCP<BaseT> >& objects_,
00091 const BuilderOpT& builder_) :
00092 objects(objects_), builder(builder_) {}
00093 template <typename T> void operator()(T) const {
00094 int idx = Sacado::mpl::find<TypeSeq,T>::value;
00095 objects[idx] = builder.template build<T>();
00096 }
00097 };
00098
00100 friend class TemplateIterator<TypeSeq,BaseT,ObjectT>;
00101
00102 public:
00103
00105 typedef TemplateIterator<TypeSeq,BaseT,ObjectT> iterator;
00106
00108 typedef ConstTemplateIterator<TypeSeq,BaseT,ObjectT> const_iterator;
00109
00111 struct DefaultBuilderOp {
00112
00114 template<class ScalarT>
00115 Teuchos::RCP<BaseT> build() const {
00116 typedef typename boost::mpl::apply<ObjectT,ScalarT>::type type;
00117 return Teuchos::rcp( dynamic_cast<BaseT*>( new type ) );
00118 }
00119
00120 };
00121
00123 TemplateManager();
00124
00126 ~TemplateManager();
00127
00129 template <typename BuilderOpT>
00130 void buildObjects(const BuilderOpT& builder);
00131
00133 void buildObjects();
00134
00136 template<typename ScalarT>
00137 Teuchos::RCP<BaseT> getAsBase();
00138
00140 template<typename ScalarT>
00141 Teuchos::RCP<const BaseT> getAsBase() const;
00142
00144 template<typename ScalarT>
00145 Teuchos::RCP< typename boost::mpl::apply<ObjectT,ScalarT>::type > getAsObject();
00146
00148 template<typename ScalarT>
00149 Teuchos::RCP< const typename boost::mpl::apply<ObjectT,ScalarT>::type > getAsObject() const;
00150
00152 typename PHX::TemplateManager<TypeSeq,BaseT,ObjectT>::iterator begin();
00153
00155 typename PHX::TemplateManager<TypeSeq,BaseT,ObjectT>::const_iterator
00156 begin() const;
00157
00159 typename PHX::TemplateManager<TypeSeq,BaseT,ObjectT>::iterator end();
00160
00162 typename PHX::TemplateManager<TypeSeq,BaseT,ObjectT>::const_iterator
00163 end() const;
00164
00165 private:
00166
00168 std::vector< Teuchos::RCP<BaseT> > objects;
00169
00170 };
00171
00172 }
00173
00174
00175 #include "Phalanx_TemplateManager_Def.hpp"
00176
00177
00178 #include "Phalanx_TemplateIterator.hpp"
00179
00180 #endif