summaryrefslogtreecommitdiff
path: root/src/nodecache.h
blob: c5a5524ce074c77a5e107384bc106ea0b0a7d18e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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