diff options
author | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
commit | 420d2ef464d4a741028e132e662d5626806a41f5 (patch) | |
tree | 1aca6eb512e4ed0fb5f3c10c528cb998b6ffd695 /core/ephermal_checkpoint.hpp |
Diffstat (limited to 'core/ephermal_checkpoint.hpp')
-rw-r--r-- | core/ephermal_checkpoint.hpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/core/ephermal_checkpoint.hpp b/core/ephermal_checkpoint.hpp new file mode 100644 index 0000000..1ca59e4 --- /dev/null +++ b/core/ephermal_checkpoint.hpp @@ -0,0 +1,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 |