3 #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4 #define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
9 #include <dune/common/fvector.hh>
34 template <
class Traits>
39 typedef typename Traits::Key
Key;
40 typedef typename Traits::Object
Object;
51 template <
class Topology>
54 return Factory::template createObject<Topology> ( key );
63 template<
class Topology >
66 static void apply (
const Key &key,
Object *&
object )
68 object = create<Topology>( key );
78 template <
class Factory>
82 typedef typename Factory::Key
Key;
83 typedef const typename Factory::Object
Object;
88 assert( gt.
id() < numTopologies );
89 return instance().getObject( gt, key );
92 template<
class Topology >
95 dune_static_assert( (Topology::dimension ==
dimension),
96 "Topology with incompatible dimension used" );
97 return instance().template getObject< Topology >( key );
109 static const unsigned int numTopologies = (1 <<
dimension);
110 typedef FieldVector< Object *, numTopologies > Array;
111 typedef std::map< Key, Array > Storage;
113 TopologySingletonFactory ()
115 ~TopologySingletonFactory ()
117 const typename Storage::iterator end = storage_.end();
118 for(
typename Storage::iterator it = storage_.begin(); it != end; ++it )
120 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
122 Object *&
object = it->second[ topologyId ];
130 Object *&find(
const unsigned int topologyId,
const Key &key )
132 typename Storage::iterator it = storage_.find( key );
133 if( it == storage_.end() )
134 it = storage_.insert( std::make_pair( key, Array( 0 ) ) ).first;
135 return it->second[ topologyId ];
140 Object *&
object = find( gt.
id(), key );
146 template<
class Topology >
149 Object *&
object = find(Topology::id,key);
151 object = Factory::template create< Topology >( key );
159 #endif // #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH