diff options
Diffstat (limited to 'util/rblog.h')
-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 |