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 #ifndef SACADO_TEMPLATEMANAGER_HPP
00033 #define SACADO_TEMPLATEMANAGER_HPP
00034
00035 #include <vector>
00036 #include <typeinfo>
00037
00038 #include "Teuchos_RCP.hpp"
00039
00040 #include "Sacado_mpl_size.hpp"
00041 #include "Sacado_mpl_find.hpp"
00042 #include "Sacado_mpl_for_each.hpp"
00043
00044 namespace Sacado {
00045
00046
00047 template <typename TypeSeq, typename BaseT, template<typename> class ObjectT>
00048 class TemplateIterator;
00049 template <typename TypeSeq, typename BaseT, template<typename> class ObjectT>
00050 class ConstTemplateIterator;
00051
00053
00073 template <typename TypeSeq, typename BaseT, template<typename> class ObjectT>
00074 class TemplateManager {
00075
00077 struct type_info_less {
00078 bool operator() (const std::type_info* a, const std::type_info* b) {
00079 return a->before(*b);
00080 }
00081 };
00082
00083 template <typename BuilderOpT>
00084 struct BuildObject {
00085 mutable std::vector< Teuchos::RCP<BaseT> >& objects;
00086 const BuilderOpT& builder;
00087 BuildObject(std::vector< Teuchos::RCP<BaseT> >& objects_,
00088 const BuilderOpT& builder_) :
00089 objects(objects_), builder(builder_) {}
00090 template <typename T> void operator()(T) const {
00091 int idx = mpl::find<TypeSeq,T>::value;
00092 objects[idx] = builder.template build<T>();
00093 }
00094 };
00095
00097 friend class TemplateIterator<TypeSeq,BaseT,ObjectT>;
00098
00099 public:
00100
00102 typedef TemplateIterator<TypeSeq,BaseT,ObjectT> iterator;
00103
00105 typedef ConstTemplateIterator<TypeSeq,BaseT,ObjectT> const_iterator;
00106
00108 struct DefaultBuilderOp {
00109
00111 template<class ScalarT>
00112 Teuchos::RCP<BaseT> build() const {
00113 return Teuchos::rcp( dynamic_cast<BaseT*>( new ObjectT<ScalarT> ) );
00114 }
00115
00116 };
00117
00119 TemplateManager();
00120
00122 ~TemplateManager();
00123
00125 template <typename BuilderOpT>
00126 void buildObjects(const BuilderOpT& builder);
00127
00129 void buildObjects();
00130
00132 template<typename ScalarT>
00133 Teuchos::RCP<BaseT> getAsBase();
00134
00136 template<typename ScalarT>
00137 Teuchos::RCP<const BaseT> getAsBase() const;
00138
00140 template<typename ScalarT>
00141 Teuchos::RCP< ObjectT<ScalarT> > getAsObject();
00142
00144 template<typename ScalarT>
00145 Teuchos::RCP< const ObjectT<ScalarT> > getAsObject() const;
00146
00148 typename Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>::iterator begin();
00149
00151 typename Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>::const_iterator
00152 begin() const;
00153
00155 typename Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>::iterator end();
00156
00158 typename Sacado::TemplateManager<TypeSeq,BaseT,ObjectT>::const_iterator
00159 end() const;
00160
00161 private:
00162
00164 std::vector< Teuchos::RCP<BaseT> > objects;
00165
00166 };
00167
00168 }
00169
00170
00171 #include "Sacado_TemplateManagerImp.hpp"
00172
00173
00174 #include "Sacado_TemplateIterator.hpp"
00175
00176 #endif