haiku/3rdparty/mmu_man/themes/CompareMessages.cpp

45 lines
977 B
C++
Raw Normal View History

/*
* function to compare 2 BMessages
*/
#include <string.h>
#include <Message.h>
/* returns true if == */
bool CompareMessages(BMessage &a, BMessage &b)
{
char *name;
type_code code;
int32 count, index, i;
const void *adata, *bdata;
ssize_t asize, bsize;
if (a.what != b.what)
return false;
for (index = 0; a.GetInfo(B_ANY_TYPE, index, &name, &code, &count) == B_OK; i++) {
for (i = 0; i < count; i++) {
if (a.FindData(name, code, i, &adata, &asize) != B_OK)
return false;
if (b.FindData(name, code, i, &bdata, &bsize) != B_OK)
return false;
if (asize != bsize)
return false;
if (memcmp(adata, bdata, asize))
return false;
}
}
/* cross compare */
for (index = 0; b.GetInfo(B_ANY_TYPE, index, &name, &code, &count) == B_OK; i++) {
type_code acode;
int32 acount;
if (a.GetInfo(name, &acode, &acount) < B_OK)
return false;
if (code != acode)
return false;
if (count != acount)
return false;
}
return true;
}