3 #ifndef DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
4 #define DUNE_GEOMETRY_TOPOLOGYFACTORY_HH
10 #include <dune/geometry/genericgeometry/topologytypes.hh>
34 template <
class Traits>
38 static const unsigned int dimension = Traits::dimension;
39 typedef typename Traits::Key Key;
40 typedef typename Traits::Object Object;
41 typedef typename Traits::Factory Factory;
47 GenericGeometry::IfTopology< Maker, dimension >::apply(
gt.id(), key,
object );
51 template <
class Topology>
52 static Object *
create(
const Key &key)
54 return Factory::template createObject<Topology> ( key );
63 template<
class Topology >
66 static void apply (
const Key &key, Object *&
object )
68 object = create<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<
class Topology >
93 static Object *
create (
const Key &key )
96 "Topology with incompatible dimension used" );
97 return instance().template getObject< Topology >( key );
109 static const unsigned int numTopologies = (1 << dimension);
110 typedef FieldVector< Object *, numTopologies > Array;
111 typedef std::map< Key, Array > Storage;
113 TopologySingletonFactory ()
115 ~TopologySingletonFactory ()
117 const typename Storage::iterator end = storage_.end();
118 for(
typename Storage::iterator it = storage_.begin(); it != end; ++it )
120 for(
unsigned int topologyId = 0; topologyId < numTopologies; ++topologyId )
122 Object *&
object = it->second[ topologyId ];
124 Factory::release(
object );
130 Object *&find(
const unsigned int topologyId,
const Key &key )
132 typename Storage::iterator it = storage_.find( key );
133 if( it == storage_.end() )
134 it = storage_.insert( std::make_pair( key, Array( 0 ) ) ).first;
135 return it->second[ topologyId ];
140 Object *&
object = find(
gt.id(), key );
142 object = Factory::create(
gt, key );
146 template<
class Topology >
147 Object *getObject (
const Key &key )
149 Object *&
object = find(Topology::id,key);
151 object = Factory::template create< Topology >( key );
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define dune_static_assert(COND, MSG)
Helper template so that compilation fails if condition is not true.
Definition: static_assert.hh:79
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:132
Dune namespace.
Definition: alignment.hh:14
Provide a factory over the generic topologies.
Definition: topologyfactory.hh:36
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:57
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:44
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:52
A wrapper for a TopologyFactory providing singleton storage. Same usage as TopologyFactory but with e...
Definition: topologyfactory.hh:80
static Object * create(const Key &key)
statically create objects
Definition: topologyfactory.hh:93
static void release(Object *object)
release the object returned by the create methods
Definition: topologyfactory.hh:100
static Object * create(const Dune::GeometryType >, const Key &key)
dynamically create objects
Definition: topologyfactory.hh:86
A unique label for each type of element that can occur in a grid.