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;
45 typedef typename Traits::Factory Factory;
50 return Impl::toGeometryTypeIdConstant<dimension>(
gt, [&](
auto id) {
51 return create<decltype(id)::value>(key);
55 template< GeometryType::Id geometryId >
56 static Object *
create (
const Key &key )
58 return Factory::template createObject< geometryId >( key );
62 template<
class Topology >
63 static Object *
create (
const Key &key )
65 return Factory::template createObject< Topology >( key );
69 static void release( Object *
object ) {
delete object; }
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 >
93 static auto create (
const Key &key )
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 >
143 Object *getObject (
const Key &key )
146 auto &
object = find( geometry.id(), key );
148 object.reset( Factory::template create< geometry >( key ) );
152 template<
class Topology >
153 Object *getObject (
const Key &key )
155 auto &
object = find( Topology::id, key );
157 object.reset( Factory::template create< Topology >( key ) );
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:156
Dune namespace.
Definition: alignedallocator.hh:11
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:40
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:48
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
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
static auto create(const Key &key) -> std::enable_if_t< static_cast< GeometryType >(geometryId).dim()==dimension, Object * >
statically create objects
Definition: topologyfactory.hh:93
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.