Dune Core Modules (2.4.1)

memory.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ALU3DGRIDMEMORY_HH
4#define DUNE_ALU3DGRIDMEMORY_HH
5
6#include <cassert>
7#include <cstdlib>
8#include <vector>
9
10namespace ALUGridSpace
11{
12 template<class T, int length>
13 class ALUGridFiniteStack ;
14}
15
16namespace Dune {
17
19 template <class Object>
21 {
22 enum { maxStackObjects = 256 };
23 typedef ALUGridSpace :: ALUGridFiniteStack< Object* , maxStackObjects > StackType ;
24 StackType objStack_ ;
25
27
28 StackType& objStack() { return objStack_ ; }
29
30 public:
31 typedef Object ObjectType;
32
35
38 : objStack_( org.objStack_ )
39 {}
40
43
45 template <class FactoryType>
46 ObjectType * getObject(const FactoryType &factory, int level);
47
49 template <class FactoryType, class EntityImp>
50 inline ObjectType * getEntityObject(const FactoryType& factory, int level , EntityImp * fakePtr )
51 {
52 if( objStack().empty() )
53 {
54 return ( new ObjectType(EntityImp(factory,level) ));
55 }
56 else
57 {
58 return stackObject();
59 }
60 }
61
63 ObjectType * getEmptyObject ();
64
66 ObjectType * getObjectCopy(const ObjectType & org);
67
69 void freeObject (ObjectType * obj);
70
71 protected:
72 inline ObjectType * stackObject()
73 {
74 assert( ! objStack().empty() );
75 // finite stack does also return object on pop
76 return objStack().pop();
77 }
78
79 };
80
81
82 //************************************************************************
83 //
84 // ALUMemoryProvider implementation
85 //
86 //************************************************************************
87 template <class Object> template <class FactoryType>
88 inline typename ALUMemoryProvider<Object>::ObjectType *
90 (const FactoryType &factory, int level )
91 {
92 if( objStack().empty() )
93 {
94 return ( new Object (factory, level) );
95 }
96 else
97 {
98 return stackObject();
99 }
100 }
101
102 template <class Object>
103 inline typename ALUMemoryProvider<Object>::ObjectType *
105 (const ObjectType & org )
106 {
107 if( objStack().empty() )
108 {
109 return ( new Object (org) );
110 }
111 else
112 {
113 return stackObject();
114 }
115 }
116
117 template <class Object>
118 inline typename ALUMemoryProvider<Object>::ObjectType *
120 {
121 if( objStack().empty() )
122 {
123 return new Object () ;
124 }
125 else
126 {
127 return stackObject();
128 }
129 }
130
131 template <class Object>
133 {
134 StackType& objStk = objStack_;
135 while ( ! objStk.empty() )
136 {
137 ObjectType * obj = objStk.pop();
138 delete obj;
139 }
140 }
141
142 template <class Object>
144 {
145 StackType& stk = objStack();
146 if( stk.full() )
147 delete obj;
148 else
149 stk.push( obj );
150 }
151
152#undef USE_FINITE_STACK
153
154} // end namespace Dune
155
156#endif
organize the memory management for entitys used by the NeighborIterator
Definition: memory.hh:21
ObjectType * getObjectCopy(const ObjectType &org)
i.e. return pointer to Entity
Definition: memory.hh:105
ObjectType * getObject(const FactoryType &factory, int level)
i.e. return pointer to Entity
Definition: memory.hh:90
void freeObject(ObjectType *obj)
free, move element to stack, returns NULL
Definition: memory.hh:143
~ALUMemoryProvider()
call deleteEntity
Definition: memory.hh:132
ObjectType * getEntityObject(const FactoryType &factory, int level, EntityImp *fakePtr)
i.e. return pointer to Entity
Definition: memory.hh:50
ALUMemoryProvider(const ALUMemoryProvider< Object > &org)
do not copy pointers
Definition: memory.hh:37
ALUMemoryProvider()
default constructor
Definition: memory.hh:34
ObjectType * getEmptyObject()
return object, if created default constructor is used
Definition: memory.hh:119
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)