3 #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4 #define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
9 #include <dune/common/array.hh>
10 #include <dune/common/nullptr.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>
53 static Object *
create(
const Key &key)
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 >
94 static Object *
create (
const Key &key )
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 >
148 Object *getObject (
const Key &key )
150 Object *&
object = find(Topology::id,key);
152 object = Factory::template create< Topology >( key );
160 #endif // #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
static const unsigned int dimension
Definition: topologyfactory.hh:39
unsigned int id() const
Return the topology id the type.
Definition: type.hh:326
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:36
Factory::Key Key
Definition: topologyfactory.hh:83
Definition: affinegeometry.hh:18
static void apply(const unsigned int topologyId)
Definition: topologytypes.hh:320
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:101
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:53
Traits::Factory Factory
Definition: topologyfactory.hh:42
const Factory::Object Object
Definition: topologyfactory.hh:84
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:94
Traits::Object Object
Definition: topologyfactory.hh:41
A unique label for each type of element that can occur in a grid.
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:80
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:24
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:45
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:87
Traits::Key Key
Definition: topologyfactory.hh:40
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:58