1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_PLATFORM_LOGGING_H_
18#define RESONANCE_AUDIO_PLATFORM_LOGGING_H_
19
20#include <cstdlib>
21
22#include <cassert>
23#include <iostream>
24#include <sstream>
25
26#undef DCHECK
27#undef DCHECK_EQ
28#undef DCHECK_NE
29#undef DCHECK_LE
30#undef DCHECK_LT
31#undef DCHECK_GE
32#undef DCHECK_GT
33#undef CHECK
34#undef CHECK_EQ
35#undef CHECK_NE
36#undef CHECK_LE
37#undef CHECK_LT
38#undef CHECK_GE
39#undef CHECK_GT
40#undef CHECK_NOTNULL
41#undef LOG
42
43namespace vraudio {
44
45// This class is used to disable logging, while still allowing for log messages
46// to contain '<<' expressions.
47class NullLogger {
48 public:
49 std::ostream& GetStream() {
50 static std::ostream kNullStream(nullptr);
51 return kNullStream;
52 }
53};
54
55// If statement prevents unused variable warnings.
56#define DCHECK(expr) \
57 if (false && (expr)) \
58 ; \
59 else \
60 NullLogger().GetStream()
61#define DCHECK_OP(val1, val2, op) DCHECK((val1)op(val2))
62
63#define DCHECK_EQ(val1, val2) DCHECK_OP((val1), (val2), ==)
64#define DCHECK_NE(val1, val2) DCHECK_OP((val1), (val2), !=)
65#define DCHECK_LE(val1, val2) DCHECK_OP((val1), (val2), <=)
66#define DCHECK_LT(val1, val2) DCHECK_OP((val1), (val2), <)
67#define DCHECK_GE(val1, val2) DCHECK_OP((val1), (val2), >=)
68#define DCHECK_GT(val1, val2) DCHECK_OP((val1), (val2), >)
69
70// This class is used to log to std::cerr.
71class FatalLogger {
72 public:
73 FatalLogger(const char* file, int line) {
74 error_string_ << file << ":" << line << ": ";
75 }
76 ~FatalLogger() {
77 const std::string error_string = error_string_.str();
78 std::cerr << error_string << std::endl;
79 abort();
80 }
81 std::ostream& GetStream() { return error_string_; }
82
83 private:
84 std::ostringstream error_string_;
85};
86
87#define CHECK(condition) \
88 !(condition) ? FatalLogger(__FILE__, __LINE__).GetStream() \
89 : NullLogger().GetStream()
90
91#define CHECK_OP(val1, val2, op) CHECK((val1)op(val2))
92
93#define CHECK_EQ(val1, val2) CHECK_OP((val1), (val2), ==)
94#define CHECK_NE(val1, val2) CHECK_OP((val1), (val2), !=)
95#define CHECK_LE(val1, val2) CHECK_OP((val1), (val2), <=)
96#define CHECK_LT(val1, val2) CHECK_OP((val1), (val2), <)
97#define CHECK_GE(val1, val2) CHECK_OP((val1), (val2), >=)
98#define CHECK_GT(val1, val2) CHECK_OP((val1), (val2), >)
99
100// Helper for CHECK_NOTNULL(), using C++11 perfect forwarding.
101template <typename T>
102T CheckNotNull(T&& t) {
103 assert(t != nullptr);
104 return std::forward<T>(t);
105}
106#define CHECK_NOTNULL(val) CheckNotNull(val)
107
108#define LOG(severity) NullLogger().GetStream()
109
110} // namespace vraudio
111
112#endif // RESONANCE_AUDIO_PLATFORM_LOGGING_H_
113

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/base/logging.h