Пример #1
0
void TreeKeyIdx::increment(int steps) {
	error = getTreeNodeFromIdxOffset(currentNode.offset + (4*steps), &currentNode);
	if (error) {
//		SWLog::getSystemLog()->logError("error: %d", error);
	}
	positionChanged();

/*
	// assert positive
	if (steps < 0) {
		decrement(steps * -1);
		return;
	}

	while (steps > 0) {
		if (!firstChild()) {
			if (!nextSibbling() {
				error = KEYERR_OUTOFBOUNDS;
				return;
			}
		}
		steps--;
	}
*/
}
Пример #2
0
void TreeKeyIdx::append() {
	TreeNode lastSib;
	if (currentNode.offset) {
		getTreeNodeFromIdxOffset(currentNode.offset, &lastSib);
		while (lastSib.next > -1) {
			getTreeNodeFromIdxOffset(lastSib.next, &lastSib);
		}
		__u32 idxOffset = idxfd->seek(0, SEEK_END);
		lastSib.next = idxOffset;
		saveTreeNodeOffsets(&lastSib);
		__u32 parent = currentNode.parent;
		currentNode.clear();
		currentNode.offset = idxOffset;
		currentNode.parent = parent;
		positionChanged();
	}
}
Пример #3
0
bool TreeKeyIdx::nextSibling() {
	if (currentNode.next > -1) {
		error = getTreeNodeFromIdxOffset(currentNode.next, &currentNode);
		positionChanged();
		return true;
	}
	return false;
}
Пример #4
0
bool TreeKeyIdx::firstChild() {
	if (currentNode.firstChild > -1) {
		error = getTreeNodeFromIdxOffset(currentNode.firstChild, &currentNode);
		positionChanged();
		return true;
	}
	return false;
}
Пример #5
0
bool TreeKeyIdx::parent() {
	if (currentNode.parent > -1) {
		error = getTreeNodeFromIdxOffset(currentNode.parent, &currentNode);
		positionChanged();
		return true;
	}
	return false;
}
Пример #6
0
bool TreeKeyIdx::previousSibling() {
	TreeNode iterator;
	__s32 target = currentNode.offset;
	if (currentNode.parent > -1) {
		getTreeNodeFromIdxOffset(currentNode.parent, &iterator);
		getTreeNodeFromIdxOffset(iterator.firstChild, &iterator);
		if (iterator.offset != target) {
			while ((iterator.next != target) && (iterator.next > -1))
				getTreeNodeFromIdxOffset(iterator.next, &iterator);
			if (iterator.next > -1) {
				error = getTreeNodeFromIdxOffset(iterator.offset, &currentNode);
				positionChanged();
				return true;
			}
		}
	}
	return false;
}
Пример #7
0
int TreeKeyIdx::getLevel() {
	TreeNode iterator;
	iterator.parent = currentNode.parent;
	int level = 0;
	while (iterator.parent > -1) {
		level++;
		getTreeNodeFromIdxOffset(iterator.parent, &iterator);
	}
	return level;
}
Пример #8
0
void TreeKeyIdx::setPosition(SW_POSITION p) {
	switch (p) {
	case POS_TOP:
		root();
		break;
	case POS_BOTTOM:
		error = getTreeNodeFromIdxOffset(idxfd->seek(-4, SEEK_END), &currentNode);
		break;
	} 
	positionChanged();
	popError();	// clear error from normalize
}
Пример #9
0
const char *TreeKeyIdx::getText() const {
	TreeNode parent;
	static SWBuf fullPath;
	fullPath = currentNode.name;
	parent.parent = currentNode.parent;
	while (parent.parent > -1) {
		getTreeNodeFromIdxOffset(parent.parent, &parent);
		fullPath = ((SWBuf)parent.name) + (SWBuf) "/" + fullPath;
	}
	// we've snapped; clear our unsnapped text holder
	unsnappedKeyText = "";
	return fullPath.c_str();
}
Пример #10
0
void TreeKeyIdx::remove() {
	TreeNode node;
	bool done = false;
	if (currentNode.offset) {
		getTreeNodeFromIdxOffset(currentNode.offset, &node);
		if (node.parent > -1) {
			TreeNode parent;
			getTreeNodeFromIdxOffset(node.parent, &parent);
			if (parent.firstChild == node.offset) {
				parent.firstChild = node.next;
				saveTreeNodeOffsets(&parent);
				getTreeNodeFromIdxOffset(parent.offset, &currentNode);
				done = true;
			}
		}
		if (!done) {
			TreeNode iterator;
			__s32 target = currentNode.offset;
			if (currentNode.parent > -1) {
				getTreeNodeFromIdxOffset(currentNode.parent, &iterator);
				getTreeNodeFromIdxOffset(iterator.firstChild, &iterator);
				if (iterator.offset != target) {
					while ((iterator.next != target) && (iterator.next > -1)) {
						getTreeNodeFromIdxOffset(iterator.next, &iterator);
					}
					if (iterator.next > -1) {
						TreeNode prev;
						getTreeNodeFromIdxOffset(iterator.offset, &prev);
						prev.next = node.next;
						saveTreeNodeOffsets(&prev);
						getTreeNodeFromIdxOffset(prev.offset, &currentNode);
					}
				}
			}
		}
		positionChanged();
	}
}
Пример #11
0
void TreeKeyIdx::decrement(int steps) {
	error = getTreeNodeFromIdxOffset(currentNode.offset - (4*steps), &currentNode);
	positionChanged();
}
Пример #12
0
void TreeKeyIdx::setOffset(unsigned long offset) {
	error = getTreeNodeFromIdxOffset(offset, &currentNode);
	positionChanged();
}
Пример #13
0
void TreeKeyIdx::root() {
	error = getTreeNodeFromIdxOffset(0, &currentNode);
	positionChanged();
}