5#ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
6#define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
40 template <
class Traits>
44 static const unsigned int dimension = Traits::dimension;
45 typedef typename Traits::Key
Key;
46 typedef typename Traits::Object
Object;
52 return Impl::toGeometryTypeIdConstant<dimension>(gt, [&](
auto id) {
53 return create<decltype(id)::value>(key);
57 template< GeometryType::Id geometryId >
60 return Factory::template createObject< geometryId >( key );
64 template<
class Topology >
67 return Factory::template createObject< 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 );
94 template< GeometryType::Id geometryId >
96 -> std::enable_if_t< static_cast<GeometryType>(geometryId).dim() ==
dimension,
Object * >
98 return instance().template getObject< geometryId >( key );
102 template<
class Topology >
104 -> std::enable_if_t< Topology::dimension == dimension, Object * >
106 return instance().template getObject< Topology >( key );
116 void operator() (
Object *ptr )
const { Factory::release( ptr ); }
119 static TopologySingletonFactory &instance ()
121 static TopologySingletonFactory instance;
125 static const unsigned int numTopologies = (1 <<
dimension);
126 typedef std::array< std::unique_ptr< Object, ObjectDeleter >, numTopologies > Array;
127 typedef std::map< Key, Array > Storage;
129 TopologySingletonFactory () =
default;
131 std::unique_ptr< Object, ObjectDeleter > &find (
const unsigned int topologyId,
const Key &key )
133 return storage_[ key ][ topologyId ];
138 auto &
object = find( gt.
id(), key );
140 object.reset( Factory::create( gt, key ) );
144 template< GeometryType::Id geometryId >
147 static constexpr GeometryType geometry = geometryId;
148 auto &
object = find( geometry.id(), key );
150 object.reset( Factory::template create< geometry >( key ) );
154 template<
class Topology >
157 auto &
object = find( Topology::id, key );
159 object.reset( Factory::template create< Topology >( key ) );
Helper classes to provide indices for geometrytypes for use in a vector.
A unique label for each type of element that can occur in a grid.
Definition affinegeometry.hh:21
Provide a factory over the generic topologies.
Definition topologyfactory.hh:42
Traits::Factory Factory
Definition topologyfactory.hh:47
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition topologyfactory.hh:50
static const unsigned int dimension
Definition topologyfactory.hh:44
static Object * create(const Key &key)
statically create objects
Definition topologyfactory.hh:58
static void release(Object *object)
release the object returned by the create methods
Definition topologyfactory.hh:71
Traits::Key Key
Definition topologyfactory.hh:45
Traits::Object Object
Definition topologyfactory.hh:46
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition topologyfactory.hh:82
static auto create(const Key &key) -> std::enable_if_t< Topology::dimension==dimension, Object * >
Definition topologyfactory.hh:103
static Object * create(const Dune::GeometryType >, const Key &key)
Definition topologyfactory.hh:88
static void release(Object *object)
release the object returned by the create methods
Definition topologyfactory.hh:110
const Factory::Object Object
Definition topologyfactory.hh:85
Factory::Key Key
Definition topologyfactory.hh:84
static auto create(const Key &key) -> std::enable_if_t< static_cast< GeometryType >(geometryId).dim()==dimension, Object * >
Definition topologyfactory.hh:95
static const unsigned int dimension
Definition topologyfactory.hh:83
Unique label for each type of entities that can occur in DUNE grids.
Definition type.hh:126
constexpr unsigned int id() const
Return the topology id of the type.
Definition type.hh:377