aboutsummaryrefslogtreecommitdiff
path: root/computer-network-experiment/Output.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-07 23:24:43 +0800
committercrupest <crupest@outlook.com>2021-06-07 23:24:43 +0800
commit2dd9b0e926ed97b64f0e6c2b6c071feaab9c47a0 (patch)
tree6a87c790fc03e3e95f14de9a59257aec66ba65b7 /computer-network-experiment/Output.h
parent1dd5c424e198a59b3572352fd973fe34dad225d1 (diff)
downloadlife-2dd9b0e926ed97b64f0e6c2b6c071feaab9c47a0.tar.gz
life-2dd9b0e926ed97b64f0e6c2b6c071feaab9c47a0.tar.bz2
life-2dd9b0e926ed97b64f0e6c2b6c071feaab9c47a0.zip
...
Diffstat (limited to 'computer-network-experiment/Output.h')
-rw-r--r--computer-network-experiment/Output.h67
1 files changed, 0 insertions, 67 deletions
diff --git a/computer-network-experiment/Output.h b/computer-network-experiment/Output.h
deleted file mode 100644
index 689c3d3..0000000
--- a/computer-network-experiment/Output.h
+++ /dev/null
@@ -1,67 +0,0 @@
-#pragma once
-#include "Common.h"
-#include "StringUtil.hpp"
-
-#include <fmt/format.h>
-#include <folly/CancellationToken.h>
-#include <folly/MPMCPipeline.h>
-#include <folly/MPMCQueue.h>
-
-#include <iostream>
-#include <mutex>
-#include <thread>
-
-enum class OutputType { Normal, Error };
-enum class OutputColor { Normal, Green, Red, Yellow };
-
-struct Output {
- Output() = default;
- Output(String message, OutputType type = OutputType::Normal)
- : message(std::move(message)), type(type),
- color(type == OutputType::Error ? OutputColor::Red
- : OutputColor::Normal) {}
-
- Output(String message, OutputColor color)
- : message(std::move(message)), type(OutputType::Normal), color(color) {}
-
- Output(String message, OutputType type, OutputColor color)
- : message(std::move(message)), type(type), color(color) {}
-
- CRU_DEFAULT_COPY(Output)
- CRU_DEFAULT_MOVE(Output)
- ~Output() = default;
-
- String message;
- OutputType type;
- OutputColor color;
-};
-
-extern folly::MPMCQueue<Output> output_queue;
-
-inline void SendOutput(Output output) {
- output_queue.blockingWrite(std::move(output));
-}
-
-inline void SendOutput(String output) { SendOutput(Output{std::move(output)}); }
-
-template <typename... Args> void SendOutput(StringView format, Args &&...args) {
- output_queue.blockingWrite(fmt::format(format, std::forward<Args>(args)...));
-}
-
-template <typename... Args>
-void SendOutput(OutputType type, StringView format, Args &&...args) {
- output_queue.blockingWrite(
- Output{fmt::format(format, std::forward<Args>(args)...), type});
-}
-
-template <typename... Args>
-void SendOutput(OutputColor color, StringView format, Args &&...args) {
- output_queue.blockingWrite(
- Output{fmt::format(format, std::forward<Args>(args)...), color});
-}
-
-void OutputThread();
-
-void SignalAndWaitForOutputThreadStop();
-
-std::lock_guard<std::mutex> BlockOutputThread();