GME  13
DOMChildNode.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: DOMChildNode.cpp 471747 2006-11-06 14:31:56Z amassari $
00020  */
00021 
00022 // This class only adds the ability to have siblings
00023 
00024 #include <xercesc/util/XercesDefs.hpp>
00025 #include "DOMNodeImpl.hpp"
00026 #include "DOMChildNode.hpp"
00027 #include "DOMCasts.hpp"
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 
00032 DOMChildNode::DOMChildNode()
00033 {
00034     this->previousSibling  = 0;
00035     this->nextSibling  = 0;
00036 }
00037 
00038 // This only makes a shallow copy, cloneChildren must also be called for a
00039 // deep clone
00040 DOMChildNode::DOMChildNode(const DOMChildNode &)
00041 {
00042     // Need to break the association w/ original siblings and parent
00043     this->previousSibling = 0;
00044     this->nextSibling = 0;
00045 }
00046 
00047 DOMChildNode::~DOMChildNode() {
00048 }
00049 
00050 
00051 DOMNode * DOMChildNode::getNextSibling() const {
00052     return nextSibling;
00053 }
00054 
00055 //
00056 //  Note:  for getParentNode and getPreviousSibling(), below, an
00057 //         extra paramter "thisNode" is required.  This is because there
00058 //         is no way to cast from a DOMChildNode pointer back to the
00059 //         DOMNodeImpl that it is part of.  Our "this" may or may not
00060 //         be preceded by a fParent in the object layout, and there's no
00061 //         practical way to tell, so we just take an extra parameter instead.
00062 
00063 DOMNode * DOMChildNode::getParentNode(const DOMNode *thisNode) const
00064 {
00065     // if we have an owner, ownerNode is our parent, otherwise it's
00066     // our ownerDocument and we don't have a parent
00067     DOMNodeImpl *thisNodeImpl = castToNodeImpl(thisNode);
00068     return thisNodeImpl->isOwned() ? thisNodeImpl->fOwnerNode : 0;
00069 }
00070 
00071 DOMNode * DOMChildNode::getPreviousSibling(const DOMNode *thisNode) const {
00072     // if we are the firstChild, previousSibling actually refers to our
00073     // parent's lastChild, but we hide that
00074     return castToNodeImpl(thisNode)->isFirstChild() ? 0 : previousSibling;
00075 }
00076 
00077 XERCES_CPP_NAMESPACE_END
00078