00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef KUDU_CLIENT_STUBS_H
00018 #define KUDU_CLIENT_STUBS_H
00019
00020 #include <stdlib.h>
00021
00022 #include <iostream>
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef PREDICT_FALSE
00031 #if defined(__GNUC__)
00032 #define PREDICT_FALSE(x) (__builtin_expect(x, 0))
00033 #else
00034 #define PREDICT_FALSE(x) x
00035 #endif
00036 #endif
00037 #ifndef PREDICT_TRUE
00038 #if defined(__GNUC__)
00039 #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
00040 #else
00041 #define PREDICT_TRUE(x) x
00042 #endif
00043 #endif
00044
00045
00046
00047
00048
00049 #ifndef WARN_UNUSED_RESULT
00050 #if defined(__GNUC__)
00051 #define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
00052 #else
00053 #define WARN_UNUSED_RESULT
00054 #endif
00055 #endif
00056
00057 #if (defined(__GNUC__) || defined(__APPLE__)) && !defined(SWIG)
00058 #undef ATTRIBUTE_UNUSED
00059 #define ATTRIBUTE_UNUSED __attribute__ ((unused))
00060 #else
00061 #ifndef ATTRIBUTE_UNUSED
00062 #define ATTRIBUTE_UNUSED
00063 #endif
00064 #endif
00065
00066
00067
00068
00069 #ifndef ATTRIBUTE_DEPRECATED
00070 #if defined(__clang__) || \
00071 (defined(COMPILER_GCC) && \
00072 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 30200)
00073 #define ATTRIBUTE_DEPRECATED(msg) __attribute__ ((deprecated (msg) ))
00074 #else
00075 #define ATTRIBUTE_DEPRECATED(msg)
00076 #endif
00077 #endif // #ifndef ATTRIBUTE_DEPRECATED
00078
00079 #ifndef COMPILE_ASSERT
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 template <bool>
00096 struct StubsCompileAssert {
00097 };
00098
00099 #define COMPILE_ASSERT(expr, msg) \
00100 typedef StubsCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] ATTRIBUTE_UNUSED // NOLINT(*)
00101 #endif
00102
00103
00104
00105
00106
00107 #ifndef OVERRIDE
00108 #if defined(COMPILER_MSVC)
00109 #define OVERRIDE override
00110 #elif defined(__clang__)
00111 #define OVERRIDE override
00112 #elif defined(COMPILER_GCC) && __cplusplus >= 201103 && \
00113 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700
00114
00115 #define OVERRIDE override
00116 #else
00117 #define OVERRIDE
00118 #endif
00119 #endif
00120
00121 #ifndef DISALLOW_COPY_AND_ASSIGN
00122 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
00123 TypeName(const TypeName&); \
00124 void operator=(const TypeName&)
00125 #endif
00126
00127 #ifndef FRIEND_TEST
00128 #define FRIEND_TEST(test_case_name, test_name) \
00129 friend class test_case_name##_##test_name##_Test
00130 #endif
00131
00132
00133
00134
00135
00136
00137 #define KUDU_DCHECK(condition) while (false) kudu::internal_logging::NullLog()
00138 #define KUDU_DCHECK_EQ(val1, val2) while (false) kudu::internal_logging::NullLog()
00139 #define KUDU_DCHECK_NE(val1, val2) while (false) kudu::internal_logging::NullLog()
00140 #define KUDU_DCHECK_LE(val1, val2) while (false) kudu::internal_logging::NullLog()
00141 #define KUDU_DCHECK_LT(val1, val2) while (false) kudu::internal_logging::NullLog()
00142 #define KUDU_DCHECK_GE(val1, val2) while (false) kudu::internal_logging::NullLog()
00143 #define KUDU_DCHECK_GT(val1, val2) while (false) kudu::internal_logging::NullLog()
00144 #define KUDU_DCHECK_NOTNULL(val) (val)
00145 #define KUDU_DCHECK_STREQ(str1, str2) while (false) kudu::internal_logging::NullLog()
00146 #define KUDU_DCHECK_STRCASEEQ(str1, str2) while (false) kudu::internal_logging::NullLog()
00147 #define KUDU_DCHECK_STRNE(str1, str2) while (false) kudu::internal_logging::NullLog()
00148 #define KUDU_DCHECK_STRCASENE(str1, str2) while (false) kudu::internal_logging::NullLog()
00149
00150
00151
00152 #define KUDU_INFO 0
00153 #define KUDU_WARNING 1
00154 #define KUDU_ERROR 2
00155 #define KUDU_FATAL 3
00156
00157 #ifdef NDEBUG
00158 #define KUDU_DFATAL KUDU_WARNING
00159 #else
00160 #define KUDU_DFATAL KUDU_FATAL
00161 #endif // NDEBUG
00162
00163 #define KUDU_LOG_INTERNAL(level) kudu::internal_logging::CerrLog(level)
00164 #define KUDU_LOG(level) KUDU_LOG_INTERNAL(KUDU_##level)
00165
00166 #define KUDU_CHECK(condition) \
00167 (condition) ? 0 : KUDU_LOG(FATAL) << "Check failed: " #condition " "
00168
00169 namespace kudu {
00170
00171 namespace internal_logging {
00172
00177 class NullLog {
00178 public:
00184 template<class T>
00185 NullLog& operator<<(const T& t) {
00186 return *this;
00187 }
00188 };
00189
00191 class CerrLog {
00192 public:
00197 CerrLog(int severity)
00198 : severity_(severity),
00199 has_logged_(false) {
00200 }
00201
00202 ~CerrLog() {
00203 if (has_logged_) {
00204 std::cerr << std::endl;
00205 }
00206 if (severity_ == KUDU_FATAL) {
00207 exit(1);
00208 }
00209 }
00210
00216 template<class T>
00217 CerrLog& operator<<(const T& t) {
00218 has_logged_ = true;
00219 std::cerr << t;
00220 return *this;
00221 }
00222
00223 private:
00224 const int severity_;
00225 bool has_logged_;
00226 };
00227
00228 }
00229 }
00230
00231 #endif