3 #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH 4 #define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH 11 #include <type_traits> 37 template <
class Traits>
41 static const unsigned int dimension = Traits::dimension;
42 typedef typename Traits::Key
Key;
43 typedef typename Traits::Object
Object;
49 return Impl::IfTopology< Maker, dimension >::apply( gt.
id(), key );
53 template<
class Topology >
54 static Object *
create (
const Key &key )
56 return Factory::template createObject< Topology >( key );
60 static void release( Object *
object ) {
delete object; }
64 template<
class Topology >
67 static Object *apply (
const Key &key )
69 return create< Topology >( key );
80 template <
class Factory>
83 static const unsigned int dimension = Factory::dimension;
84 typedef typename Factory::Key
Key;
85 typedef const typename Factory::Object
Object;
90 assert( gt.
id() < numTopologies );
91 return instance().getObject( gt, key );
95 template<
class Topology >
96 static auto create (
const Key &key )
97 -> std::enable_if_t< Topology::dimension == dimension, Object * >
99 return instance().template getObject< Topology >( key );
109 void operator() ( Object *ptr )
const { Factory::release( ptr ); }
118 static const unsigned int numTopologies = (1 <<
dimension);
119 typedef std::array< std::unique_ptr< Object, ObjectDeleter >, numTopologies > Array;
120 typedef std::map< Key, Array > Storage;
124 std::unique_ptr< Object, ObjectDeleter > &find (
const unsigned int topologyId,
const Key &key )
126 return storage_[ key ][ topologyId ];
131 auto &
object = find( gt.
id(), key );
133 object.reset( Factory::create( gt, key ) );
137 template<
class Topology >
138 Object *getObject (
const Key &key )
140 auto &
object = find( Topology::id, key );
142 object.reset( Factory::template create< Topology >( key ) );
151 #endif // #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:577
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:38
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:103
const Factory::Object Object
Definition: topologyfactory.hh:85
Traits::Factory Factory
Definition: topologyfactory.hh:44
static const unsigned int dimension
Definition: topologyfactory.hh:41
static auto create(const Key &key) -> std::enable_if_t< Topology::dimension==dimension, Object * >
statically create objects
Definition: topologyfactory.hh:96
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:276
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:54
A unique label for each type of element that can occur in a grid.
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:47
Factory::Key Key
Definition: topologyfactory.hh:84
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:81
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:60
Definition: affinegeometry.hh:18
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:88
Traits::Object Object
Definition: topologyfactory.hh:43
Traits::Key Key
Definition: topologyfactory.hh:42