summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/benchmark/src/log.h
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/benchmark/src/log.h')
-rw-r--r--3rdparty/benchmark/src/log.h56
1 files changed, 50 insertions, 6 deletions
diff --git a/3rdparty/benchmark/src/log.h b/3rdparty/benchmark/src/log.h
index 3777810e1c9..e965d36194b 100644
--- a/3rdparty/benchmark/src/log.h
+++ b/3rdparty/benchmark/src/log.h
@@ -1,19 +1,63 @@
#ifndef BENCHMARK_LOG_H_
#define BENCHMARK_LOG_H_
+#include <iostream>
#include <ostream>
+#include "benchmark/macros.h"
+
namespace benchmark {
namespace internal {
-int GetLogLevel();
-void SetLogLevel(int level);
+typedef std::basic_ostream<char>&(EndLType)(std::basic_ostream<char>&);
+
+class LogType {
+ friend LogType& GetNullLogInstance();
+ friend LogType& GetErrorLogInstance();
+
+ // FIXME: Add locking to output.
+ template <class Tp>
+ friend LogType& operator<<(LogType&, Tp const&);
+ friend LogType& operator<<(LogType&, EndLType*);
+
+ private:
+ LogType(std::ostream* out) : out_(out) {}
+ std::ostream* out_;
+ BENCHMARK_DISALLOW_COPY_AND_ASSIGN(LogType);
+};
-std::ostream& GetNullLogInstance();
-std::ostream& GetErrorLogInstance();
+template <class Tp>
+LogType& operator<<(LogType& log, Tp const& value) {
+ if (log.out_) {
+ *log.out_ << value;
+ }
+ return log;
+}
+
+inline LogType& operator<<(LogType& log, EndLType* m) {
+ if (log.out_) {
+ *log.out_ << m;
+ }
+ return log;
+}
+
+inline int& LogLevel() {
+ static int log_level = 0;
+ return log_level;
+}
+
+inline LogType& GetNullLogInstance() {
+ static LogType log(nullptr);
+ return log;
+}
+
+inline LogType& GetErrorLogInstance() {
+ static LogType log(&std::clog);
+ return log;
+}
-inline std::ostream& GetLogInstanceForLevel(int level) {
- if (level <= GetLogLevel()) {
+inline LogType& GetLogInstanceForLevel(int level) {
+ if (level <= LogLevel()) {
return GetErrorLogInstance();
}
return GetNullLogInstance();