From 9bf644e65d5bb51a161b22da94f9718af29d02f1 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 11 Sep 2012 18:16:12 +0200 Subject: Added ring buffer log class. --- util/rblog.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 util/rblog.h diff --git a/util/rblog.h b/util/rblog.h new file mode 100644 index 0000000..5914239 --- /dev/null +++ b/util/rblog.h @@ -0,0 +1,39 @@ +#ifndef RBLOG_H +#define RBLOG_H + +#include +#include + +template +class RBLog { + private: + static const uint32_t num_entries = E; + static const uint32_t num_arguments = A; + + struct entry_t { + uint32_t timestamp; + const char* string; + uint32_t arguments[num_arguments]; + }; + + entry_t entries[num_entries]; + uint32_t index; + + public: + RBLog() : index(0) { + for(entry_t& entry : entries) { + entry = {0, 0}; + } + } + + template + void log(const char* s, Arguments... a) { + entries[index] = {Time::time(), s, {a...}}; + + if(++index >= num_entries) { + index = 0; + } + } +}; + +#endif -- cgit v1.2.3