3#ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4#define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
37 template <
class Traits>
41 static const unsigned int dimension = Traits::dimension;
42 typedef typename Traits::Key Key;
43 typedef typename Traits::Object Object;
44 typedef typename Traits::Factory Factory;
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 ); }
112 static TopologySingletonFactory &instance ()
114 static TopologySingletonFactory instance;
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;
122 TopologySingletonFactory () =
default;
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 ) );
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:280
decltype(auto) apply(F &&f, ArgTuple &&args)
Apply function with arguments given as tuple.
Definition: apply.hh:46
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:14
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:39
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:47
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:54
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:60
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 * >
statically create objects
Definition: topologyfactory.hh:96
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:88
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:103
A unique label for each type of element that can occur in a grid.