00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "bufferiterator.h"
00036
00037 BufferIterator::BufferIterator(BufferNode * _base, PathExpression * _path):
00038 base(_base), cur(_base), cur_old(NULL), cur_locked(false),
00039 path(_path), spp(StreamPreProcessor::getInstance()), ps_index(0) {
00040 if (!path) {
00041 return;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050 if ((path->hasInnerTextNodeTest()
00051 && !path->getPathStepAfterTextNodeTest()->isDosNodeStep())
00052 || (base->type == TYPE_PCDATA
00053 && !path->getPathStepAt(0)->isDosNodeStep())) {
00054 cur = NULL;
00055 }
00056
00057 for (unsigned i = 0; i < _path->getPathSize(); i++) {
00058
00059
00060
00061 ps_context.push_back(NULL);
00062
00063
00064
00065
00066
00067
00068
00069 ps_context_position.push_back(0);
00070
00071
00072
00073
00074
00075
00076
00077
00078 if (i == 0 && path->getPathStepAt(i)->getAxisType() == at_child) {
00079 ps_skip_subtree.push_back(true);
00080 } else if (!path->hasPreviousDescendantOrDosUpTo(i) &&
00081 path->getPathStepAt(i)->getAxisType() == at_child) {
00082 ps_skip_subtree.push_back(true);
00083 } else {
00084 ps_skip_subtree.push_back(false);
00085 }
00086
00087
00088
00089
00090
00091
00092
00093 if (path->getPathStepAt(i)->hasAttribute()) {
00094 ps_attribute.push_back(true);
00095 switch (path->getPathStepAt(i)->getAttribute()->getType()) {
00096 case at_position:
00097 ps_attribute_position.
00098 push_back(((PathStepAttributePosition *) path->
00099 getPathStepAt(i)->getAttribute())->
00100 getPosition());
00101 break;
00102 }
00103 } else {
00104 ps_attribute.push_back(false);
00105 ps_attribute_position.push_back(0);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 if (i > 0 && ps_back_track[i - 1]
00123 && path->getPathStepAt(i)->getAxisType() == at_child) {
00124 ps_back_track.push_back(true);
00125 } else if (i > 1
00126 && path->getPathStepAt(i - 2)->getAxisType() != at_child
00127 && path->getPathStepAt(i - 1)->getAxisType() == at_child
00128 && path->getPathStepAt(i)->getAxisType() == at_child) {
00129 ps_back_track.push_back(true);
00130 } else {
00131 ps_back_track.push_back(false);
00132 }
00133 }
00134 }
00135
00136 BufferIterator::~BufferIterator() {
00137 }
00138
00139 void BufferIterator::init(BufferNode * _base) {
00140 base = _base;
00141 cur = _base;
00142 cur_old = NULL;
00143 cur_locked = false;
00144 ps_index = 0;
00145
00146 if (!path) {
00147 return;
00148 }
00149
00150 if ((path->hasInnerTextNodeTest()
00151 && !path->getPathStepAfterTextNodeTest()->isDosNodeStep())
00152 || (_base->type == TYPE_PCDATA
00153 && !path->getPathStepAt(0)->isDosNodeStep())) {
00154 cur = NULL;
00155 }
00156 }
00157
00158 void BufferIterator::debugPrint(OutputStream & dos, unsigned debug_mode) {
00159 vector < PathStepExpression * >*ps = NULL;
00160 if (path) {
00161 dos << "path=" << (*path) << NEWLINE;
00162 ps = path->getPathSteps();
00163 dos << "path_process=";
00164 for (unsigned i = 0; i < ps->size(); i++) {
00165 dos << (*path->getPathStepAt(i)) << "[" << ps_context_position[i];
00166 if (ps_attribute_position[i] > 0) {
00167 dos << " <= " << ps_attribute_position[i];
00168 }
00169 dos << "]";
00170 if (debug_mode == BIT_DEBUG_MODE_FULL
00171 || debug_mode == BIT_DEBUG_MODE_PARTIAL) {
00172 dos << " [";
00173 if (ps_attribute[i]) {
00174 dos << "attribute=true";
00175 } else {
00176 dos << "attribute=false";
00177 }
00178 dos << "; ";
00179 if (ps_skip_subtree[i]) {
00180 dos << "skip_subtree=true";
00181 } else {
00182 dos << "skip_subtree=false";
00183 }
00184 dos << "; ";
00185 if (ps_back_track[i]) {
00186 dos << "back_track=true";
00187 } else {
00188 dos << "back_track=false";
00189 }
00190 dos << "] ";
00191 } else {
00192 dos << " ";
00193 }
00194 if (i == ps_index) {
00195 dos << "{*processed*} ";
00196 }
00197 }
00198 }
00199 dos << NEWLINE << "base ";
00200 if (base) {
00201 if (base->type == TYPE_TAG) {
00202 dos << "[TAG] => ";
00203 } else {
00204 dos << "[#PCDATA] => ";
00205 }
00206 if (debug_mode == BIT_DEBUG_MODE_FULL && !base->isRoot()) {
00207 base->debugPrint(dos);
00208 } else {
00209 base->printNoSubnodes(dos);
00210 }
00211 } else {
00212 dos << "[NONE] => NULL";
00213 }
00214 if (path) {
00215 for (unsigned i = 0; i < ps->size(); i++) {
00216 dos << NEWLINE << "step=[" << i << "] ";
00217 if (ps_context[i]) {
00218 if (ps_context[i]->type == TYPE_TAG) {
00219 dos << "[TAG] => ";
00220 } else {
00221 dos << "[#PCDATA] => ";
00222 }
00223 if (debug_mode == BIT_DEBUG_MODE_FULL
00224 && !ps_context[i]->isRoot()) {
00225 ps_context[i]->debugPrint(dos);
00226 } else {
00227 ps_context[i]->printNoSubnodes(dos);
00228 }
00229 } else {
00230 dos << "[NONE] => NULL";
00231 }
00232 }
00233 }
00234 dos << NEWLINE << NEWLINE << "cur (previous returned node) ";
00235 if (cur_old) {
00236 if (cur_old->type == TYPE_TAG) {
00237 dos << "[TAG] => ";
00238 } else {
00239 dos << "[#PCDATA] => ";
00240 }
00241 if (debug_mode == BIT_DEBUG_MODE_FULL && !cur_old->isRoot()) {
00242 cur_old->debugPrint(dos);
00243 } else {
00244 cur_old->printNoSubnodes(dos);
00245 }
00246 } else {
00247 dos << "[NONE] => NULL";
00248 }
00249 dos << NEWLINE << "cur (returned node) ";
00250 if (cur) {
00251 if (cur_locked) {
00252 dos << "[bit locked] ";
00253 } else {
00254 dos << "[bit not locked] ";
00255 }
00256 if (cur->type == TYPE_TAG) {
00257 dos << "[TAG] => ";
00258 } else {
00259 dos << "[#PCDATA] => ";
00260 }
00261 if (debug_mode == BIT_DEBUG_MODE_FULL && !cur->isRoot()) {
00262 cur->debugPrint(dos);
00263 } else {
00264 cur->printNoSubnodes(dos);
00265 }
00266 } else {
00267 dos << "[NONE] => NULL";
00268 }
00269 }
00270
00271 BufferNode *BufferIterator::getNext(unsigned read_up_to_closing,
00272 unsigned lock_node) {
00273 if (cur == NULL) {
00274 return NULL;
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 if (path) {
00291 BufferNode *nnode = cur;
00292
00293 while ((bool) (nnode = isSatisfyingPath(nnode))) {
00294 if (nnode->type == TYPE_TAG) {
00295 while (((TagNode *) nnode->node)->children.isEmpty()
00296 && !nnode->isClosed()) {
00297 spp->readNext();
00298 }
00299 if (!((TagNode *) nnode->node)->children.isEmpty()) {
00300 nnode = ((TagNode *) nnode->node)->children[0];
00301 } else {
00302 while (nnode->r_sibling == NULL && nnode->parent
00303 && !nnode->parent->isClosed()) {
00304 spp->readNext();
00305 }
00306 while (nnode->r_sibling == NULL && nnode != base) {
00307 unsignPSNode(nnode);
00308 nnode = nnode->parent;
00309 while (nnode->r_sibling == NULL && nnode->parent
00310 && !nnode->parent->isClosed()) {
00311 spp->readNext();
00312 }
00313 }
00314 unsignPSNode(nnode);
00315 if (nnode == base) {
00316 nnode = NULL;
00317 } else {
00318 nnode = nnode->r_sibling;
00319 }
00320 }
00321 } else {
00322 while (nnode->r_sibling == NULL && nnode->parent
00323 && !nnode->parent->isClosed()) {
00324 spp->readNext();
00325 }
00326 while (nnode->r_sibling == NULL && nnode != base) {
00327 unsignPSNode(nnode);
00328 nnode = nnode->parent;
00329 while (nnode->r_sibling == NULL && nnode->parent
00330 && !nnode->parent->isClosed()) {
00331 spp->readNext();
00332 }
00333 }
00334 unsignPSNode(nnode);
00335 if (nnode == base) {
00336 nnode = NULL;
00337 } else {
00338 nnode = nnode->r_sibling;
00339 }
00340 }
00341 }
00342
00343
00344
00345 BufferNode *cur_old_tmp = cur_old;
00346
00347 cur_old = cur;
00348
00349
00350
00351
00352
00353 cur = ps_context[ps_index];
00354
00355
00356
00357 if (cur == NULL) {
00358 ps_context_position[ps_index] = 0;
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 if (read_up_to_closing == READ_UP_TO_CLOSE_BASE && base
00377 && base->type == TYPE_TAG) {
00378 while (!base->isClosed()) {
00379 spp->readNext();
00380 }
00381 } else if (read_up_to_closing == READ_UP_TO_CLOSE_CONTEXT && cur
00382 && cur->type == TYPE_TAG) {
00383 while (!cur->isClosed()) {
00384 spp->readNext();
00385 }
00386 }
00387
00388
00389 if (lock_node != LOCK_NONE_NO_CLEAR) {
00390 bool externally_locked = true;
00391 bool cur_locked_tmp = cur_locked;
00392
00393 cur_locked = false;
00394 if (cur) {
00395 externally_locked = cur->isLocked();
00396 if (!externally_locked) {
00397 cur->lock();
00398 cur_locked = true;
00399 }
00400 if (cur_old_tmp && cur_locked_tmp) {
00401 cur_old->unlock();
00402 if (lock_node == LOCK_CONTEXT_ALWAYS_CLEAR) {
00403 cur_old->clear();
00404 }
00405 }
00406 } else {
00407 if (lock_node != LOCK_CONTEXT_NO_CLEAR) {
00408 if (cur_old_tmp && cur_locked_tmp) {
00409 cur_old->unlock();
00410 cur_old->clear();
00411 }
00412 }
00413 }
00414 }
00415
00416 return cur;
00417 } else {
00418
00419 if ((read_up_to_closing == READ_UP_TO_CLOSE_BASE
00420 || read_up_to_closing == READ_UP_TO_CLOSE_CONTEXT) && base
00421 && base->type == TYPE_TAG) {
00422 while (!base->isClosed()) {
00423 spp->readNext();
00424 }
00425 }
00426
00427 cur = NULL;
00428 return base;
00429 }
00430 }
00431
00432 void BufferIterator::reset() {
00433
00434 cur = base;
00435 cur_old = NULL;
00436 cur_locked = false;
00437 ps_index = 0;
00438
00439 if (!path) {
00440 return;
00441 }
00442
00443 if ((path->hasInnerTextNodeTest()
00444 && !path->getPathStepAfterTextNodeTest()->isDosNodeStep())
00445 || (base->type == TYPE_PCDATA
00446 && !path->getPathStepAt(0)->isDosNodeStep())) {
00447 cur = NULL;
00448 }
00449
00450 for (unsigned i = 0; i < path->getPathSize(); i++) {
00451 ps_context[i] = NULL;
00452 ps_context_position[i] = 0;
00453 }
00454 }
00455
00456 void BufferIterator::clear() {
00457
00458 }
00459
00460 BufferNode *BufferIterator::isSatisfyingPath(BufferNode * nnode) {
00461 bool match = false;
00462
00463 if (nnode == cur) {
00464 return nnode;
00465 }
00466
00467 if (nnode) {
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500 if (cur
00501 &&
00502 ((ps_index > 0
00503 && path->getPathStepAt(ps_index - 1)->getAxisType() != at_child
00504 && path->getPathStepAt(ps_index)->getAxisType() == at_child
00505 && (ps_index + 1) < path->getPathSize()
00506 && path->getPathStepAt(ps_index + 1)->getAxisType() == at_child)
00507 || ps_back_track[ps_index])) {
00508
00509
00510 unsigned ps_index_first_back_track = ps_index;
00511
00512 while (ps_back_track[ps_index_first_back_track]) {
00513 ps_index_first_back_track--;
00514 }
00515
00516 unsigned ps_index_last_back_track = ps_index_first_back_track;
00517
00518 ps_index_last_back_track++;
00519 while (ps_back_track[ps_index_last_back_track]
00520 && ps_index_last_back_track < path->getPathSize()) {
00521 ps_index_last_back_track++;
00522 }
00523 ps_index_last_back_track = ps_index_last_back_track - 1;
00524
00525
00526
00527
00528 if (isMatchingNodeTestAndPredicates(nnode, ps_index_last_back_track)
00529 && ps_index != ps_index_last_back_track) {
00530 BufferNode *nnode_tmp = nnode;
00531 bool match_tmp = true;
00532
00533
00534 unsigned ps_index_tmp = ps_index_last_back_track;
00535
00536
00537 stack < BufferNode * >st_ancestors = stack < BufferNode * >();
00538
00539
00540
00541 while (nnode_tmp
00542 && ps_index_tmp > (ps_index_first_back_track - 1)
00543 && match_tmp) {
00544 if (nnode_tmp->parent) {
00545 nnode_tmp = (nnode_tmp->parent->isRoot()
00546 || nnode_tmp ==
00547 ps_context[ps_index_first_back_track -
00548 1]) ? NULL : nnode_tmp->parent;
00549 if (nnode_tmp) {
00550 st_ancestors.push(nnode_tmp);
00551 ps_index_tmp--;
00552 if (!isMatchingNodeTestAndPredicates
00553 (nnode_tmp, ps_index_tmp)) {
00554 match_tmp = false;
00555 ps_index_tmp = ps_index_last_back_track;
00556 }
00557 } else {
00558 match_tmp = false;
00559 ps_index_tmp = ps_index_last_back_track;
00560 }
00561 } else {
00562 nnode_tmp = nnode_tmp->parent;
00563 }
00564 }
00565
00566
00567
00568 if (ps_index_tmp == (ps_index_first_back_track - 1)) {
00569
00570
00571 BufferNode *cur_old = cur;
00572 bool ps_backtrack_reset;
00573
00574 ps_index = ps_index_first_back_track;
00575 unsigned ps_index_old = ps_index;
00576
00577 st_ancestors.pop();
00578 while (!st_ancestors.empty()) {
00579 ps_backtrack_reset = false;
00580
00581 if (ps_back_track[ps_index]) {
00582 ps_back_track[ps_index] = false;
00583 ps_backtrack_reset = true;
00584 }
00585
00586 cur_old = cur;
00587 cur = NULL;
00588
00589 ps_index_old = ps_index;
00590
00591 nnode_tmp = isSatisfyingPath(st_ancestors.top());
00592
00593 if (ps_backtrack_reset) {
00594 ps_back_track[ps_index_old] = true;
00595 }
00596
00597 cur = cur_old;
00598
00599 st_ancestors.pop();
00600 }
00601
00602
00603 st_ancestors = stack < BufferNode * >();
00604 if (nnode_tmp == NULL) {
00605 if (ps_index >= path->getPathSize()) {
00606 ps_index--;
00607 }
00608 return NULL;
00609 }
00610 }
00611
00612 st_ancestors = stack < BufferNode * >();
00613 }
00614 }
00615
00616 switch (path->getPathStepAt(ps_index)->getAxisType()) {
00617 case at_child:
00618 if (ps_index > 0
00619 && path->getPathStepAt(ps_index - 1)->getAxisType() !=
00620 at_child
00621 && path->getPathStepAt(ps_index)->getAxisType() ==
00622 at_child) {
00623 if (isMatchingNodeTestAndPredicates(nnode, ps_index)
00624 && isMatchingNodeTestAndPredicates(nnode->parent,
00625 (ps_index - 1))) {
00626
00627 if (nnode->parent != getPrevPSNode()) {
00628
00629
00630 ps_context_position[ps_index - 1] =
00631 (ps_context_position[ps_index - 1] + 1);
00632
00633
00634
00635 ps_context_position[ps_index] = 0;
00636 }
00637
00638
00639 ps_context[ps_index] = NULL;
00640 match = true;
00641 }
00642 } else {
00643 if (isMatchingNodeTestAndPredicates(nnode, ps_index)
00644 && nnode->parent == getPrevPSNode()) {
00645 match = true;
00646 }
00647 }
00648 break;
00649 case at_descendant:
00650 if (isMatchingNodeTestAndPredicates(nnode, ps_index)) {
00651 match = true;
00652 }
00653 break;
00654 case at_dos:
00655 if (isMatchingNodeTestAndPredicates(nnode, ps_index)) {
00656 match = true;
00657 }
00658 break;
00659 }
00660 }
00661
00662 BufferNode *pnode = nnode;
00663
00664 if (match) {
00665 ps_context[ps_index] = nnode;
00666 ps_context_position[ps_index] = (ps_context_position[ps_index] + 1);
00667 ps_index++;
00668
00669
00670
00671 while (ps_index < path->getPathSize()
00672 && path->getPathStepAt(ps_index)->getAxisType() == at_dos
00673 && isMatchingNodeTestAndPredicates(nnode, ps_index)) {
00674 ps_context[ps_index] = nnode;
00675 ps_context_position[ps_index] = (ps_context_position[ps_index] + 1);
00676 ps_index++;
00677 }
00678 } else if ((nnode && ps_back_track[ps_index]
00679 && (nnode->parent == getPrevPSNode()
00680 || (nnode->parent
00681 && nnode->parent->parent == getPrevPSNode())))) {
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 bool process_backtrack = false;
00712
00713 if (nnode->parent && nnode->parent->parent == getPrevPSNode()) {
00714 process_backtrack = true;
00715 } else if (nnode->type == TYPE_TAG) {
00716 while (((TagNode *) nnode->node)->children.isEmpty()
00717 && !nnode->isClosed()) {
00718 spp->readNext();
00719 }
00720
00721 if (!((TagNode *) nnode->node)->children.isEmpty()) {
00722 process_backtrack = true;
00723 }
00724 }
00725
00726 if (process_backtrack) {
00727
00728
00729
00730 ps_context[ps_index] = NULL;
00731 ps_context_position[ps_index] = 0;
00732
00733
00734
00735 stack < BufferNode * >st_ancestors = stack < BufferNode * >();
00736
00737
00738 st_ancestors.push(nnode);
00739
00740
00741
00742
00743 if (nnode->parent && nnode->parent->parent == getPrevPSNode()) {
00744 nnode = nnode->parent;
00745
00746
00747 st_ancestors.push(nnode);
00748 }
00749
00750
00751
00752
00753
00754 ps_index--;
00755
00756
00757
00758
00759
00760
00761
00762 while (ps_back_track[ps_index]) {
00763 ps_context[ps_index] = NULL;
00764 ps_context_position[ps_index] = 0;
00765 ps_index--;
00766 nnode = nnode->parent;
00767 st_ancestors.push(nnode);
00768 }
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782 stack < BufferNode * >st_ancestors_cpy =
00783 stack < BufferNode * >(st_ancestors);
00784
00785
00786
00787
00788 unsigned ps_index_old = ps_index;
00789 unsigned ps_index_desc = ps_index;
00790
00791
00792
00793
00794 bool ps_backtrack_reset;
00795
00796
00797
00798
00799
00800 BufferNode *cur_old = cur;
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816 while (!st_ancestors.empty()) {
00817
00818
00819
00820 ps_backtrack_reset = false;
00821 if (ps_back_track[ps_index]) {
00822 ps_back_track[ps_index] = false;
00823 ps_backtrack_reset = true;
00824 }
00825
00826 cur_old = cur;
00827 cur = NULL;
00828
00829 ps_index_old = ps_index;
00830
00831 nnode = isSatisfyingPath(st_ancestors.top());
00832
00833
00834 if (ps_backtrack_reset) {
00835 ps_back_track[ps_index_old] = true;
00836 }
00837
00838 cur = cur_old;
00839
00840 if (nnode == NULL) {
00841 if (ps_index >= path->getPathSize()) {
00842 ps_index--;
00843 }
00844
00845 st_ancestors = stack < BufferNode * >();
00846 st_ancestors_cpy = stack < BufferNode * >();
00847 return NULL;
00848 } else if (ps_index_old < ps_index) {
00849 st_ancestors.pop();
00850 if (!ps_back_track[ps_index_old]) {
00851 st_ancestors_cpy.pop();
00852 }
00853 } else {
00854 if (!ps_back_track[ps_index]) {
00855 st_ancestors_cpy.pop();
00856 }
00857 st_ancestors = stack < BufferNode * >(st_ancestors_cpy);
00858 for (unsigned i = ps_index_desc; i < ps_index; i++) {
00859 ps_context[i] = NULL;
00860 ps_context_position[i] = 0;
00861 }
00862 ps_index = ps_index_desc;
00863 }
00864 }
00865
00866
00867 st_ancestors = stack < BufferNode * >();
00868 st_ancestors_cpy = stack < BufferNode * >();
00869
00870
00871
00872
00873 }
00874 } else if (nnode && ps_skip_subtree[ps_index]) {
00875
00876
00877
00878
00879
00880 bool ps_first_assigned = false;
00881 bool ps_first_null = false;
00882
00883 while (ps_index >= 0 && ps_index < path->getPathSize()
00884 && ps_skip_subtree[ps_index] && !ps_first_null) {
00885 BufferNode *tmp = NULL;
00886
00887 if (ps_context[ps_index]) {
00888 tmp = ps_context[ps_index];
00889 } else if (nnode->parent == getPrevPSNode()) {
00890 tmp = nnode;
00891 } else if (nnode->parent
00892 && nnode->parent->parent == getPrevPSNode()) {
00893 tmp = nnode->parent;
00894 } else {
00895 BufferNode *nnode_tmp = getPrevPSNode();
00896
00897 if (nnode_tmp->type == TYPE_TAG) {
00898 while (((TagNode *) nnode_tmp->node)->children.isEmpty()
00899 && !nnode_tmp->isClosed()) {
00900 spp->readNext();
00901 }
00902 if (!((TagNode *) nnode_tmp->node)->children.isEmpty()) {
00903 tmp = ((TagNode *) nnode_tmp->node)->children[0];
00904 }
00905 }
00906
00907 if (ps_index == 0 && ps_first_assigned) {
00908 tmp = NULL;
00909 }
00910 }
00911
00912 if (ps_index == 0) {
00913 ps_first_assigned = true;
00914 }
00915
00916 if (tmp) {
00917
00918
00919 while (tmp && (tmp == ps_context[ps_index]
00920 || !isMatchingNodeTestAndPredicates(tmp,
00921 ps_index))) {
00922 while (tmp->r_sibling == NULL && tmp->parent
00923 && !tmp->parent->isClosed()) {
00924 spp->readNext();
00925 }
00926 tmp = tmp->r_sibling;
00927 }
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940 if (tmp && tmp != ps_context[ps_index]
00941 && isMatchingNodeTestAndPredicates(tmp, ps_index)) {
00942 ps_context[ps_index] = tmp;
00943 ps_context_position[ps_index] =
00944 (ps_context_position[ps_index] + 1);
00945 ps_index++;
00946 pnode = tmp;
00947 } else {
00948 ps_context[ps_index] = NULL;
00949 ps_context_position[ps_index] = 0;
00950 if (ps_index == 0 && ps_first_assigned) {
00951 ps_first_null = true;
00952 }
00953 if (ps_index > 0) {
00954 ps_index--;
00955 }
00956 }
00957 } else {
00958 ps_context[ps_index] = NULL;
00959 ps_context_position[ps_index] = 0;
00960 if (ps_index == 0 && ps_first_assigned) {
00961 ps_first_null = true;
00962 }
00963 if (ps_index > 0) {
00964 ps_index--;
00965 }
00966 }
00967 }
00968
00969 if (ps_first_null) {
00970 return NULL;
00971 }
00972 }
00973
00974
00975 if (ps_index >= path->getPathSize()) {
00976 ps_index--;
00977 return NULL;
00978 }
00979
00980 return pnode;
00981 }
00982
00983 bool BufferIterator::isMatchingNodeTestAndPredicates(BufferNode * nnode,
00984 unsigned ps_idx) {
00985 if (nnode && ps_idx >= 0 && ps_idx < path->getPathSize()) {
00986 switch (path->getPathStepAt(ps_idx)->getNodeTestType()) {
00987 case ntt_tag:
00988 if (nnode->type == TYPE_TAG) {
00989 return (path->getPathStepAt(ps_idx)->
00990 isMatchingTag(((TagNode *) nnode->node)->tag)
00991 && (!ps_attribute[ps_idx]
00992 || ps_context_position[ps_idx] <=
00993 ps_attribute_position[ps_idx]));
00994 }
00995 return false;
00996 case ntt_star:
00997 return (nnode->type == TYPE_TAG && (!ps_attribute[ps_idx]
00998 ||
00999 ps_context_position[ps_idx]
01000 <=
01001 ps_attribute_position
01002 [ps_idx]));
01003 case ntt_node:
01004 return ((nnode->type == TYPE_TAG || nnode->type == TYPE_PCDATA)
01005 && (!ps_attribute[ps_idx]
01006 || ps_context_position[ps_idx] <=
01007 ps_attribute_position[ps_idx]));
01008 case ntt_text:
01009 return (nnode->type == TYPE_PCDATA && (!ps_attribute[ps_idx]
01010 ||
01011 ps_context_position
01012 [ps_idx] <=
01013 ps_attribute_position
01014 [ps_idx]));
01015 }
01016 }
01017
01018 return false;
01019 }
01020
01021 BufferNode *BufferIterator::getPrevPSNode() {
01022 return (ps_index == 0) ? base : ps_context[ps_index - 1];
01023 }
01024
01025 void BufferIterator::unsignPSNode(BufferNode * nnode) {
01026 if (nnode) {
01027 if (nnode == ps_context[ps_index]) {
01028
01029
01030
01031
01032
01033 ps_context[ps_index] = NULL;
01034 }
01035 if (ps_index > 0 && nnode == ps_context[ps_index - 1]) {
01036
01037
01038
01039
01040 ps_context_position[ps_index] = 0;
01041 ps_context[ps_index - 1] = NULL;
01042 ps_index--;
01043 }
01044 }
01045 }