本文整理汇总了C++中PropertyMap::first方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertyMap::first方法的具体用法?C++ PropertyMap::first怎么用?C++ PropertyMap::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropertyMap
的用法示例。
在下文中一共展示了PropertyMap::first方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testInsertDelete
bool testInsertDelete(int numInsert, int numDelete, int delOffset, int randSeed) {
srand(randSeed);
char str[20];
bool result = true;
assert(numDelete >= 0 && numDelete < numInsert);
assert(delOffset >= 0 && delOffset+numDelete <= numInsert);
PropertyMap map;
// add some random numbers
int *nums = (int*)malloc(numInsert*sizeof(int));
int i;
for (i = 0; i < numInsert; i++) {
nums[i] = int(1000.0*rand()/RAND_MAX);
Value val = Number(nums[i]);
ValueImp *v = val.imp();
v->ref();
sprintf(str,"%05d-%05d",nums[i],i); // ensure uniqueness
map.put(str,v,0);
map.checkTree();
}
// check to ensure they're all there
for (i = 0; i < numInsert; i++) {
sprintf(str,"%05d-%05d",nums[i],i);
ValueImp *v = map.get(str);
if (v == 0 || v->type() != NumberType ||
static_cast<NumberImp*>(v)->value() != nums[i]) {
result = false;
}
map.checkTree();
}
// delete some
for (i = delOffset; i < delOffset+numDelete; i++) {
sprintf(str,"%05d-%05d",nums[i],i);
map.remove(str);
map.checkTree();
}
// make sure the deletes ones aren't there any more, and the others are
for (i = 0; i < numInsert; i++) {
sprintf(str,"%05d-%05d",nums[i],i);
ValueImp *v = map.get(str);
if (i >= delOffset && i < delOffset+numDelete) {
// should have been deleted
if (v)
result = false;
}
else {
// should not have been deleted
if (v == 0 || v->type() != NumberType ||
static_cast<NumberImp*>(v)->value() != nums[i]) {
result = false;
}
}
map.checkTree();
}
// check that first() and next() work
PropertyMapNode *it = map.first();
int itcount = 0;
while (it) {
itcount++;
PropertyMapNode *prev = it;
it = it->next();
if (it) {
if (uscompare(prev->name,it->name) >= 0)
result = false;
}
}
if (itcount != numInsert-numDelete)
result = false;
if (result)
printf("PASS: Insert %d, delete %d-%d, seed %d\n",numInsert,delOffset,
delOffset+numDelete-1,randSeed);
else
printf("FAIL: Insert %d, delete %d-%d, seed %d\n",numInsert,delOffset,
delOffset+numDelete-1,randSeed);
return result;
}