3#ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4#define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
38 template <
class Traits>
42 static const unsigned int dimension = Traits::dimension;
43 typedef typename Traits::Key
Key;
44 typedef typename Traits::Object
Object;
50 return Impl::toGeometryTypeIdConstant<dimension>(gt, [&](
auto id) {
51 return create<decltype(id)::value>(key);
55 template< GeometryType::Id geometryId >
58 return Factory::template createObject< geometryId >( key );
62 template<
class Topology >
65 return Factory::template createObject< Topology >( key );
78 template <
class Factory>
81 static const unsigned int dimension = Factory::dimension;
82 typedef typename Factory::Key
Key;
83 typedef const typename Factory::Object
Object;
88 assert( gt.
id() < numTopologies );
89 return instance().getObject( gt, key );
92 template< GeometryType::Id geometryId >
94 -> std::enable_if_t< static_cast<GeometryType>(geometryId).dim() ==
dimension,
Object * >
96 return instance().template getObject< geometryId >( key );
100 template<
class Topology >
102 -> std::enable_if_t< Topology::dimension == dimension, Object * >
104 return instance().template getObject< Topology >( key );
114 void operator() (
Object *ptr )
const { Factory::release( ptr ); }
117 static TopologySingletonFactory &instance ()
119 static TopologySingletonFactory instance;
123 static const unsigned int numTopologies = (1 <<
dimension);
124 typedef std::array< std::unique_ptr< Object, ObjectDeleter >, numTopologies > Array;
125 typedef std::map< Key, Array > Storage;
127 TopologySingletonFactory () =
default;
129 std::unique_ptr< Object, ObjectDeleter > &find (
const unsigned int topologyId,
const Key &key )
131 return storage_[ key ][ topologyId ];
136 auto &
object = find( gt.
id(), key );
138 object.reset( Factory::create( gt, key ) );
142 template< GeometryType::Id geometryId >
145 static constexpr GeometryType geometry = geometryId;
146 auto &
object = find( geometry.id(), key );
148 object.reset( Factory::template create< geometry >( key ) );
152 template<
class Topology >
155 auto &
object = find( Topology::id, key );
157 object.reset( Factory::template create< Topology >( key ) );
A unique label for each type of element that can occur in a grid.
Helper classes to provide indices for geometrytypes for use in a vector.
Definition: affinegeometry.hh:19
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:40
Traits::Factory Factory
Definition: topologyfactory.hh:45
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:48
static const unsigned int dimension
Definition: topologyfactory.hh:42
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:56
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:69
Traits::Key Key
Definition: topologyfactory.hh:43
Traits::Object Object
Definition: topologyfactory.hh:44
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:80
static auto create(const Key &key) -> std::enable_if_t< Topology::dimension==dimension, Object * >
statically create objects
Definition: topologyfactory.hh:101
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:86
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:108
const Factory::Object Object
Definition: topologyfactory.hh:83
Factory::Key Key
Definition: topologyfactory.hh:82
static auto create(const Key &key) -> std::enable_if_t< static_cast< GeometryType >(geometryId).dim()==dimension, Object * >
statically create objects
Definition: topologyfactory.hh:93
static const unsigned int dimension
Definition: topologyfactory.hh:81
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:374