summaryrefslogtreecommitdiff
path: root/src/nodecache.h
diff options
context:
space:
mode:
authorMarius Kintel <kintel@sim.no>2010-03-02 18:22:31 (GMT)
committerMarius Kintel <marius@kintel.net>2010-10-31 00:42:34 (GMT)
commit393c5a19fedfa4f97ca939fbcf52c2ccab1cde6a (patch)
treefbcb75d32e8763aac3f0ad28528936a0ec11930b /src/nodecache.h
parent746159d1838e895e80725cdc892f7bef85feb1af (diff)
Committed current version of visitor refactoring
Diffstat (limited to 'src/nodecache.h')
-rw-r--r--src/nodecache.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/nodecache.h b/src/nodecache.h
new file mode 100644
index 0000000..c5a5524
--- /dev/null
+++ b/src/nodecache.h
@@ -0,0 +1,33 @@
+#ifndef NODECACHE_H_
+#define NODECACHE_H_
+
+#include <vector>
+#include "node.h"
+
+template <class T>
+class NodeCache
+{
+public:
+ NodeCache() { }
+ virtual ~NodeCache() { }
+
+ const T & operator[](const AbstractNode &node) const {
+ if (this->cache.size() > node.index()) return this->cache[node.index()];
+ else return nullvalue;
+ }
+
+ void insert(const class AbstractNode &node, const T & value) {
+ 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;
+ }
+
+private:
+ std::vector<T> cache;
+ T nullvalue;
+};
+
+#endif
contact: Jan Huwald // Impressum