00001 #ifndef DOMSPtr_HEADER_GUARD_
00002 #define DOMSPtr_HEADER_GUARD_
00003
00004 /*
00005 * Copyright 2001-2004 The Apache Software Foundation.
00006 *
00007 * Licensed under the Apache License, Version 2.0 (the "License");
00008 * you may not use this file except in compliance with the License.
00009 * You may obtain a copy of the License at
00010 *
00011 * http://www.apache.org/licenses/LICENSE-2.0
00012 *
00013 * Unless required by applicable law or agreed to in writing, software
00014 * distributed under the License is distributed on an "AS IS" BASIS,
00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016 * See the License for the specific language governing permissions and
00017 * limitations under the License.
00018 */
00019
00020 /*
00021 * $Id: StDOMNode.hpp 176026 2004-09-08 13:57:07Z peiyongz $
00022 */
00023
00024 #include <xercesc/dom/DOMNode.hpp>
00025 #include <xercesc/dom/DOMAttr.hpp>
00026 #include <xercesc/dom/DOMElement.hpp>
00027
00028 XERCES_CPP_NAMESPACE_BEGIN
00029
00030 /* This class is a smart pointer implementation over DOMNode interface and
00031 ** classes derived from it. It takes care of reference counting automatically.
00032 ** Reference counting is optional so use of this class is experimental.
00033 */00034template <class T> class StDOMNode {
00035 T* m_node;
00036
00037 staticinlinevoid INCREFCOUNT(T *x) { if (x != (T*)0) x->incRefCount(); }
00038 staticinlinevoid DECREFCOUNT(T *x) { if (x != (T*)0) x->decRefCount(); }
00039
00040 public:
00041inlineStDOMNode(T* node = (T*)0) : m_node(node) { INCREFCOUNT(m_node); }
00042inlineStDOMNode(constStDOMNode& stNode) : m_node(stNode.m_node) { INCREFCOUNT(m_node); }
00043inline~StDOMNode() { DECREFCOUNT(m_node); }
00044
00045inline T* operator= (T *node)
00046 {
00047 if (m_node != node) {
00048 DECREFCOUNT(m_node);
00049 m_node = node;
00050 INCREFCOUNT(m_node);
00051 }
00052 return (m_node);
00053 }
00054
00055inlinebooloperator!= (T* node) const { return (m_node != node); }
00056inlinebooloperator== (T* node) const { return (m_node == node); }
00057
00058inline T& operator* () { return (*m_node); }
00059inlineconst T& operator* () const { return (*m_node); }
00060inline T* operator-> () const { return (m_node); }
00061inlineoperator T*() const { return (m_node); }
00062inlinevoidClearNode() { operator=((T*)(0)); }
00063 };
00064
00065 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)
00066 typedefStDOMNode<DOMNode>DOMNodeSPtr;
00067 #else00068typedefDOMNode* DOMNodeSPtr;
00069 #endif
00070
00071 /* StDOMNode is a smart pointer implementation over DOMNode interface and
00072 ** classes derived from it. It takes care of reference counting automatically.
00073 ** Reference counting is optional so use of this class is experimental.
00074 */
00075 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)
00076 typedefStDOMNode<DOMAttr>DOMAttrSPtr;
00077 #else00078typedefDOMAttr* DOMAttrSPtr;
00079 #endif
00080
00081 /* StDOMNode is a smart pointer implementation over DOMNode interface and
00082 ** classes derived from it. It takes care of reference counting automatically.
00083 ** Reference counting is optional so use of this class is experimental.
00084 */
00085 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)
00086 typedefStDOMNode<DOMElement>DOMElementSPtr;
00087 #else00088typedefDOMElement* DOMElementSPtr;
00089 #endif
00090
00091 XERCES_CPP_NAMESPACE_END
00092
00093 #endif
00094