📄 dom2_traversalimpl.cpp
字号:
/** * This file is part of the DOM implementation for KDE. * * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: dom2_traversalimpl.cpp,v 1.1.1.1 2002/01/16 10:39:55 ymwei Exp $ */#include "dom2_traversal.h"#include "dom_node.h"#include "dom_exception.h"#include "dom2_traversalimpl.h"using namespace DOM;NodeIteratorImpl::NodeIteratorImpl(){ filter = 0;}NodeIteratorImpl::NodeIteratorImpl(const NodeIteratorImpl &other) : DomShared(other){ referenceNode = other.referenceNode; rootNode = other.rootNode; whatToShow = other.whatToShow; filter = other.filter; inFront = other.inFront; expandEntityReferences = other.expandEntityReferences;}NodeIteratorImpl::NodeIteratorImpl(Node n, NodeFilter *f){ if( !n.isNull() ) { rootNode = n; referenceNode = n; whatToShow = 0x0000FFFF; filter = f; } else throw DOMException(DOMException::NOT_FOUND_ERR); // ### should we go into an invalid state instead?}NodeIteratorImpl::NodeIteratorImpl(Node n, long _whatToShow , NodeFilter *f){ filter = f; whatToShow = _whatToShow; referenceNode = n; rootNode = n;}NodeIteratorImpl &NodeIteratorImpl::operator = (const NodeIteratorImpl &other){ referenceNode = other.referenceNode; rootNode = other.rootNode; whatToShow = other.whatToShow; filter = other.filter; inFront = other.inFront; expandEntityReferences = other.expandEntityReferences; return *this;}NodeIteratorImpl::~NodeIteratorImpl(){ if(filter) { delete filter; filter = 0; }}void NodeIteratorImpl::setWhatToShow(long _whatToShow){ whatToShow = _whatToShow;}void NodeIteratorImpl::moveReferenceNode(Node n){ if( !n.isNull() ) { // cheching if they are in the same subtree?? referenceNode = n; inFront = true; }}void NodeIteratorImpl::setReferenceNode(Node n){ if( !n.isNull() ) { rootNode = n; referenceNode = n; inFront = true; }}void NodeIteratorImpl::setFilter(NodeFilter *_filter){ if(_filter != 0) { if( filter != 0 ) delete filter; filter = _filter; }}void NodeIteratorImpl::setExpandEntityReferences(bool value){ expandEntityReferences = value;}Node NodeIteratorImpl::getRoot(){ // ### return 0;}unsigned long NodeIteratorImpl::getWhatToShow(){ // ### return 0;}NodeFilter NodeIteratorImpl::getFilter(){ // ### return NodeFilter();}bool NodeIteratorImpl::getExpandEntityReferences(){ // ### return 0;}Node NodeIteratorImpl::nextNode( ){ short _result; Node _tempCurrent = getNextNode(referenceNode); while( !_tempCurrent.isNull() ) { _result = isAccepted(_tempCurrent); if(_result == NodeFilter::FILTER_ACCEPT) { referenceNode = _tempCurrent; return referenceNode; } _tempCurrent = getNextNode(_tempCurrent); } return Node();}Node NodeIteratorImpl::getNextNode(Node n){ /* 1. my first child * 2. my next sibling * 3. my parents sibling, or their parents sibling (loop) * 4. not found */ if( n.isNull() ) return n; inFront = true; if( n.hasChildNodes() ) return n.firstChild(); if( !n.nextSibling().isNull() ) return n.nextSibling(); if( rootNode == n) return Node(); Node parent = n.parentNode(); while( !parent.isNull() ) { n = parent.nextSibling(); if( !n.isNull() ) return n; if( rootNode == parent ) return Node(); parent = parent.parentNode(); } return Node();}Node NodeIteratorImpl::previousNode( ){ short _result; Node _tempCurrent = getPreviousNode(referenceNode); while( !_tempCurrent.isNull() ) { _result = isAccepted(_tempCurrent); if(_result == NodeFilter::FILTER_ACCEPT) { referenceNode = _tempCurrent; return referenceNode; } _tempCurrent = getPreviousNode(_tempCurrent); } return Node();}Node NodeIteratorImpl::getPreviousNode(Node n){/* 1. my previous sibling.lastchild * 2. my previous sibling * 3. my parent */ Node _tempCurrent; if( n.isNull() ) return Node(); inFront = false; _tempCurrent = n.previousSibling(); if( !_tempCurrent.isNull() ) { if( _tempCurrent.hasChildNodes() ) { while( _tempCurrent.hasChildNodes() ) _tempCurrent = _tempCurrent.lastChild(); return _tempCurrent; } else return _tempCurrent; } if(n == rootNode) return Node(); return n.parentNode();}void NodeIteratorImpl::detach(){}void NodeIteratorImpl::deleteNode(Node n){ if( n.isNull() ) return; // someone tried to delete a null node :) Node _tempDeleted = referenceNode; while( !_tempDeleted.isNull() && _tempDeleted != n) // did I get deleted, or one of my parents? _tempDeleted = _tempDeleted.parentNode(); if( _tempDeleted.isNull() ) // someone that did consern me got deleted return; if( !inFront) { Node _next = getNextNode(_tempDeleted); if( !_next.isNull() ) referenceNode = _next; else { inFront = false; referenceNode = getPreviousNode(_tempDeleted); return; } } referenceNode = getPreviousNode(_tempDeleted);}short NodeIteratorImpl::isAccepted(Node n){ // if XML is implemented we have to check expandEntityRerefences in this function if( ( ( 1 << n.nodeType()-1) & whatToShow) != 0 ) { if(filter) return filter->acceptNode(n); else return NodeFilter::FILTER_ACCEPT; } return NodeFilter::FILTER_SKIP;}// --------------------------------------------------------------NodeFilterImpl::NodeFilterImpl(){}NodeFilterImpl::~NodeFilterImpl(){}short NodeFilterImpl::acceptNode(const Node &){ return NodeFilter::FILTER_ACCEPT;}// --------------------------------------------------------------TreeWalkerImpl::TreeWalkerImpl(){ filter = 0; whatToShow = 0x0000FFFF; expandEntityReferences = true;}TreeWalkerImpl::TreeWalkerImpl(const TreeWalkerImpl &other) : DomShared(){ expandEntityReferences = other.expandEntityReferences; filter = other.filter; whatToShow = other.whatToShow; currentNode = other.currentNode; rootNode = other.rootNode;}TreeWalkerImpl::TreeWalkerImpl(Node n, NodeFilter *f){ currentNode = n; rootNode = n; whatToShow = 0x0000FFFF; filter = f;}TreeWalkerImpl::TreeWalkerImpl(Node n, long _whatToShow, NodeFilter *f){ currentNode = n; rootNode = n; whatToShow = _whatToShow; filter = f;}TreeWalkerImpl &TreeWalkerImpl::operator = (const TreeWalkerImpl &other){ expandEntityReferences = other.expandEntityReferences; filter = other.filter; whatToShow = other.whatToShow; currentNode = other.currentNode; return *this;}TreeWalkerImpl::~TreeWalkerImpl()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -