summaryrefslogtreecommitdiff
path: root/core/ephermal_checkpoint.hpp
blob: 1ca59e492d503a26f76df8bf712c0546b673b723 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// like Checkpoint, but memory-backed instead of file-backed and only
// storing the last time/value-paiir -> NO ACTUAL CHECKPOINTS
#ifndef kR1Z42gIzRShmbO3sKvSk0HIEo
#define kR1Z42gIzRShmbO3sKvSk0HIEo

#include <boost/static_assert.hpp>

#include "array.hpp"
#include "string_helpers.hpp"
#include "simlimits.hpp"
#include "template_helpers.hpp"
#include "time.hpp"

template<typename T, uint32_t size>
class EphermalCheckpoint {
public:
  typedef uint32_t ptr_t;

  EphermalCheckpoint(string name, const T initialValue);

  // read access
  inline Time getTime (const Time t, const ptr_t i);
  inline T    getValue(const Time t, const ptr_t i);
  inline Time getTime (const Time t); // only with size == 1
  inline T    getValue(const Time t); // only with size == 1

  // write access
  inline void set(const Time t, const ptr_t i, const T val);
  inline void set(const Time t, const T val); // only with size == 1

  void sync() const {};

  // memory backed data; they store for each element the ...
  Array<T, size> content;  // ... last known content
  Array<Time, size> times; // ... associated time

private:
  EphermalCheckpoint();
};

template<typename T, uint32_t size>
inline void EphermalCheckpoint<T, size>::set(const Time t, const ptr_t i, const T val) {
  times.set(i, t);
  content.set(i, val);
}

template<typename T, uint32_t size>
inline void EphermalCheckpoint<T, size>::set(const Time t, const T val) {
  BOOST_STATIC_ASSERT(size == 1);
  setValue(t, 0, val);
}

template<typename T, uint32_t size>
inline Time EphermalCheckpoint<T, size>::getTime(const Time t, const ptr_t i) {
  return times.get(i);
}

template<typename T, uint32_t size>
inline Time EphermalCheckpoint<T, size>::getTime(const Time t) {
  BOOST_STATIC_ASSERT(size == 1);
  return getTime(t, 0);
}

template<typename T, uint32_t size>
inline T EphermalCheckpoint<T, size>::getValue(const Time t, const ptr_t i) {
  return content.get(i);
}

template<typename T, uint32_t size>
inline T EphermalCheckpoint<T, size>::getValue(const Time t) {
  BOOST_STATIC_ASSERT(size == 1);
  return getValue(t, 0);
}

template<typename T, uint32_t size>
EphermalCheckpoint<T, size>::EphermalCheckpoint(string name, const T initialValue) {
  for (ptr_t i=0; i<size; i++) {
    content.set(i, initialValue);
    times.set(i, 0);
  }
}

#endif // kR1Z42gIzRShmbO3sKvSk0HIEo
contact: Jan Huwald // Impressum