diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-09-11 18:16:12 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-09-11 18:16:12 +0200 |
commit | 9bf644e65d5bb51a161b22da94f9718af29d02f1 (patch) | |
tree | 929f0bbb35e9e4d875aae8b643a7bbec2316858d | |
parent | 79842b0d5c5f117659dbaddb6d4dc70cbe46d844 (diff) |
Added ring buffer log class.
-rw-r--r-- | util/rblog.h | 39 |
1 files changed, 39 insertions, 0 deletions
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 <stdint.h> +#include <os/time.h> + +template <uint32_t E, uint32_t A = 0> +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 <typename... Arguments> + void log(const char* s, Arguments... a) { + entries[index] = {Time::time(), s, {a...}}; + + if(++index >= num_entries) { + index = 0; + } + } +}; + +#endif |