void TreeKeyIdx::increment(int steps) { error = getTreeNodeFromIdxOffset(currentNode.offset + (4*steps), ¤tNode); 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--; } */ }
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(); } }
bool TreeKeyIdx::nextSibling() { if (currentNode.next > -1) { error = getTreeNodeFromIdxOffset(currentNode.next, ¤tNode); positionChanged(); return true; } return false; }
bool TreeKeyIdx::firstChild() { if (currentNode.firstChild > -1) { error = getTreeNodeFromIdxOffset(currentNode.firstChild, ¤tNode); positionChanged(); return true; } return false; }
bool TreeKeyIdx::parent() { if (currentNode.parent > -1) { error = getTreeNodeFromIdxOffset(currentNode.parent, ¤tNode); positionChanged(); return true; } return false; }
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, ¤tNode); positionChanged(); return true; } } } return false; }
int TreeKeyIdx::getLevel() { TreeNode iterator; iterator.parent = currentNode.parent; int level = 0; while (iterator.parent > -1) { level++; getTreeNodeFromIdxOffset(iterator.parent, &iterator); } return level; }
void TreeKeyIdx::setPosition(SW_POSITION p) { switch (p) { case POS_TOP: root(); break; case POS_BOTTOM: error = getTreeNodeFromIdxOffset(idxfd->seek(-4, SEEK_END), ¤tNode); break; } positionChanged(); popError(); // clear error from normalize }
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(); }
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, ¤tNode); 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, ¤tNode); } } } } positionChanged(); } }
void TreeKeyIdx::decrement(int steps) { error = getTreeNodeFromIdxOffset(currentNode.offset - (4*steps), ¤tNode); positionChanged(); }
void TreeKeyIdx::setOffset(unsigned long offset) { error = getTreeNodeFromIdxOffset(offset, ¤tNode); positionChanged(); }
void TreeKeyIdx::root() { error = getTreeNodeFromIdxOffset(0, ¤tNode); positionChanged(); }