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
......@@ -65,14 +65,33 @@ void dataCacheDouble::resize() {
//dataCacheMap members
dataCacheDouble &dataCacheMap::get(const function *f, dataCacheDouble *caller)
{
dataCacheDouble *&r= _cacheDoubleMap[f];
if(r==NULL)
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)
r = new dataCacheDouble(this, const_cast<function*>(f));
if(caller)
if (caller)
r->addMeAsDependencyOf(caller);
return *r;
}
dataCacheDouble &dataCacheMap::substitute(const function *f)
{
dataCacheDouble *&r= _cacheDoubleMap[f];
r = new dataCacheDouble(this, const_cast<function*>(f));
return *r;
}
dataCacheMap::~dataCacheMap()
{
for (std::set<dataCacheDouble*>::iterator it = _toDelete.begin();
......@@ -333,6 +352,9 @@ void dataCacheMap::setNbEvaluationPoints(int nbEvaluationPoints) {
(*it)->resize();
(*it)->_valid = false;
}
for(std::list<dataCacheMap*>::iterator it = _children.begin(); it!= _children.end(); it++) {
(*it)->setNbEvaluationPoints(nbEvaluationPoints);
}
}
//functionC
......
......@@ -4,6 +4,7 @@
#include "fullMatrix.h"
#include <map>
#include <set>
#include <list>
#include <string>
#include <vector>
class dataCacheMap;
......@@ -143,10 +144,9 @@ public :
// more explanation at the head of this file
class dataCacheMap {
friend class dataCacheDouble;
private:
dataCacheMap *_parent;
std::list<dataCacheMap*> _children;
int _nbEvaluationPoints;
// keep track of the current element and all the dataCaches that
// depend on it
std::map<const function*, dataCacheDouble*> _cacheDoubleMap;
std::set<dataCacheDouble*> _toDelete;
std::set<dataCacheDouble*> _toResize;
......@@ -165,14 +165,24 @@ class dataCacheMap {
}
public:
dataCacheDouble &get(const function *f, dataCacheDouble *caller=0);
dataCacheDouble &substitute(const function *f);
inline void setElement(MElement *element) {
_element=element;
for(std::set<dataCacheDouble*>::iterator it = _toInvalidateOnElement.begin(); it!= _toInvalidateOnElement.end(); it++) {
(*it)->_valid=false;
}
for(std::list<dataCacheMap*>::iterator it = _children.begin(); it!= _children.end(); it++) {
(*it)->setElement(element);
}
}
inline MElement *getElement() {return _element;}
dataCacheMap(){
dataCacheMap() {
_nbEvaluationPoints = 0;
_parent=NULL;
}
dataCacheMap(dataCacheMap *parent) {
_parent = parent;
_parent->_children.push_back(this);
_nbEvaluationPoints = 0;
}
void setNbEvaluationPoints(int nbEvaluationPoints);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment