summaryrefslogtreecommitdiff
path: root/multilog.h
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2018-08-20 21:53:38 +0200
committerTom Smeding <tom.smeding@gmail.com>2018-08-20 21:53:38 +0200
commit1c42efb1b116287949e59370198cad2df465835d (patch)
tree6c191f0a629b23566763827e73071c523f0d3e2b /multilog.h
Initial
Diffstat (limited to 'multilog.h')
-rw-r--r--multilog.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/multilog.h b/multilog.h
new file mode 100644
index 0000000..ba0ff4d
--- /dev/null
+++ b/multilog.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <vector>
+#include <string_view>
+#include <mutex>
+
+using namespace std;
+
+
+// Access is thread-safe
+class MultiLog {
+ struct Item {
+ int id;
+ string line;
+ bool complete = false;
+
+ Item();
+ };
+
+ mutex mut;
+ vector<Item> items;
+
+ // Methods assume mutex is taken.
+ size_t findId(int id);
+ void redrawLine(size_t idx);
+
+public:
+ // Returns id of new item
+ int add(const string_view prefix);
+ void append(int id, const string_view text);
+ void complete(int id);
+};