Skip to content
Snippets Groups Projects
Commit 721f0d79 authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

add dataCacheMap::parent

parent ea7e9b15
No related branches found
No related tags found
No related merge requests found
...@@ -66,6 +66,18 @@ void dataCacheDouble::resize() { ...@@ -66,6 +66,18 @@ void dataCacheDouble::resize() {
dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller) dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller)
{ {
dataCacheDouble *&r = _cacheDoubleMap[f]; dataCacheDouble *&r = _cacheDoubleMap[f];
if (r==NULL && _parent) {
std::map<const function *, dataCacheDouble *>::iterator it = _parent->_cacheDoubleMap.find(f);
if (it != _parent->_cacheDoubleMap.end()) {
r = it->second;
for (std::set<dataCacheDouble*>::iterator dep = r->_iDependOn.begin(); dep != r->_iDependOn.end(); dep++) {
if (&(*dep)->_cacheMap == this) {
r = NULL;
break;
}
}
}
}
if (r==NULL) if (r==NULL)
r = new dataCacheDouble(this, const_cast<function*>(f)); r = new dataCacheDouble(this, const_cast<function*>(f));
if (caller) if (caller)
...@@ -73,6 +85,13 @@ dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller) ...@@ -73,6 +85,13 @@ dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller)
return *r; return *r;
} }
dataCacheDouble &dataCacheMap::substitute(const function *f)
{
dataCacheDouble *&r= _cacheDoubleMap[f];
r = new dataCacheDouble(this, const_cast<function*>(f));
return *r;
}
dataCacheMap::~dataCacheMap() dataCacheMap::~dataCacheMap()
{ {
for (std::set<dataCacheDouble*>::iterator it = _toDelete.begin(); for (std::set<dataCacheDouble*>::iterator it = _toDelete.begin();
...@@ -333,6 +352,9 @@ void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) { ...@@ -333,6 +352,9 @@ void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) {
(*it)->resize(); (*it)->resize();
(*it)->_valid = false; (*it)->_valid = false;
} }
for(std::list<dataCacheMap*>::iterator it = _children.begin(); it!= _children.end(); it++) {
(*it)->setNbEvaluationPoints(nbEvaluationPoints);
}
} }
//functionC //functionC
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "fullMatrix.h" #include "fullMatrix.h"
#include <map> #include <map>
#include <set> #include <set>
#include <list>
#include <string> #include <string>
#include <vector> #include <vector>
class dataCacheMap; class dataCacheMap;
...@@ -143,10 +144,9 @@ public : ...@@ -143,10 +144,9 @@ public :
// more explanation at the head of this file // more explanation at the head of this file
class dataCacheMap { class dataCacheMap {
friend class dataCacheDouble; friend class dataCacheDouble;
private: dataCacheMap *_parent;
std::list<dataCacheMap*> _children;
int _nbEvaluationPoints; int _nbEvaluationPoints;
// keep track of the current element and all the dataCaches that
// depend on it
std::map<const function*, dataCacheDouble*> _cacheDoubleMap; std::map<const function*, dataCacheDouble*> _cacheDoubleMap;
std::set<dataCacheDouble*> _toDelete; std::set<dataCacheDouble*> _toDelete;
std::set<dataCacheDouble*> _toResize; std::set<dataCacheDouble*> _toResize;
...@@ -165,15 +165,25 @@ class dataCacheMap { ...@@ -165,15 +165,25 @@ class dataCacheMap {
} }
public: public:
dataCacheDouble &get(const function *f, dataCacheDouble *caller=0); dataCacheDouble &get(const function *f, dataCacheDouble *caller=0);
dataCacheDouble &substitute(const function *f);
inline void setElement(MElement *element) { inline void setElement(MElement *element) {
_element=element; _element=element;
for(std::set<dataCacheDouble*>::iterator it = _toInvalidateOnElement.begin(); it!= _toInvalidateOnElement.end(); it++) { for(std::set<dataCacheDouble*>::iterator it = _toInvalidateOnElement.begin(); it!= _toInvalidateOnElement.end(); it++) {
(*it)->_valid=false; (*it)->_valid=false;
} }
for(std::list<dataCacheMap*>::iterator it = _children.begin(); it!= _children.end(); it++) {
(*it)->setElement(element);
}
} }
inline MElement *getElement() {return _element;} inline MElement *getElement() {return _element;}
dataCacheMap() { dataCacheMap() {
_nbEvaluationPoints = 0; _nbEvaluationPoints = 0;
_parent=NULL;
}
dataCacheMap(dataCacheMap *parent) {
_parent = parent;
_parent->_children.push_back(this);
_nbEvaluationPoints = 0;
} }
void setNbEvaluationPoints(int nbEvaluationPoints); void setNbEvaluationPoints(int nbEvaluationPoints);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment