#include <treekeyidx.h>


Classes | |
| class | TreeNode |
Public Member Functions | |
| virtual int | _compare (const TreeKeyIdx &ikey) |
| virtual void | append () |
| virtual void | appendChild () |
| virtual void | assureKeyPath (const char *keyPath=0) |
| virtual void | clearBound () const |
| virtual SWKey * | clone () const |
| virtual int | compare (const SWKey &ikey) |
| virtual int | compare (const SWKey &ikey) |
| virtual void | copyFrom (const SWKey &ikey) |
| virtual void | copyFrom (const TreeKeyIdx &ikey) |
| virtual void | decrement (int steps=1) |
| virtual bool | equals (const SWKey &ikey) |
| SWDEPRECATED char | Error () |
| virtual bool | firstChild () |
| const SWClass * | getClass () const |
| virtual long | getIndex () const |
| virtual int | getLevel () |
| char * | getLocale () const |
| virtual const char * | getLocalName () |
| unsigned long | getOffset () const |
| virtual const char * | getOSISRefRangeText () const |
| virtual const char * | getRangeText () const |
| virtual const char * | getShortText () const |
| virtual const char * | getText () const |
| virtual const char * | getUserData (int *size=0) const |
| virtual bool | hasChildren () |
| virtual void | increment (int steps=1) |
| virtual void | insertBefore () |
| virtual bool | isBoundSet () const |
| bool | isPersist () const |
| virtual bool | isTraversable () const |
| virtual bool | nextSibling () |
| virtual SWKey & | operator= (const TreeKeyIdx &ikey) |
| virtual bool | parent () |
| SWDEPRECATED char | Persist (signed char ipersist) |
| SWDEPRECATED char | Persist () const |
| virtual char | popError () |
| virtual void | positionFrom (const SWKey &ikey) |
| virtual bool | previousSibling () |
| virtual void | remove () |
| virtual void | root () |
| virtual void | save () |
| virtual void | setError (char err) |
| virtual void | setIndex (long iindex) |
| void | setLocale (const char *name) |
| virtual const char * | setLocalName (const char *) |
| void | setOffset (unsigned long offset) |
| void | setPersist (bool ipersist) |
| virtual void | setPosition (SW_POSITION p) |
| void | setPositionChangeListener (PositionChangeListener *pcl) |
| virtual SWKEY_OPERATORS void | setText (const char *ikey) |
| virtual void | setUserData (const char *userData, int size=0) |
| TreeKeyIdx (const char *idxPath, int fileMode=-1) | |
| TreeKeyIdx (const TreeKeyIdx &ikey) | |
| virtual | ~TreeKeyIdx () |
Static Public Member Functions | |
| static signed char | create (const char *path) |
Public Attributes | |
| class TreeKey::PositionChangeListener * | posChangeListener |
| __u64 | userData |
Protected Member Functions | |
| SWLocale * | getPrivateLocale () const |
| void | positionChanged () |
Protected Attributes | |
| bool | boundSet |
| char | error |
| char * | keytext |
| char * | localeName |
| SWClass * | myclass |
| bool | persist |
| char * | rangeText |
| SWBuf | unsnappedKeyText |
Private Member Functions | |
| void | getTreeNodeFromDatOffset (long ioffset, TreeNode *buf) const |
| char | getTreeNodeFromIdxOffset (long ioffset, TreeNode *node) const |
| void | init () |
| void | saveTreeNode (TreeNode *node) |
| void | saveTreeNodeOffsets (TreeNode *node) |
Private Attributes | |
| class TreeKeyIdx::TreeNode | currentNode |
| FileDesc * | datfd |
| FileDesc * | idxfd |
| char * | path |
Static Private Attributes | |
| static SWClass | classdef |
Class TreeKeyIdx The TreeKey implementation used for all tree-based modules in Sword, such as GenBooks.
Definition at line 37 of file treekeyidx.h.
| TreeKeyIdx::TreeKeyIdx | ( | const TreeKeyIdx & | ikey | ) |
Definition at line 40 of file treekeyidx.cpp.
| TreeKeyIdx::TreeKeyIdx | ( | const char * | idxPath, | |
| int | fileMode = -1 | |||
| ) |
Definition at line 48 of file treekeyidx.cpp.
00048 : currentNode() { 00049 SWBuf buf; 00050 00051 init(); 00052 path = 0; 00053 stdstr(&path, idxPath); 00054 00055 if (fileMode == -1) { // try read/write if possible 00056 fileMode = FileMgr::RDWR; 00057 } 00058 00059 buf.setFormatted("%s.idx", path); 00060 idxfd = FileMgr::getSystemFileMgr()->open(buf, fileMode, true); 00061 buf.setFormatted("%s.dat", path); 00062 datfd = FileMgr::getSystemFileMgr()->open(buf, fileMode, true); 00063 00064 if (datfd <= 0) { 00065 SWLog::getSystemLog()->logError("%d", errno); 00066 error = errno; 00067 } 00068 else { 00069 root(); 00070 } 00071 }
| TreeKeyIdx::~TreeKeyIdx | ( | ) | [virtual] |
Definition at line 79 of file treekeyidx.cpp.
00079 { 00080 if (path) 00081 delete [] path; 00082 00083 FileMgr::getSystemFileMgr()->close(idxfd); 00084 FileMgr::getSystemFileMgr()->close(datfd); 00085 }
| int TreeKeyIdx::_compare | ( | const TreeKeyIdx & | ikey | ) | [virtual] |
Definition at line 569 of file treekeyidx.cpp.
| void TreeKeyIdx::append | ( | ) | [virtual] |
Implements TreeKey.
Definition at line 200 of file treekeyidx.cpp.
00200 { 00201 TreeNode lastSib; 00202 if (currentNode.offset) { 00203 getTreeNodeFromIdxOffset(currentNode.offset, &lastSib); 00204 while (lastSib.next > -1) { 00205 getTreeNodeFromIdxOffset(lastSib.next, &lastSib); 00206 } 00207 __u32 idxOffset = idxfd->seek(0, SEEK_END); 00208 lastSib.next = idxOffset; 00209 saveTreeNodeOffsets(&lastSib); 00210 __u32 parent = currentNode.parent; 00211 currentNode.clear(); 00212 currentNode.offset = idxOffset; 00213 currentNode.parent = parent; 00214 positionChanged(); 00215 } 00216 }
| void TreeKeyIdx::appendChild | ( | ) | [virtual] |
Implements TreeKey.
Definition at line 219 of file treekeyidx.cpp.
00219 { 00220 if (firstChild()) { 00221 append(); 00222 } 00223 else { 00224 __u32 idxOffset = idxfd->seek(0, SEEK_END); 00225 currentNode.firstChild = idxOffset; 00226 saveTreeNodeOffsets(¤tNode); 00227 __u32 parent = currentNode.offset; 00228 currentNode.clear(); 00229 currentNode.offset = idxOffset; 00230 currentNode.parent = parent; 00231 } 00232 positionChanged(); 00233 }
| void TreeKey::assureKeyPath | ( | const char * | keyPath = 0 |
) | [virtual, inherited] |
Set the key to this path. If the path doesn't exist, then nodes are created as necessary
| keyPath | path to set/create; if unsupplied, then use any unsnapped setText value. |
Definition at line 39 of file treekey.cpp.
00039 { 00040 00041 if (!keyBuffer) { 00042 keyBuffer = unsnappedKeyText; 00043 //assert we have something to do before setting root 00044 if (!*keyBuffer) 00045 return; 00046 } 00047 00048 char *keybuf = 0; 00049 stdstr(&keybuf, keyBuffer); 00050 00051 root(); 00052 00053 // TODO: change to NOT use strtok. strtok is dangerous. 00054 SWBuf tok = strtok(keybuf, "/"); 00055 tok.trim(); 00056 while (tok.size()) { 00057 bool foundkey = false; 00058 if (hasChildren()) { 00059 firstChild(); 00060 if (tok == getLocalName()) { 00061 foundkey = true; 00062 } 00063 else { 00064 while (nextSibling()) { 00065 if (getLocalName()) { 00066 if (tok == getLocalName()) { 00067 foundkey = true; 00068 break; 00069 } 00070 } 00071 } 00072 } 00073 if (!foundkey) { 00074 append(); 00075 setLocalName(tok); 00076 save(); 00077 } 00078 } 00079 else { 00080 appendChild(); 00081 setLocalName(tok); 00082 save(); 00083 } 00084 00085 #ifdef DEBUG 00086 // std::cout << getLocalName() << " : " << tok << std::endl; 00087 #endif 00088 00089 tok = strtok(0, "/"); 00090 tok.trim(); 00091 00092 } 00093 delete [] keybuf; 00094 }
| virtual void SWKey::clearBound | ( | ) | const [inline, virtual, inherited] |
| SWKey * TreeKeyIdx::clone | ( | ) | const [virtual] |
Returns a new exact clone of this SWKey object. This allocates a new SWKey which must be deleted by the caller
Reimplemented from SWKey.
Definition at line 667 of file treekeyidx.cpp.
00668 { 00669 return new TreeKeyIdx(*this); 00670 }
| int SWKey::compare | ( | const SWKey & | ikey | ) | [virtual, inherited] |
Compares this key object to another SWKey object
| ikey | key to compare with this one |
| int TreeKeyIdx::compare | ( | const SWKey & | ikey | ) | [virtual] |
Implements TreeKey.
Definition at line 574 of file treekeyidx.cpp.
00574 { 00575 TreeKeyIdx *treeKey = SWDYNAMIC_CAST(TreeKeyIdx, (&ikey)); 00576 if (treeKey) 00577 return _compare(*treeKey); 00578 return SWKey::compare(ikey); 00579 }
| void TreeKeyIdx::copyFrom | ( | const SWKey & | ikey | ) | [virtual] |
Definition at line 549 of file treekeyidx.cpp.
00549 { 00550 unsnappedKeyText = ikey; 00551 SWKey::copyFrom(ikey); 00552 positionChanged(); 00553 }
| void TreeKeyIdx::copyFrom | ( | const TreeKeyIdx & | ikey | ) | [virtual] |
Copies as much info (position, range, etc.) as possible from another SWKey object
| ikey | other SWKey object from which to copy |
Reimplemented from SWKey.
Definition at line 449 of file treekeyidx.cpp.
00449 { 00450 unsnappedKeyText = ""; 00451 00452 SWKey::copyFrom(ikey); 00453 00454 currentNode.offset = ikey.currentNode.offset; 00455 currentNode.parent = ikey.currentNode.parent; 00456 currentNode.next = ikey.currentNode.next; 00457 currentNode.firstChild = ikey.currentNode.firstChild; 00458 stdstr(&(currentNode.name), ikey.currentNode.name); 00459 currentNode.dsize = ikey.currentNode.dsize; 00460 00461 if (currentNode.userData) 00462 delete [] currentNode.userData; 00463 if (currentNode.dsize) { 00464 currentNode.userData = new char [ currentNode.dsize ]; 00465 memcpy(currentNode.userData, ikey.currentNode.userData, currentNode.dsize); 00466 } 00467 else currentNode.userData = 0; 00468 00469 bool newFiles = true; 00470 00471 if (path && ikey.path) 00472 newFiles = strcmp(path, ikey.path); 00473 00474 if (newFiles) { 00475 stdstr(&path, ikey.path); 00476 00477 if (idxfd) { 00478 FileMgr::getSystemFileMgr()->close(idxfd); 00479 FileMgr::getSystemFileMgr()->close(datfd); 00480 } 00481 idxfd = FileMgr::getSystemFileMgr()->open(ikey.idxfd->path, ikey.idxfd->mode, ikey.idxfd->perms); 00482 datfd = FileMgr::getSystemFileMgr()->open(ikey.datfd->path, ikey.datfd->mode, ikey.datfd->perms); 00483 } 00484 positionChanged(); 00485 }
| signed char TreeKeyIdx::create | ( | const char * | path | ) | [static] |
Definition at line 286 of file treekeyidx.cpp.
00286 { 00287 char *path = 0; 00288 char *buf = new char [ strlen (ipath) + 20 ]; 00289 FileDesc *fd, *fd2; 00290 00291 stdstr(&path, ipath); 00292 00293 if ((path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\')) 00294 path[strlen(path)-1] = 0; 00295 00296 sprintf(buf, "%s.dat", path); 00297 FileMgr::removeFile(buf); 00298 fd = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); 00299 fd->getFd(); 00300 FileMgr::getSystemFileMgr()->close(fd); 00301 00302 sprintf(buf, "%s.idx", path); 00303 FileMgr::removeFile(buf); 00304 fd2 = FileMgr::getSystemFileMgr()->open(buf, FileMgr::CREAT|FileMgr::WRONLY, FileMgr::IREAD|FileMgr::IWRITE); 00305 fd2->getFd(); 00306 FileMgr::getSystemFileMgr()->close(fd2); 00307 00308 TreeKeyIdx newTree(path); 00309 TreeKeyIdx::TreeNode root; 00310 stdstr(&(root.name), ""); 00311 newTree.saveTreeNode(&root); 00312 00313 delete [] path; 00314 00315 return 0; 00316 }
| void TreeKeyIdx::decrement | ( | int | steps = 1 |
) | [virtual] |
Decrements key a number of entry positions This is only valid if isTraversable is true
| steps | Number of entries to jump backward |
Implements TreeKey.
Definition at line 582 of file treekeyidx.cpp.
00582 { 00583 error = getTreeNodeFromIdxOffset(currentNode.offset - (4*steps), ¤tNode); 00584 positionChanged(); 00585 }
| virtual bool SWKey::equals | ( | const SWKey & | ikey | ) | [inline, virtual, inherited] |
| SWDEPRECATED char SWKey::Error | ( | ) | [inline, inherited] |
| bool TreeKeyIdx::firstChild | ( | ) | [virtual] |
Go to the first child of the current node
Implements TreeKey.
Definition at line 155 of file treekeyidx.cpp.
00155 { 00156 if (currentNode.firstChild > -1) { 00157 error = getTreeNodeFromIdxOffset(currentNode.firstChild, ¤tNode); 00158 positionChanged(); 00159 return true; 00160 } 00161 return false; 00162 }
| const SWClass* SWObject::getClass | ( | ) | const [inline, inherited] |
Use this to get the class definition and inheritance order.
Definition at line 59 of file swobject.h.
00059 { 00060 return myclass; 00061 }
| virtual long TreeKey::getIndex | ( | ) | const [inline, virtual, inherited] |
| int TreeKeyIdx::getLevel | ( | ) | [virtual] |
Reimplemented from TreeKey.
Definition at line 133 of file treekeyidx.cpp.
00133 { 00134 TreeNode iterator; 00135 iterator.parent = currentNode.parent; 00136 int level = 0; 00137 while (iterator.parent > -1) { 00138 level++; 00139 getTreeNodeFromIdxOffset(iterator.parent, &iterator); 00140 } 00141 return level; 00142 }
| char* SWKey::getLocale | ( | ) | const [inline, inherited] |
Definition at line 215 of file swkey.h.
00215 { return localeName; }
| const char * TreeKeyIdx::getLocalName | ( | ) | [virtual] |
Implements TreeKey.
Definition at line 88 of file treekeyidx.cpp.
00088 { 00089 unsnappedKeyText = ""; 00090 return currentNode.name; 00091 }
| unsigned long TreeKeyIdx::getOffset | ( | ) | const [virtual] |
Implements TreeKey.
Definition at line 409 of file treekeyidx.cpp.
00409 { 00410 unsnappedKeyText = ""; 00411 return currentNode.offset; 00412 }
| const char * SWKey::getOSISRefRangeText | ( | ) | const [virtual, inherited] |
Reimplemented in ListKey, and VerseKey.
Definition at line 202 of file swkey.cpp.
00202 { 00203 return getRangeText(); 00204 }
| SWLocale * SWKey::getPrivateLocale | ( | ) | const [protected, inherited] |
Definition at line 110 of file swkey.cpp.
00110 { 00111 if (!locale) { 00112 if ((!localeCache.name) || (strcmp(localeCache.name, localeName))) { 00113 stdstr(&(localeCache.name), localeName); 00114 // this line is the entire bit of work we're trying to avoid with the cache 00115 // worth it? compare time examples/cmdline/search KJV "God love world" to 00116 // same with this method reduced to: 00117 // if (!local) local = ... (call below); return locale; 00118 localeCache.locale = LocaleMgr::getSystemLocaleMgr()->getLocale(localeName); 00119 } 00120 locale = localeCache.locale; 00121 } 00122 return locale; 00123 }
| const char * SWKey::getRangeText | ( | ) | const [virtual, inherited] |
| virtual const char* SWKey::getShortText | ( | ) | const [inline, virtual, inherited] |
| const char * TreeKeyIdx::getText | ( | ) | const [virtual] |
returns string representation of this key
Implements TreeKey.
Definition at line 615 of file treekeyidx.cpp.
00615 { 00616 TreeNode parent; 00617 static SWBuf fullPath; 00618 fullPath = currentNode.name; 00619 parent.parent = currentNode.parent; 00620 while (parent.parent > -1) { 00621 getTreeNodeFromIdxOffset(parent.parent, &parent); 00622 fullPath = ((SWBuf)parent.name) + (SWBuf) "/" + fullPath; 00623 } 00624 // we've snapped; clear our unsnapped text holder 00625 unsnappedKeyText = ""; 00626 return fullPath.c_str(); 00627 }
| void TreeKeyIdx::getTreeNodeFromDatOffset | ( | long | ioffset, | |
| TreeNode * | buf | |||
| ) | const [private] |
Definition at line 328 of file treekeyidx.cpp.
00328 { 00329 unsnappedKeyText = ""; 00330 char ch; 00331 __s32 tmp; 00332 __u16 tmp2; 00333 00334 if (datfd > 0) { 00335 00336 datfd->seek(ioffset, SEEK_SET); 00337 00338 datfd->read(&tmp, 4); 00339 node->parent = swordtoarch32(tmp); 00340 00341 datfd->read(&tmp, 4); 00342 node->next = swordtoarch32(tmp); 00343 00344 datfd->read(&tmp, 4); 00345 node->firstChild = swordtoarch32(tmp); 00346 00347 SWBuf name; 00348 do { 00349 datfd->read(&ch, 1); 00350 name += ch; 00351 } while (ch); 00352 00353 stdstr(&(node->name), name.c_str()); 00354 00355 datfd->read(&tmp2, 2); 00356 node->dsize = swordtoarch16(tmp2); 00357 00358 if (node->dsize) { 00359 if (node->userData) 00360 delete [] node->userData; 00361 node->userData = new char [node->dsize]; 00362 datfd->read(node->userData, node->dsize); 00363 } 00364 } 00365 }
| char TreeKeyIdx::getTreeNodeFromIdxOffset | ( | long | ioffset, | |
| TreeNode * | node | |||
| ) | const [private] |
Definition at line 377 of file treekeyidx.cpp.
00377 { 00378 unsnappedKeyText = ""; 00379 __u32 offset; 00380 char error = KEYERR_OUTOFBOUNDS; 00381 00382 if (ioffset < 0) { 00383 ioffset = 0; 00384 error = 77; // out of bounds but still position to 0; 00385 } 00386 00387 node->offset = ioffset; 00388 if (idxfd > 0) { 00389 if (idxfd->getFd() > 0) { 00390 idxfd->seek(ioffset, SEEK_SET); 00391 if (idxfd->read(&offset, 4) == 4) { 00392 offset = swordtoarch32(offset); 00393 error = (error == 77) ? KEYERR_OUTOFBOUNDS : 0; 00394 getTreeNodeFromDatOffset(offset, node); 00395 } 00396 else { 00397 idxfd->seek(-4, SEEK_END); 00398 if (idxfd->read(&offset, 4) == 4) { 00399 offset = swordtoarch32(offset); 00400 getTreeNodeFromDatOffset(offset, node); 00401 } 00402 } 00403 } 00404 } 00405 return error; 00406 }
| const char * TreeKeyIdx::getUserData | ( | int * | size = 0 |
) | const [virtual] |
Implements TreeKey.
Definition at line 94 of file treekeyidx.cpp.
00094 { 00095 unsnappedKeyText = ""; 00096 if (size) 00097 *size = (int)currentNode.dsize; 00098 return currentNode.userData; 00099 }
| bool TreeKeyIdx::hasChildren | ( | ) | [virtual] |
Does the current node have children?
Implements TreeKey.
Definition at line 195 of file treekeyidx.cpp.
00195 { 00196 return (currentNode.firstChild > -1); 00197 }
| void TreeKeyIdx::increment | ( | int | steps = 1 |
) | [virtual] |
Increments key a number of entry positions This is only valid if isTraversable is true
| steps | Number of entries to jump forward |
Implements TreeKey.
Definition at line 587 of file treekeyidx.cpp.
00587 { 00588 error = getTreeNodeFromIdxOffset(currentNode.offset + (4*steps), ¤tNode); 00589 if (error) { 00590 // SWLog::getSystemLog()->logError("error: %d", error); 00591 } 00592 positionChanged(); 00593 00594 /* 00595 // assert positive 00596 if (steps < 0) { 00597 decrement(steps * -1); 00598 return; 00599 } 00600 00601 while (steps > 0) { 00602 if (!firstChild()) { 00603 if (!nextSibbling() { 00604 error = KEYERR_OUTOFBOUNDS; 00605 return; 00606 } 00607 } 00608 steps--; 00609 } 00610 */ 00611 }
| void TreeKeyIdx::init | ( | ) | [private] |
Reimplemented from TreeKey.
Definition at line 74 of file treekeyidx.cpp.
| void TreeKeyIdx::insertBefore | ( | ) | [virtual] |
| virtual bool SWKey::isBoundSet | ( | ) | const [inline, virtual, inherited] |
| bool SWKey::isPersist | ( | ) | const [inherited] |
| virtual bool TreeKeyIdx::isTraversable | ( | ) | const [inline, virtual] |
Whether or not this key can be ++ -- incremented
Reimplemented from TreeKey.
Definition at line 119 of file treekeyidx.h.
| bool TreeKeyIdx::nextSibling | ( | ) | [virtual] |
Go to the next sibling of the current node
Implements TreeKey.
Definition at line 165 of file treekeyidx.cpp.
00165 { 00166 if (currentNode.next > -1) { 00167 error = getTreeNodeFromIdxOffset(currentNode.next, ¤tNode); 00168 positionChanged(); 00169 return true; 00170 } 00171 return false; 00172 }
| virtual SWKey& TreeKeyIdx::operator= | ( | const TreeKeyIdx & | ikey | ) | [inline, virtual] |
Definition at line 109 of file treekeyidx.h.
00109 { copyFrom(ikey); return *this; }
| bool TreeKeyIdx::parent | ( | ) | [virtual] |
Go to the parent of the current node
Implements TreeKey.
Definition at line 145 of file treekeyidx.cpp.
00145 { 00146 if (currentNode.parent > -1) { 00147 error = getTreeNodeFromIdxOffset(currentNode.parent, ¤tNode); 00148 positionChanged(); 00149 return true; 00150 } 00151 return false; 00152 }
| SWDEPRECATED char SWKey::Persist | ( | signed char | ipersist | ) | [inline, inherited] |
Sets whether this key should persist in any module to which it is set otherwise just a copy will be used in the module.
| ipersist | value which to set persist; |
Definition at line 153 of file swkey.h.
00153 { setPersist(ipersist); return isPersist(); }
| SWDEPRECATED char SWKey::Persist | ( | ) | const [inline, inherited] |
| char SWKey::popError | ( | ) | [virtual, inherited] |
| void TreeKey::positionChanged | ( | ) | [inline, protected, inherited] |
Definition at line 49 of file treekey.h.
00049 { if (posChangeListener) posChangeListener->positionChanged(); }
| virtual void SWKey::positionFrom | ( | const SWKey & | ikey | ) | [inline, virtual, inherited] |
| bool TreeKeyIdx::previousSibling | ( | ) | [virtual] |
Go to the previous sibling of the current node
Implements TreeKey.
Definition at line 175 of file treekeyidx.cpp.
00175 { 00176 TreeNode iterator; 00177 __s32 target = currentNode.offset; 00178 if (currentNode.parent > -1) { 00179 getTreeNodeFromIdxOffset(currentNode.parent, &iterator); 00180 getTreeNodeFromIdxOffset(iterator.firstChild, &iterator); 00181 if (iterator.offset != target) { 00182 while ((iterator.next != target) && (iterator.next > -1)) 00183 getTreeNodeFromIdxOffset(iterator.next, &iterator); 00184 if (iterator.next > -1) { 00185 error = getTreeNodeFromIdxOffset(iterator.offset, ¤tNode); 00186 positionChanged(); 00187 return true; 00188 } 00189 } 00190 } 00191 return false; 00192 }
| void TreeKeyIdx::remove | ( | ) | [virtual] |
Implements TreeKey.
Definition at line 240 of file treekeyidx.cpp.
00240 { 00241 TreeNode node; 00242 bool done = false; 00243 if (currentNode.offset) { 00244 getTreeNodeFromIdxOffset(currentNode.offset, &node); 00245 if (node.parent > -1) { 00246 TreeNode parent; 00247 getTreeNodeFromIdxOffset(node.parent, &parent); 00248 if (parent.firstChild == node.offset) { 00249 parent.firstChild = node.next; 00250 saveTreeNodeOffsets(&parent); 00251 getTreeNodeFromIdxOffset(parent.offset, ¤tNode); 00252 done = true; 00253 } 00254 } 00255 if (!done) { 00256 TreeNode iterator; 00257 __s32 target = currentNode.offset; 00258 if (currentNode.parent > -1) { 00259 getTreeNodeFromIdxOffset(currentNode.parent, &iterator); 00260 getTreeNodeFromIdxOffset(iterator.firstChild, &iterator); 00261 if (iterator.offset != target) { 00262 while ((iterator.next != target) && (iterator.next > -1)) 00263 getTreeNodeFromIdxOffset(iterator.next, &iterator); 00264 if (iterator.next > -1) { 00265 TreeNode prev; 00266 getTreeNodeFromIdxOffset(iterator.offset, &prev); 00267 prev.next = node.next; 00268 saveTreeNodeOffsets(&prev); 00269 getTreeNodeFromIdxOffset(prev.offset, ¤tNode); 00270 } 00271 } 00272 } 00273 } 00274 positionChanged(); 00275 } 00276 }
| void TreeKeyIdx::root | ( | ) | [virtual] |
Go to the root node
Implements TreeKey.
Definition at line 128 of file treekeyidx.cpp.
00128 { 00129 error = getTreeNodeFromIdxOffset(0, ¤tNode); 00130 positionChanged(); 00131 }
| void TreeKeyIdx::save | ( | ) | [virtual] |
Reimplemented from TreeKey.
Definition at line 123 of file treekeyidx.cpp.
00123 { 00124 saveTreeNode(¤tNode); 00125 }
| void TreeKeyIdx::saveTreeNode | ( | TreeNode * | node | ) | [private] |
Definition at line 488 of file treekeyidx.cpp.
00488 { 00489 long datOffset = 0; 00490 __s32 tmp; 00491 if (idxfd > 0) { 00492 00493 idxfd->seek(node->offset, SEEK_SET); 00494 datOffset = datfd->seek(0, SEEK_END); 00495 tmp = archtosword32(datOffset); 00496 idxfd->write(&tmp, 4); 00497 00498 saveTreeNodeOffsets(node); 00499 00500 datfd->write(node->name, strlen(node->name)); 00501 char null = 0; 00502 datfd->write(&null, 1); 00503 00504 __u16 tmp2 = archtosword16(node->dsize); 00505 datfd->write(&tmp2, 2); 00506 00507 if (node->dsize) { 00508 datfd->write(node->userData, node->dsize); 00509 } 00510 } 00511 }
| void TreeKeyIdx::saveTreeNodeOffsets | ( | TreeNode * | node | ) | [private] |
Definition at line 420 of file treekeyidx.cpp.
00420 { 00421 unsnappedKeyText = ""; 00422 long datOffset = 0; 00423 __s32 tmp; 00424 00425 if (idxfd > 0) { 00426 idxfd->seek(node->offset, SEEK_SET); 00427 if (idxfd->read(&tmp, 4) != 4) { 00428 datOffset = datfd->seek(0, SEEK_END); 00429 tmp = archtosword32(datOffset); 00430 idxfd->write(&tmp, 4); 00431 } 00432 else { 00433 datOffset = swordtoarch32(tmp); 00434 datfd->seek(datOffset, SEEK_SET); 00435 } 00436 00437 tmp = archtosword32(node->parent); 00438 datfd->write(&tmp, 4); 00439 00440 tmp = archtosword32(node->next); 00441 datfd->write(&tmp, 4); 00442 00443 tmp = archtosword32(node->firstChild); 00444 datfd->write(&tmp, 4); 00445 } 00446 }
| virtual void SWKey::setError | ( | char | err | ) | [inline, virtual, inherited] |
| virtual void TreeKey::setIndex | ( | long | iindex | ) | [inline, virtual, inherited] |
| void SWKey::setLocale | ( | const char * | name | ) | [inline, inherited] |
Definition at line 216 of file swkey.h.
00216 { stdstr(&localeName, name); locale = 0; } // this will force an on demand lookup of our locale
| const char * TreeKeyIdx::setLocalName | ( | const char * | newName | ) | [virtual] |
Implements TreeKey.
Definition at line 116 of file treekeyidx.cpp.
00116 { 00117 unsnappedKeyText = ""; 00118 stdstr(&(currentNode.name), newName); 00119 return currentNode.name; 00120 }
| void TreeKeyIdx::setOffset | ( | unsigned long | offset | ) | [virtual] |
Implements TreeKey.
Definition at line 414 of file treekeyidx.cpp.
00414 { 00415 error = getTreeNodeFromIdxOffset(offset, ¤tNode); 00416 positionChanged(); 00417 }
| void SWKey::setPersist | ( | bool | ipersist | ) | [inherited] |
| void TreeKeyIdx::setPosition | ( | SW_POSITION | p | ) | [virtual] |
Implements TreeKey.
Definition at line 555 of file treekeyidx.cpp.
00555 { 00556 switch (p) { 00557 case POS_TOP: 00558 root(); 00559 break; 00560 case POS_BOTTOM: 00561 error = getTreeNodeFromIdxOffset(idxfd->seek(-4, SEEK_END), ¤tNode); 00562 break; 00563 } 00564 positionChanged(); 00565 popError(); // clear error from normalize 00566 }
| void TreeKey::setPositionChangeListener | ( | PositionChangeListener * | pcl | ) | [inline, inherited] |
Definition at line 63 of file treekey.h.
00063 { posChangeListener = pcl; posChangeListener->setTreeKey(this); }
| void TreeKeyIdx::setText | ( | const char * | ikey | ) | [virtual] |
Sets this SWKey with a character string
| ikey | string used to set this key |
Implements TreeKey.
Definition at line 514 of file treekeyidx.cpp.
00514 { 00515 char *buf = 0; 00516 stdstr(&buf, ikey); 00517 SWBuf leaf = strtok(buf, "/"); 00518 leaf.trim(); 00519 root(); 00520 while ((leaf.size()) && (!popError())) { 00521 bool ok, inChild = false; 00522 error = KEYERR_OUTOFBOUNDS; 00523 for (ok = firstChild(); ok; ok = nextSibling()) { 00524 inChild = true; 00525 if (leaf == getLocalName()) { 00526 error = 0; 00527 break; 00528 } 00529 } 00530 leaf = strtok(0, "/"); 00531 leaf.trim(); 00532 if (!ok) { 00533 if (inChild) { // if we didn't find a matching child node, default to first child 00534 parent(); 00535 firstChild(); 00536 } 00537 error = KEYERR_OUTOFBOUNDS; 00538 } 00539 } 00540 if (leaf.size()) 00541 error = KEYERR_OUTOFBOUNDS; 00542 delete [] buf; 00543 unsnappedKeyText = ikey; 00544 positionChanged(); 00545 }
| void TreeKeyIdx::setUserData | ( | const char * | userData, | |
| int | size = 0 | |||
| ) | [virtual] |
Implements TreeKey.
Definition at line 102 of file treekeyidx.cpp.
00102 { 00103 // this makes sure any unsnapped path exists 00104 assureKeyPath(); 00105 if (currentNode.userData) 00106 delete currentNode.userData; 00107 00108 if (!size) 00109 size = strlen(userData) + 1; 00110 00111 currentNode.userData = new char [ size ]; 00112 memcpy(currentNode.userData, userData, size); 00113 currentNode.dsize = size; 00114 }
bool SWKey::boundSet [mutable, protected, inherited] |
SWClass TreeKeyIdx::classdef [static, private] |
Reimplemented from TreeKey.
Definition at line 53 of file treekeyidx.h.
class TreeKeyIdx::TreeNode TreeKeyIdx::currentNode [private] |
FileDesc* TreeKeyIdx::datfd [private] |
Definition at line 58 of file treekeyidx.h.
char SWKey::error [protected, inherited] |
FileDesc* TreeKeyIdx::idxfd [private] |
Definition at line 57 of file treekeyidx.h.
char* SWKey::keytext [protected, inherited] |
char* SWKey::localeName [protected, inherited] |
SWClass* SWObject::myclass [protected, inherited] |
Definition at line 53 of file swobject.h.
char* TreeKeyIdx::path [private] |
Definition at line 55 of file treekeyidx.h.
bool SWKey::persist [protected, inherited] |
class TreeKey::PositionChangeListener * TreeKey::posChangeListener [inherited] |
char* SWKey::rangeText [mutable, protected, inherited] |
SWBuf TreeKey::unsnappedKeyText [mutable, protected, inherited] |
__u64 SWKey::userData [inherited] |
1.6.1