summaryrefslogtreecommitdiff
path: root/src/nodecache.h
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2010-04-12 00:16:36 (GMT)
committerMarius Kintel <marius@kintel.net>2010-10-31 00:42:35 (GMT)
commite8e213b3c9ce0580045ea6e7e86b00ab41d4c58b (patch)
treecb32e67b6334aa1f1dc62aa4a0686a22782e7f77 /src/nodecache.h
parent53a9953b7dc4ab4a366046c91529b32fb6652551 (diff)
Another refactoring session:
o mk_cache_id() obsoleted by removing the node index from the dump o node index output removed from each node and make optional in NodeDumper o The visitors are no longer global, but associated with a tree o Added Tree class to manage node trees and the (now implicit) dump cache o Moved PolySet cache into PolySetRenderer
Diffstat (limited to 'src/nodecache.h')
-rw-r--r--src/nodecache.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/nodecache.h b/src/nodecache.h
index efd5104..ca0bd6c 100644
--- a/src/nodecache.h
+++ b/src/nodecache.h
@@ -2,27 +2,36 @@
#define NODECACHE_H_
#include <vector>
+#include <string>
#include "node.h"
-template <class T>
+/*!
+ Caches values per node based on the node.index().
+ The node index guaranteed to be unique per node tree since the index is reset
+ every time a new tree is generated.
+*/
class NodeCache
{
public:
NodeCache() { }
virtual ~NodeCache() { }
- const T & operator[](const AbstractNode &node) const {
+ bool contains(const AbstractNode &node) const {
+ return !(*this)[node].empty();
+ }
+
+ const std::string & operator[](const AbstractNode &node) const {
if (this->cache.size() > node.index()) return this->cache[node.index()];
- else return nullvalue;
+ else return this->nullvalue;
}
- void insert(const class AbstractNode &node, const T & value) {
+ void insert(const class AbstractNode &node, const std::string & value) {
if (this->cache.size() <= node.index()) this->cache.resize(node.index() + 1);
this->cache[node.index()] = value;
}
void remove(const class AbstractNode &node) {
- if (this->cache.size() > node.index()) this->cache[node.index()] = nullvalue;
+ if (this->cache.size() > node.index()) this->cache[node.index()] = std::string();
}
void clear() {
@@ -30,8 +39,8 @@ public:
}
private:
- std::vector<T> cache;
- T nullvalue;
+ std::vector<std::string> cache;
+ std::string nullvalue;
};
#endif
contact: Jan Huwald // Impressum