3#ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4#define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
9#include <dune/common/array.hh>
35 template <
class Traits>
39 static const unsigned int dimension = Traits::dimension;
40 typedef typename Traits::Key
Key;
41 typedef typename Traits::Object
Object;
52 template <
class Topology>
55 return Factory::template createObject<Topology> ( key );
64 template<
class Topology >
67 static void apply (
const Key &key,
Object *&
object )
69 object = create<Topology>( key );
79 template <
class Factory>
82 static const unsigned int dimension = Factory::dimension;
83 typedef typename Factory::Key
Key;
84 typedef const typename Factory::Object
Object;
89 assert( gt.
id() < numTopologies );
90 return instance().getObject( gt, key );
93 template<
class Topology >
96 static_assert((Topology::dimension ==
dimension),
97 "Topology with incompatible dimension used");
98 return instance().template getObject< Topology >( key );
110 static const unsigned int numTopologies = (1 <<
dimension);
111 typedef std::array< Object *, numTopologies > Array;
112 typedef std::map< Key, Array > Storage;
114 TopologySingletonFactory ()
116 ~TopologySingletonFactory ()
118 const typename Storage::iterator end = storage_.end();
119 for(
typename Storage::iterator it = storage_.begin(); it != end; ++it )
121 for(
unsigned int topologyId = 0; topologyId <
numTopologies; ++topologyId )
123 Object *&
object = it->second[ topologyId ];
125 Factory::release(
object );
131 Object *&find(
const unsigned int topologyId,
const Key &key )
133 typename Storage::iterator it = storage_.find( key );
134 if( it == storage_.end() )
135 it = storage_.insert( std::make_pair( key, fill_array<Object*, numTopologies>(
nullptr ) ) ).first;
136 return it->second[ topologyId ];
141 Object *&
object = find( gt.
id(), key );
143 object = Factory::create( gt, key );
147 template<
class Topology >
150 Object *&
object = find(Topology::id,key);
152 object = Factory::template create< Topology >( key );
A unique label for each type of element that can occur in a grid.
Definition affinegeometry.hh:19
unsigned int numTopologies(int dim)
obtain the number of topologies of a given dimension
Definition topologytypes.hh:134
static void apply(const unsigned int topologyId)
Definition topologytypes.hh:320
Provide a factory over the generic topologies.
Definition topologyfactory.hh:37
Traits::Factory Factory
Definition topologyfactory.hh:42
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition topologyfactory.hh:45
static const unsigned int dimension
Definition topologyfactory.hh:39
static Object * create(const Key &key)
statically create objects
Definition topologyfactory.hh:53
static void release(Object *object)
release the object returned by the create methods
Definition topologyfactory.hh:58
Traits::Key Key
Definition topologyfactory.hh:40
Traits::Object Object
Definition topologyfactory.hh:41
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition topologyfactory.hh:81
static Object * create(const Dune::GeometryType >, const Key &key)
Definition topologyfactory.hh:87
static void release(Object *object)
release the object returned by the create methods
Definition topologyfactory.hh:101
const Factory::Object Object
Definition topologyfactory.hh:84
Factory::Key Key
Definition topologyfactory.hh:83
static Object * create(const Key &key)
Definition topologyfactory.hh:94
static const unsigned int dimension
Definition topologyfactory.hh:82
Unique label for each type of entities that can occur in DUNE grids.
Definition type.hh:25
unsigned int id() const
Return the topology id the type.
Definition type.hh:326