3 #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH 4 #define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH 9 #include <dune/common/array.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;
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;
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 );
109 typedef std::array< Object *, numTopologies > Array;
110 typedef std::map< Key, Array > Storage;
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 );
158 #endif // #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:267
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:44
static auto apply(unsigned int topologyId, Args &&... args)
Definition: type.hh:233
const Factory::Object Object
Definition: topologyfactory.hh:82
Definition: affinegeometry.hh:18
static unsigned int numTopologies(int dim) noexcept
obtain the number of topologies of a given dimension
Definition: type.hh:93
A unique label for each type of element that can occur in a grid.
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:92
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:99
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:35
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:51
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:78
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:57
Traits::Factory Factory
Definition: topologyfactory.hh:41
static const unsigned int dimension
Definition: topologyfactory.hh:38
Factory::Key Key
Definition: topologyfactory.hh:81
unsigned int id() const
Return the topology id the type.
Definition: type.hh:570
Traits::Key Key
Definition: topologyfactory.hh:39
Traits::Object Object
Definition: topologyfactory.hh:40