Android里面这些CHECK操作是什么作用?
类似的操作:
#define CHECK_EQ(x,y) CHECK_OP(x,y,EQ,==)
#define CHECK_NE(x,y) CHECK_OP(x,y,NE,!=)
#define CHECK_LE(x,y) CHECK_OP(x,y,LE,<=)
#define CHECK_LT(x,y) CHECK_OP(x,y,LT,<)
#define CHECK_GE(x,y) CHECK_OP(x,y,GE,>=)
#define CHECK_GT(x,y) CHECK_OP(x,y,GT,>)CHECK_OP的定义如下:
#define CHECK_OP(x,y,suffix,op) \
do { \
AString ___res = Compare_##suffix(x, y); \
if (!___res.empty()) { \
AString ___full = \
__FILE__ ":" LITERAL_TO_STRING(__LINE__) \
" CHECK_" #suffix "( " #x "," #y ") failed: "; \
___full.append(___res); \
\
LOG_ALWAYS_FATAL("%s", ___full.c_str()); \
} \
} while (false)如以下代码 开始处的 CHECK_EQ((int)info->mStatus, (int)OWNED_BY_US);
bool OMXCodec::drainInputBuffer(BufferInfo *info) {
if (info != NULL) {
CHECK_EQ((int)info->mStatus, (int)OWNED_BY_US);
} if (mSignalledEOS) {
return false;
}
类似的操作:
#define CHECK_EQ(x,y) CHECK_OP(x,y,EQ,==)
#define CHECK_NE(x,y) CHECK_OP(x,y,NE,!=)
#define CHECK_LE(x,y) CHECK_OP(x,y,LE,<=)
#define CHECK_LT(x,y) CHECK_OP(x,y,LT,<)
#define CHECK_GE(x,y) CHECK_OP(x,y,GE,>=)
#define CHECK_GT(x,y) CHECK_OP(x,y,GT,>)CHECK_OP的定义如下:
#define CHECK_OP(x,y,suffix,op) \
do { \
AString ___res = Compare_##suffix(x, y); \
if (!___res.empty()) { \
AString ___full = \
__FILE__ ":" LITERAL_TO_STRING(__LINE__) \
" CHECK_" #suffix "( " #x "," #y ") failed: "; \
___full.append(___res); \
\
LOG_ALWAYS_FATAL("%s", ___full.c_str()); \
} \
} while (false)如以下代码 开始处的 CHECK_EQ((int)info->mStatus, (int)OWNED_BY_US);
bool OMXCodec::drainInputBuffer(BufferInfo *info) {
if (info != NULL) {
CHECK_EQ((int)info->mStatus, (int)OWNED_BY_US);
} if (mSignalledEOS) {
return false;
}
解决方案 »
- javapos ptr.open打印机 出错
- 很奇怪:android中使用socket出现异常setsockopt failed: EBADF (Bad file number)
- post传参保存数据库中为空怎么回事?
- 求助!!!
- 现在有能用在android上的RDP client吗?要有source code的
- 关于GridView的一个问题
- 如何防止后台程序自己退出?
- 弱弱的问个问题 android怎么输出system语句啊
- Android app 发布到 google play
- 请问Android如何在视图里添加按钮呢?
- 跪求 Android 4.2 虚拟机的root方法
- 如何实现手机和PC用NFC通信
There are various helper macros for equality/inequality checks - CHECK_EQ, CHECK_NE, CHECK_LE, CHECK_LT, CHECK_GE, and CHECK_GT. They compare two values, and log a FATAL message including the two values when the result is not as expected. The values must have operator<<(ostream, ...) defined.You may append to the error message like so: CHECK_NE(1, 2) << ": The world must be ending!";
We are very careful to ensure that each argument is evaluated exactly once, and that anything which is legal to pass as a function argument is legal here. In particular, the arguments may be temporary expressions which will end up being destroyed at the end of the apparent statement, for example: CHECK_EQ(string("abc")[1], 'b');
The compiler reports an error if one of the arguments is a pointer and the other is NULL. To work around this, simply static_cast NULL to the type of the desired pointer. CHECK_EQ(some_ptr, static_cast<SomeType*>(NULL));
Better yet, use the CHECK_NOTNULL macro: CHECK_NOTNULL(some_ptr);
some_ptr->DoSomething();
Since this macro returns the given pointer, this is very useful in constructor initializer lists. struct S {
S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
Something* ptr_;
};
Note that you cannot use this macro as a C++ stream due to this feature. Please use CHECK_EQ described above to log a custom message before aborting the application.If you are comparing C strings (char *), a handy set of macros performs case sensitive as well as case insensitive comparisons - CHECK_STREQ, CHECK_STRNE, CHECK_STRCASEEQ, and CHECK_STRCASENE. The CASE versions are case-insensitive. You can safely pass NULL pointers for this macro. They treat NULL and any non-NULL string as not equal. Two NULLs are equal.Note that both arguments may be temporary strings which are destructed at the end of the current "full expression" (e.g., CHECK_STREQ(Foo().c_str(), Bar().c_str()) where Foo and Bar return C++'s std::string).The CHECK_DOUBLE_EQ macro checks the equality of two floating point values, accepting a small error margin. CHECK_NEAR accepts a third floating point argument, which specifies the acceptable error margin.