Go to the documentation of this file.
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 >
56 return Factory::template createObject< Topology >( key );
64 template<
class Topology >
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 >
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 >
140 auto &
object = find( Topology::id, key );
142 object.reset( Factory::template create< Topology >( key ) );
151 #endif // #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
static const unsigned int dimension
Definition: topologyfactory.hh:83
A unique label for each type of element that can occur in a grid.
const typedef Factory::Object Object
Definition: topologyfactory.hh:85
static const unsigned int dimension
Definition: topologyfactory.hh:41
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:81
Factory::Key Key
Definition: topologyfactory.hh:84
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:47
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:278
Traits::Factory Factory
Definition: topologyfactory.hh:44
Traits::Object Object
Definition: topologyfactory.hh:43
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:60
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:88
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:54
Definition: affinegeometry.hh:18
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:103
Traits::Key Key
Definition: topologyfactory.hh:42
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:38
constexpr unsigned int id() const
Return the topology id of the type.
Definition: type.hh:649