diff options
Diffstat (limited to 'doc/api-documentation/html/treekeyidx_8cpp-source.html')
-rw-r--r-- | doc/api-documentation/html/treekeyidx_8cpp-source.html | 604 |
1 files changed, 604 insertions, 0 deletions
diff --git a/doc/api-documentation/html/treekeyidx_8cpp-source.html b/doc/api-documentation/html/treekeyidx_8cpp-source.html new file mode 100644 index 0000000..bb88f5b --- /dev/null +++ b/doc/api-documentation/html/treekeyidx_8cpp-source.html @@ -0,0 +1,604 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> +<title>treekeyidx.cpp Source File</title> +<link href="doxygen.css" rel="stylesheet" type="text/css"> +</head><body> +<!-- Generated by Doxygen 1.2.15 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center> +<hr><h1>treekeyidx.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font> +00002 <font class="comment"> * versekey.h - code for class 'versekey'- a standard Biblical verse key</font> +00003 <font class="comment"> *</font> +00004 <font class="comment"> * $Id: treekeyidx_8cpp-source.html,v 1.3 2002/06/20 20:23:10 mgruner Exp $</font> +00005 <font class="comment"> *</font> +00006 <font class="comment"> * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)</font> +00007 <font class="comment"> * CrossWire Bible Society</font> +00008 <font class="comment"> * P. O. Box 2528</font> +00009 <font class="comment"> * Tempe, AZ 85280-2528</font> +00010 <font class="comment"> *</font> +00011 <font class="comment"> * This program is free software; you can redistribute it and/or modify it</font> +00012 <font class="comment"> * under the terms of the GNU General Public License as published by the</font> +00013 <font class="comment"> * Free Software Foundation version 2.</font> +00014 <font class="comment"> *</font> +00015 <font class="comment"> * This program is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"> *</font> +00020 <font class="comment"> */</font> +00021 +00022 +00023 <font class="preprocessor">#include <treekeyidx.h></font> +00024 <font class="preprocessor">#include <fcntl.h></font> +00025 <font class="preprocessor">#include <stdio.h></font> +00026 <font class="preprocessor">#include <errno.h></font> +00027 <font class="preprocessor">#include <string></font> +00028 +00029 <font class="preprocessor">#ifndef __GNUC__</font> +00030 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font> +00031 <font class="preprocessor">#else</font> +00032 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font> +00033 <font class="preprocessor">#endif</font> +00034 <font class="preprocessor"></font> +00035 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00036 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font> nl = <font class="charliteral">'\n'</font>; +00037 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font> *classes[] = {<font class="stringliteral">"TreeKeyIdx"</font>, <font class="stringliteral">"TreeKey"</font>, <font class="stringliteral">"SWKey"</font>, <font class="stringliteral">"SWObject"</font>, 0}; +00038 <a class="code" href="class_s_w_class.html">SWClass</a> TreeKeyIdx::classdef(classes); +00039 +00040 +00041 TreeKeyIdx::TreeKeyIdx(<font class="keyword">const</font> <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> &ikey) : currentNode() { +00042 init(); +00043 path = 0; +00044 idxfd = 0; +00045 datfd = 0; +00046 <a class="code" href="class_s_w_key.html#a8">copyFrom</a>(ikey); +00047 } +00048 +00049 TreeKeyIdx::TreeKeyIdx(<font class="keyword">const</font> <font class="keywordtype">char</font> *idxPath, <font class="keywordtype">int</font> fileMode) : currentNode() { +00050 <font class="keywordtype">char</font> buf[127]; +00051 +00052 init(); +00053 path = 0; +00054 stdstr(&path, idxPath); +00055 +00056 <font class="preprocessor">#ifndef O_BINARY // O_BINARY is needed in Borland C++ 4.53</font> +00057 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0 // If it hasn't been defined than we probably</font> +00058 <font class="preprocessor"></font><font class="preprocessor">#endif // don't need it.</font> +00059 <font class="preprocessor"></font> +00060 <font class="keywordflow">if</font> (fileMode == -1) { <font class="comment">// try read/write if possible</font> +00061 fileMode = O_RDWR; +00062 } +00063 +00064 sprintf(buf, <font class="stringliteral">"%s.idx"</font>, path); +00065 idxfd = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>); +00066 sprintf(buf, <font class="stringliteral">"%s.dat"</font>, path); +00067 datfd = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>); +00068 +00069 <font class="keywordflow">if</font> (datfd <= 0) { +00070 sprintf(buf, <font class="stringliteral">"Error: %d"</font>, errno); +00071 perror(buf); +00072 error = errno; +00073 } +00074 <font class="keywordflow">else</font> { +00075 root(); +00076 } +00077 } +00078 +00079 +00080 <font class="keywordtype">void</font> TreeKeyIdx::init() { +00081 myclass = &classdef; +00082 } +00083 +00084 +00085 TreeKeyIdx::~TreeKeyIdx () { +00086 <font class="keywordflow">if</font> (path) +00087 <font class="keyword">delete</font> [] path; +00088 +00089 FileMgr::systemFileMgr.close(idxfd); +00090 FileMgr::systemFileMgr.close(datfd); +00091 } +00092 +00093 +00094 <font class="keyword">const</font> <font class="keywordtype">char</font> *TreeKeyIdx::getLocalName() { +00095 <font class="keywordflow">return</font> currentNode.name; +00096 } +00097 +00098 +00099 <font class="keyword">const</font> <font class="keywordtype">char</font> *TreeKeyIdx::getUserData(<font class="keywordtype">int</font> *size) { +00100 <font class="keywordflow">if</font> (size) +00101 *size = (int)currentNode.dsize; +00102 <font class="keywordflow">return</font> currentNode.userData; +00103 } +00104 +00105 +00106 <font class="keywordtype">void</font> TreeKeyIdx::setUserData(<font class="keyword">const</font> <font class="keywordtype">char</font> *userData, <font class="keywordtype">int</font> size) { +00107 <font class="keywordflow">if</font> (currentNode.userData) +00108 <font class="keyword">delete</font> currentNode.userData; +00109 +00110 <font class="keywordflow">if</font> (!size) +00111 size = strlen(userData) + 1; +00112 +00113 currentNode.userData = <font class="keyword">new</font> <font class="keywordtype">char</font> [ size ]; +00114 memcpy(currentNode.userData, userData, size); +00115 currentNode.dsize = size; +00116 } +00117 +00118 <font class="keyword">const</font> <font class="keywordtype">char</font> *TreeKeyIdx::setLocalName(<font class="keyword">const</font> <font class="keywordtype">char</font> *newName) { +00119 stdstr(&(currentNode.name), newName); +00120 <font class="keywordflow">return</font> currentNode.name; +00121 } +00122 +00123 +00124 <font class="keywordtype">void</font> TreeKeyIdx::save() { +00125 saveTreeNode(&currentNode); +00126 } +00127 +00128 +00129 <font class="keyword">const</font> <font class="keywordtype">char</font> *TreeKeyIdx::getFullName()<font class="keyword"> const </font>{ +00130 TreeNode parent; +00131 <font class="keyword">static</font> string fullPath; +00132 fullPath = currentNode.name; +00133 parent.parent = currentNode.parent; +00134 <font class="keywordflow">while</font> (parent.parent > -1) { +00135 getTreeNodeFromIdxOffset(parent.parent, &parent); +00136 fullPath = ((string)parent.name) + (string) <font class="stringliteral">"/"</font> + fullPath; +00137 } +00138 <font class="keywordflow">return</font> fullPath.c_str(); +00139 } +00140 +00141 +00142 <font class="keywordtype">void</font> TreeKeyIdx::root() { +00143 error = getTreeNodeFromIdxOffset(0, &currentNode); +00144 } +00145 +00146 +00147 <font class="keywordtype">bool</font> TreeKeyIdx::parent() { +00148 <font class="keywordflow">if</font> (currentNode.parent > -1) { +00149 error = getTreeNodeFromIdxOffset(currentNode.parent, &currentNode); +00150 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00151 } +00152 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00153 } +00154 +00155 +00156 <font class="keywordtype">bool</font> TreeKeyIdx::firstChild() { +00157 <font class="keywordflow">if</font> (currentNode.firstChild > -1) { +00158 error = getTreeNodeFromIdxOffset(currentNode.firstChild, &currentNode); +00159 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00160 } +00161 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00162 } +00163 +00164 +00165 <font class="keywordtype">bool</font> TreeKeyIdx::nextSibling() { +00166 <font class="keywordflow">if</font> (currentNode.next > -1) { +00167 error = getTreeNodeFromIdxOffset(currentNode.next, &currentNode); +00168 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00169 } +00170 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00171 } +00172 +00173 +00174 <font class="keywordtype">bool</font> TreeKeyIdx::previousSibling() { +00175 TreeNode iterator; +00176 __u32 target = currentNode.offset; +00177 <font class="keywordflow">if</font> (currentNode.parent > -1) { +00178 getTreeNodeFromIdxOffset(currentNode.parent, &iterator); +00179 getTreeNodeFromIdxOffset(iterator.firstChild, &iterator); +00180 <font class="keywordflow">if</font> (iterator.offset != target) { +00181 <font class="keywordflow">while</font> ((iterator.next != target) && (iterator.next > -1)) +00182 getTreeNodeFromIdxOffset(iterator.next, &iterator); +00183 <font class="keywordflow">if</font> (iterator.next > -1) { +00184 error = getTreeNodeFromIdxOffset(iterator.offset, &currentNode); +00185 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00186 } +00187 } +00188 } +00189 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00190 } +00191 +00192 +00193 <font class="keywordtype">bool</font> TreeKeyIdx::hasChildren() { +00194 <font class="keywordflow">return</font> (currentNode.firstChild > -1); +00195 } +00196 +00197 +00198 <font class="keywordtype">void</font> TreeKeyIdx::append() { +00199 TreeNode lastSib; +00200 <font class="keywordflow">if</font> (currentNode.offset) { +00201 getTreeNodeFromIdxOffset(currentNode.offset, &lastSib); +00202 <font class="keywordflow">while</font> (lastSib.next > -1) { +00203 getTreeNodeFromIdxOffset(lastSib.next, &lastSib); +00204 } +00205 __u32 idxOffset = lseek(idxfd->getFd(), 0, SEEK_END); +00206 lastSib.next = idxOffset; +00207 saveTreeNodeOffsets(&lastSib); +00208 __u32 parent = currentNode.parent; +00209 currentNode.clear(); +00210 currentNode.offset = idxOffset; +00211 currentNode.parent = parent; +00212 } +00213 } +00214 +00215 +00216 <font class="keywordtype">void</font> TreeKeyIdx::appendChild() { +00217 <font class="keywordflow">if</font> (firstChild()) { +00218 append(); +00219 } +00220 <font class="keywordflow">else</font> { +00221 __u32 idxOffset = lseek(idxfd->getFd(), 0, SEEK_END); +00222 currentNode.firstChild = idxOffset; +00223 saveTreeNodeOffsets(&currentNode); +00224 __u32 parent = currentNode.offset; +00225 currentNode.clear(); +00226 currentNode.offset = idxOffset; +00227 currentNode.parent = parent; +00228 } +00229 } +00230 +00231 +00232 <font class="keywordtype">void</font> TreeKeyIdx::insertBefore() { +00233 } +00234 +00235 +00236 <font class="keywordtype">void</font> TreeKeyIdx::remove() { +00237 } +00238 +00239 +00240 <font class="comment">/******************************************************************************</font> +00241 <font class="comment"> * TreeKeyIdx::Create - Creates new key idx/dat files</font> +00242 <font class="comment"> *</font> +00243 <font class="comment"> * ENT: path - directory to store module files</font> +00244 <font class="comment"> * RET: error status</font> +00245 <font class="comment"> */</font> +00246 +00247 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> TreeKeyIdx::create(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath) { +00248 <font class="keywordtype">char</font> *path = 0; +00249 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (ipath) + 20 ]; +00250 FileDesc *fd, *fd2; +00251 +00252 stdstr(&path, ipath); +00253 +00254 <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>)) +00255 path[strlen(path)-1] = 0; +00256 +00257 sprintf(buf, <font class="stringliteral">"%s.dat"</font>, path); +00258 unlink(buf); +00259 fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE); +00260 fd->getFd(); +00261 FileMgr::systemFileMgr.close(fd); +00262 +00263 sprintf(buf, <font class="stringliteral">"%s.idx"</font>, path); +00264 unlink(buf); +00265 fd2 = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE); +00266 fd2->getFd(); +00267 FileMgr::systemFileMgr.close(fd2); +00268 +00269 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> newTree(path); +00270 TreeKeyIdx::TreeNode root; +00271 stdstr(&(root.name), <font class="stringliteral">""</font>); +00272 newTree.<a class="code" href="class_tree_key_idx.html#c2">saveTreeNode</a>(&root); +00273 +00274 <font class="keyword">delete</font> [] path; +00275 +00276 <font class="keywordflow">return</font> 0; +00277 } +00278 +00279 +00280 <font class="comment">/******************************************************************************</font> +00281 <font class="comment"> * zStr::getidxbufdat - Gets the index string at the given dat offset</font> +00282 <font class="comment"> * NOTE: buf is calloc'd, or if not null, realloc'd and must</font> +00283 <font class="comment"> * be free'd by calling function</font> +00284 <font class="comment"> *</font> +00285 <font class="comment"> * ENT: ioffset - offset in dat file to lookup</font> +00286 <font class="comment"> * node - address of pointer to allocate for storage of string</font> +00287 <font class="comment"> */</font> +00288 +00289 <font class="keywordtype">void</font> TreeKeyIdx::getTreeNodeFromDatOffset(<font class="keywordtype">long</font> ioffset, TreeNode *node)<font class="keyword"> const </font>{ +00290 <font class="keywordtype">char</font> ch; +00291 __s32 tmp; +00292 __u16 tmp2; +00293 +00294 <font class="keywordflow">if</font> (datfd > 0) { +00295 +00296 lseek(datfd->getFd(), ioffset, SEEK_SET); +00297 +00298 read(datfd->getFd(), &tmp, 4); +00299 node->parent = swordtoarch32(tmp); +00300 +00301 read(datfd->getFd(), &tmp, 4); +00302 node->next = swordtoarch32(tmp); +00303 +00304 read(datfd->getFd(), &tmp, 4); +00305 node->firstChild = swordtoarch32(tmp); +00306 +00307 string name; +00308 <font class="keywordflow">do</font> { +00309 read(datfd->getFd(), &ch, 1); +00310 name += ch; +00311 } <font class="keywordflow">while</font> (ch); +00312 +00313 stdstr(&(node->name), name.c_str()); +00314 +00315 read(datfd->getFd(), &tmp2, 2); +00316 node->dsize = swordtoarch16(tmp2); +00317 +00318 <font class="keywordflow">if</font> (node->dsize) { +00319 <font class="keywordflow">if</font> (node->userData) +00320 <font class="keyword">delete</font> [] node->userData; +00321 node->userData = <font class="keyword">new</font> <font class="keywordtype">char</font> [node->dsize]; +00322 read(datfd->getFd(), node->userData, node->dsize); +00323 } +00324 } +00325 } +00326 +00327 +00328 <font class="comment">/******************************************************************************</font> +00329 <font class="comment"> * zStr::getidxbuf - Gets the index string at the given idx offset</font> +00330 <font class="comment"> * NOTE: buf is calloc'd, or if not null, realloc'd</font> +00331 <font class="comment"> * and must be freed by calling function</font> +00332 <font class="comment"> *</font> +00333 <font class="comment"> * ENT: ioffset - offset in idx file to lookup</font> +00334 <font class="comment"> * buf - address of pointer to allocate for storage of string</font> +00335 <font class="comment"> */</font> +00336 +00337 <font class="keywordtype">char</font> TreeKeyIdx::getTreeNodeFromIdxOffset(<font class="keywordtype">long</font> ioffset, TreeNode *node)<font class="keyword"> const </font>{ +00338 __u32 offset; +00339 <font class="keywordtype">char</font> error = 0; +00340 +00341 <font class="keywordflow">if</font> (ioffset < 0) { +00342 ioffset = 0; +00343 error = KEYERR_OUTOFBOUNDS; +00344 } +00345 +00346 node->offset = ioffset; +00347 <font class="keywordflow">if</font> (idxfd > 0) { +00348 lseek(idxfd->getFd(), ioffset, SEEK_SET); +00349 <font class="keywordflow">if</font> (read(idxfd->getFd(), &offset, 4) == 4) { +00350 offset = swordtoarch32(offset); +00351 getTreeNodeFromDatOffset(offset, node); +00352 } +00353 <font class="keywordflow">else</font> { +00354 lseek(idxfd->getFd(), -4, SEEK_END); +00355 <font class="keywordflow">if</font> (read(idxfd->getFd(), &offset, 4) == 4) { +00356 offset = swordtoarch32(offset); +00357 getTreeNodeFromDatOffset(offset, node); +00358 } +00359 error = KEYERR_OUTOFBOUNDS; +00360 } +00361 } +00362 <font class="keywordflow">return</font> error; +00363 } +00364 +00365 +00366 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> TreeKeyIdx::getOffset()<font class="keyword"> const </font>{ +00367 <font class="keywordflow">return</font> currentNode.offset; +00368 } +00369 +00370 <font class="keywordtype">void</font> TreeKeyIdx::setOffset(<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> offset) { +00371 error = getTreeNodeFromIdxOffset(offset, &currentNode); +00372 } +00373 +00374 +00375 <font class="keywordtype">void</font> TreeKeyIdx::saveTreeNodeOffsets(TreeNode *node) { +00376 <font class="keywordtype">long</font> datOffset = 0; +00377 __s32 tmp; +00378 +00379 <font class="keywordflow">if</font> (idxfd > 0) { +00380 lseek(idxfd->getFd(), node->offset, SEEK_SET); +00381 <font class="keywordflow">if</font> (read(idxfd->getFd(), &tmp, 4) != 4) { +00382 datOffset = lseek(datfd->getFd(), 0, SEEK_END); +00383 tmp = archtosword32(datOffset); +00384 write(idxfd->getFd(), &tmp, 4); +00385 } +00386 <font class="keywordflow">else</font> { +00387 datOffset = swordtoarch32(tmp); +00388 lseek(datfd->getFd(), datOffset, SEEK_SET); +00389 } +00390 +00391 tmp = archtosword32(node->parent); +00392 write(datfd->getFd(), &tmp, 4); +00393 +00394 tmp = archtosword32(node->next); +00395 write(datfd->getFd(), &tmp, 4); +00396 +00397 tmp = archtosword32(node->firstChild); +00398 write(datfd->getFd(), &tmp, 4); +00399 } +00400 } +00401 +00402 +00403 <font class="keywordtype">void</font> <a class="code" href="class_tree_key_idx.html#a20">TreeKeyIdx::copyFrom</a>(<font class="keyword">const</font> <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> &ikey) { +00404 +00405 <a class="code" href="class_s_w_key.html#a8">SWKey::copyFrom</a>(ikey); +00406 +00407 currentNode.offset = ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.offset; +00408 currentNode.parent = ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.parent; +00409 currentNode.next = ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.next; +00410 currentNode.firstChild = ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.firstChild; +00411 stdstr(&(currentNode.name), ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.name); +00412 currentNode.dsize = ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.dsize; +00413 +00414 <font class="keywordflow">if</font> (currentNode.userData) +00415 <font class="keyword">delete</font> [] currentNode.userData; +00416 <font class="keywordflow">if</font> (currentNode.dsize) { +00417 currentNode.userData = <font class="keyword">new</font> <font class="keywordtype">char</font> [ currentNode.dsize ]; +00418 memcpy(currentNode.userData, ikey.<a class="code" href="class_tree_key_idx.html#o0">currentNode</a>.userData, currentNode.dsize); +00419 } +00420 <font class="keywordflow">else</font> currentNode.userData = 0; +00421 +00422 <font class="keywordtype">bool</font> newFiles = <font class="keyword">true</font>; +00423 +00424 <font class="keywordflow">if</font> (path && ikey.<a class="code" href="class_tree_key_idx.html#o1">path</a>) +00425 newFiles = strcmp(path, ikey.<a class="code" href="class_tree_key_idx.html#o1">path</a>); +00426 +00427 <font class="keywordflow">if</font> (newFiles) { +00428 stdstr(&path, ikey.<a class="code" href="class_tree_key_idx.html#o1">path</a>); +00429 +00430 <font class="keywordflow">if</font> (idxfd) { +00431 FileMgr::systemFileMgr.close(idxfd); +00432 FileMgr::systemFileMgr.close(datfd); +00433 } +00434 idxfd = FileMgr::systemFileMgr.open(ikey.<a class="code" href="class_tree_key_idx.html#o2">idxfd</a>->path, ikey.<a class="code" href="class_tree_key_idx.html#o2">idxfd</a>->mode, ikey.<a class="code" href="class_tree_key_idx.html#o2">idxfd</a>->perms); +00435 datfd = FileMgr::systemFileMgr.open(ikey.<a class="code" href="class_tree_key_idx.html#o3">datfd</a>->path, ikey.<a class="code" href="class_tree_key_idx.html#o3">datfd</a>->mode, ikey.<a class="code" href="class_tree_key_idx.html#o3">datfd</a>->perms); +00436 } +00437 } +00438 +00439 +00440 <font class="keywordtype">void</font> TreeKeyIdx::saveTreeNode(TreeNode *node) { +00441 <font class="keywordtype">long</font> datOffset = 0; +00442 __s32 tmp; +00443 <font class="keywordflow">if</font> (idxfd > 0) { +00444 +00445 lseek(idxfd->getFd(), node->offset, SEEK_SET); +00446 datOffset = lseek(datfd->getFd(), 0, SEEK_END); +00447 tmp = archtosword32(datOffset); +00448 write(idxfd->getFd(), &tmp, 4); +00449 +00450 saveTreeNodeOffsets(node); +00451 +00452 write(datfd->getFd(), node->name, strlen(node->name)); +00453 <font class="keywordtype">char</font> null = 0; +00454 write(datfd->getFd(), &null, 1); +00455 +00456 __u16 tmp2 = archtosword16(node->dsize); +00457 write(datfd->getFd(), &tmp2, 2); +00458 +00459 <font class="keywordflow">if</font> (node->dsize) { +00460 write(datfd->getFd(), node->userData, node->dsize); +00461 } +00462 } +00463 } +00464 +00465 +<a name="l00466"></a><a class="code" href="class_tree_key_idx.html#a24">00466</a> <font class="keywordtype">void</font> <a class="code" href="class_tree_key_idx.html#a24">TreeKeyIdx::setText</a>(<font class="keyword">const</font> <font class="keywordtype">char</font> *ikey) { +00467 <font class="keywordtype">char</font> *buf = 0; +00468 stdstr(&buf, ikey); +00469 <font class="keywordtype">char</font> *leaf = strtok(buf, <font class="stringliteral">"/"</font>); +00470 root(); +00471 <font class="keywordflow">while</font> ((leaf) && (!<a class="code" href="class_s_w_key.html#a6">Error</a>())) { +00472 <font class="keywordtype">bool</font> ok, inChild = <font class="keyword">false</font>; +00473 <font class="keywordflow">for</font> (ok = firstChild(); ok; ok = nextSibling()) { +00474 inChild = <font class="keyword">true</font>; +00475 <font class="keywordflow">if</font> (!stricmp(leaf, getLocalName())) +00476 <font class="keywordflow">break</font>; +00477 } +00478 leaf = strtok(0, <font class="stringliteral">"/"</font>); +00479 <font class="keywordflow">if</font> (!ok) { +00480 <font class="keywordflow">if</font> (inChild) { <font class="comment">// if we didn't find a matching child node, default to first child</font> +00481 parent(); +00482 firstChild(); +00483 } +00484 <font class="keywordflow">if</font> (leaf) +00485 error = KEYERR_OUTOFBOUNDS; +00486 <font class="keywordflow">break</font>; +00487 } +00488 } +00489 <font class="keyword">delete</font> [] buf; +00490 } +00491 +00492 +00493 +<a name="l00494"></a><a class="code" href="class_tree_key_idx.html#a20">00494</a> <font class="keywordtype">void</font> <a class="code" href="class_tree_key_idx.html#a20">TreeKeyIdx::copyFrom</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &ikey) { +00495 <a class="code" href="class_s_w_key.html#a8">SWKey::copyFrom</a>(ikey); +00496 } +00497 +00498 <font class="keywordtype">void</font> TreeKeyIdx::setPosition(SW_POSITION p) { +00499 <font class="keywordflow">switch</font> (p) { +00500 <font class="keywordflow">case</font> POS_TOP: +00501 root(); +00502 <font class="keywordflow">break</font>; +00503 <font class="keywordflow">case</font> POS_BOTTOM: +00504 error = getTreeNodeFromIdxOffset(lseek(idxfd->getFd(), -4, SEEK_END), &currentNode); +00505 <font class="keywordflow">break</font>; +00506 } +00507 <a class="code" href="class_s_w_key.html#a6">Error</a>(); <font class="comment">// clear error from normalize</font> +00508 } +00509 +<a name="l00510"></a><a class="code" href="class_tree_key_idx.html#a26">00510</a> <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="class_tree_key_idx.html#a26">TreeKeyIdx::getText</a>()<font class="keyword"> const </font>{ +00511 <font class="keywordflow">return</font> getFullName(); +00512 } +00513 +00514 +00515 <font class="keywordtype">int</font> TreeKeyIdx::_compare (<font class="keyword">const</font> <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> & ikey) { +00516 <font class="keywordflow">return</font> (getOffset() - ikey.<a class="code" href="class_tree_key_idx.html#a23">getOffset</a>()); +00517 } +00518 +00519 +<a name="l00520"></a><a class="code" href="class_tree_key_idx.html#a28">00520</a> <font class="keywordtype">int</font> <a class="code" href="class_tree_key_idx.html#a28">TreeKeyIdx::compare</a>(<font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> &ikey) { +00521 <a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a> *treeKey = SWDYNAMIC_CAST(<a class="code" href="class_tree_key_idx.html">TreeKeyIdx</a>, (&ikey)); +00522 <font class="keywordflow">if</font> (treeKey) +00523 <font class="keywordflow">return</font> _compare(*treeKey); +00524 <font class="keywordflow">return</font> <a class="code" href="class_s_w_key.html#a11">SWKey::compare</a>(ikey); +00525 } +00526 +00527 +<a name="l00528"></a><a class="code" href="class_tree_key_idx.html#a29">00528</a> <font class="keywordtype">void</font> <a class="code" href="class_tree_key_idx.html#a29">TreeKeyIdx::decrement</a>(<font class="keywordtype">int</font> steps) { +00529 error = getTreeNodeFromIdxOffset(currentNode.offset - (4*steps), &currentNode); +00530 } +00531 +<a name="l00532"></a><a class="code" href="class_tree_key_idx.html#a30">00532</a> <font class="keywordtype">void</font> <a class="code" href="class_tree_key_idx.html#a30">TreeKeyIdx::increment</a>(<font class="keywordtype">int</font> steps) { +00533 error = getTreeNodeFromIdxOffset(currentNode.offset + (4*steps), &currentNode); +00534 +00535 <font class="comment">/*</font> +00536 <font class="comment"> // assert positive</font> +00537 <font class="comment"> if (steps < 0) {</font> +00538 <font class="comment"> decrement(steps * -1);</font> +00539 <font class="comment"> return;</font> +00540 <font class="comment"> }</font> +00541 <font class="comment"></font> +00542 <font class="comment"> while (steps > 0) {</font> +00543 <font class="comment"> if (!firstChild()) {</font> +00544 <font class="comment"> if (!nextSibbling() {</font> +00545 <font class="comment"> error = KEYERR_OUTOFBOUNDS;</font> +00546 <font class="comment"> return;</font> +00547 <font class="comment"> }</font> +00548 <font class="comment"> }</font> +00549 <font class="comment"> steps--;</font> +00550 <font class="comment"> }</font> +00551 <font class="comment">*/</font> +00552 } +00553 +00554 +00555 +00556 TreeKeyIdx::TreeNode::TreeNode() { +00557 +00558 name = 0; +00559 stdstr(&name, <font class="stringliteral">""</font>); +00560 userData = 0; +00561 +00562 clear(); +00563 } +00564 +00565 +00566 <font class="keywordtype">void</font> TreeKeyIdx::TreeNode::clear() { +00567 offset = 0; +00568 parent = -1; +00569 next = -1; +00570 firstChild = -1; +00571 dsize = 0; +00572 +00573 <font class="keywordflow">if</font> (name) +00574 <font class="keyword">delete</font> [] name; +00575 name = 0; +00576 stdstr(&name, <font class="stringliteral">""</font>); +00577 +00578 <font class="keywordflow">if</font> (userData) +00579 <font class="keyword">delete</font> [] userData; +00580 userData = 0; +00581 } +00582 +00583 +00584 TreeKeyIdx::TreeNode::~TreeNode() { +00585 <font class="keywordflow">if</font> (name) +00586 <font class="keyword">delete</font> [] name; +00587 +00588 <font class="keywordflow">if</font> (userData) +00589 <font class="keyword">delete</font> [] userData; +00590 } +</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by +<a href="http://www.doxygen.org/index.html"> +<img src="doxygen.png" alt="doxygen" align="middle" border=0 +width=110 height=53></a>1.2.15 </small></address> +</body> +</html> |