Пример #1
0
/*!	\brief Returns the previous item belonging to the object.
	\param foundItem Pointer to a pre-allocated Item that shall be set
		   to the found item.
	\return \c B_OK, if everything went fine, \c B_ENTRY_NOT_FOUND, if we're
			through.
*/
status_t
ObjectItemIterator::GetPrevious(Item *foundItem)
{
//PRINT(("ObjectItemIterator::GetPrevious()\n"));
	status_t error = (foundItem ? InitCheck() : B_BAD_VALUE);
	if (error == B_OK && fDone)
		error = B_ENTRY_NOT_FOUND;
	if (error == B_OK) {
		// get the next item
		Item item;
		if (fFindFirst) {
			// first invocation: find the rightmost item of the object
			VKey k(fDirID, fObjectID, fOffset, 0xffffffffUL, KEY_FORMAT_3_5);
			error = fItemIterator.FindRightMostClose(&k, &item);
			fFindFirst = false;
		} else {
			// item iterator positioned, get the previous item
			error = fItemIterator.GoToPrevious(&item);
		}
		// check whether the item belongs to our object
		if (error == B_OK) {
			VKey itemKey;
			if (item.GetDirID() == fDirID && item.GetObjectID() == fObjectID) {
//PRINT(("  found item: %lu, %lu, %Lu\n", fDirID, fObjectID, item.GetOffset()));
				*foundItem = item;
			} else
{
//PRINT(("  item belongs to different object: (%lu, %lu)\n", item.GetDirID(), item.GetObjectID()));
				error = B_ENTRY_NOT_FOUND;
}
		}
		if (error != B_OK)
			fDone = true;
	}
//PRINT(("ObjectItemIterator::GetPrevious() done: %s\n", strerror(error)));
	return error;
}
Пример #2
0
/*!	\brief Returns the next item belonging to the object.

	Note, that offsets don't need to be unique for an object, at least not
	for files -- all indirect (and direct?) items have the same offset (1).
	This has the ugly side effect, when iterating forward there may be items
	with the same offset on previous nodes that will be skipped at the
	beginning. The GetNext() does always find the item on the rightmost
	possible node. Therefore searching forward starting with FIRST_ITEM_OFFSET
	doesn't work for files!

	\param foundItem Pointer to a pre-allocated Item that shall be set
		   to the found item.
	\return \c B_OK, if everything went fine, \c B_ENTRY_NOT_FOUND, if we're
			through.
*/
status_t
ObjectItemIterator::GetNext(Item *foundItem)
{
//PRINT(("ObjectItemIterator::GetNext(): fDirID: %lu, fObjectID: %lu\n", fDirID, fObjectID));
	status_t error = (foundItem ? InitCheck() : B_BAD_VALUE);
	if (error == B_OK && fDone)
		error = B_ENTRY_NOT_FOUND;
	if (error == B_OK) {
		// get the next item
		Item item;
		if (fFindFirst) {
			// first invocation: find the item with the given IDs and offset
			VKey k(fDirID, fObjectID, fOffset, 0, KEY_FORMAT_3_5);
			error = fItemIterator.FindRightMostClose(&k, &item);
			fFindFirst = false;
		} else {
			// item iterator positioned, get the next item
			error = fItemIterator.GoToNext(&item);
//REPORT_ERROR(error);
		}
		// check whether the item belongs to our object
		if (error == B_OK) {
			VKey itemKey;
			if (item.GetDirID() == fDirID && item.GetObjectID() == fObjectID)
				*foundItem = item;
			else
{
//PRINT(("  found item for another object: (%lu, %lu)\n", item.GetDirID(), item.GetObjectID()));
				error = B_ENTRY_NOT_FOUND;
}
		}
		if (error != B_OK)
			fDone = true;
	}
//	return error;
RETURN_ERROR(error)
}