3 #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4 #define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
9 #include <dune/common/fvector.hh>
34 template <
class Traits>
38 static const unsigned int dimension = Traits::dimension;
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>
81 static const unsigned int dimension = Factory::dimension;
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 ];
124 Factory::release(
object );
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 );
142 object = Factory::create( gt, 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
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:79
A unique label for each type of element that can occur in a grid.
Traits::Object Object
Definition: topologyfactory.hh:40
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:35
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:57
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:100
static const unsigned int dimension
Definition: topologyfactory.hh:38
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:52
static void apply(const unsigned int topologyId)
Definition: topologytypes.hh:321
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:44
Traits::Factory Factory
Definition: topologyfactory.hh:41
unsigned int id() const
Return the topology id the type.
Definition: type.hh:327
const Factory::Object Object
Definition: topologyfactory.hh:83
Factory::Key Key
Definition: topologyfactory.hh:82
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:93
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:24
Traits::Key Key
Definition: topologyfactory.hh:39
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:86
static const unsigned int dimension
Definition: topologyfactory.hh:81