3#ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4#define DUNE_GEOMETRY_TOPOLOGYFACTORY_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;
41 typedef typename Traits::Factory Factory;
46 return Impl::IfTopology< Maker, dimension >::apply(
gt.id(), key );
50 template<
class Topology >
51 static Object *
create (
const Key &key )
53 return Factory::template createObject< Topology >( key );
57 static void release( Object *
object ) {
delete object; }
61 template<
class Topology >
64 static Object *apply (
const Key &key )
66 return create< Topology >( key );
77 template <
class Factory>
80 static const unsigned int dimension = Factory::dimension;
81 typedef typename Factory::Key Key;
82 typedef const typename Factory::Object Object;
87 assert(
gt.id() < numTopologies );
88 return instance().getObject(
gt, key );
91 template<
class Topology >
92 static Object *
create (
const Key &key )
94 static_assert((Topology::dimension == dimension),
95 "Topology with incompatible dimension used");
96 return instance().template getObject< Topology >( key );
108 static const unsigned int numTopologies = (1 << dimension);
109 typedef std::array< Object *, numTopologies > Array;
110 typedef std::map< Key, Array > Storage;
112 TopologySingletonFactory ()
114 ~TopologySingletonFactory ()
116 const typename Storage::iterator end = storage_.end();
117 for(
typename Storage::iterator it = storage_.begin(); it != end; ++it )
119 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
121 Object *&
object = it->second[ topologyId ];
123 Factory::release(
object );
129 Object *&find(
const unsigned int topologyId,
const Key &key )
131 typename Storage::iterator it = storage_.find( key );
132 if( it == storage_.end() )
133 it = storage_.insert( std::make_pair( key, fill_array<Object*, numTopologies>(
nullptr ) ) ).first;
134 return it->second[ topologyId ];
139 Object *&
object = find(
gt.id(), key );
141 object = Factory::create(
gt, key );
145 template<
class Topology >
146 Object *getObject (
const Key &key )
148 Object *&
object = find(Topology::id,key);
150 object = Factory::template create< Topology >( key );
Fallback implementation of the std::array class (a static array)
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:268
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
Dune namespace.
Definition: alignment.hh:11
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:36
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:44
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:51
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:57
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:79
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:85
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:99
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:92
A unique label for each type of element that can occur in a grid.