00001 #ifndef DOMSPtr_HEADER_GUARD_00002 #define DOMSPtr_HEADER_GUARD_00003
00004 /*00005 * Licensed to the Apache Software Foundation (ASF) under one or more00006 * contributor license agreements. See the NOTICE file distributed with00007 * this work for additional information regarding copyright ownership.00008 * The ASF licenses this file to You under the Apache License, Version 2.000009 * (the "License"); you may not use this file except in compliance with00010 * the License. You may obtain a copy of the License at00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.000013 * 00014 * Unless required by applicable law or agreed to in writing, software00015 * distributed under the License is distributed on an "AS IS" BASIS,00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.00017 * See the License for the specific language governing permissions and00018 * limitations under the License.00019 */00020
00021 /*00022 * $Id: StDOMNode.hpp 570125 2007-08-27 13:57:11Z amassari $00023 */00024
00025 #include <xercesc/dom/DOMNode.hpp>00026 #include <xercesc/dom/DOMAttr.hpp>00027 #include <xercesc/dom/DOMElement.hpp>00028
00029 XERCES_CPP_NAMESPACE_BEGIN00030
00031 /* This class is a smart pointer implementation over DOMNode interface and00032 ** classes derived from it. It takes care of reference counting automatically.00033 ** Reference counting is optional so use of this class is experimental.00034 */00035template <class T> class StDOMNode {
00036 T* m_node;
00037
00038 staticinlinevoid INCREFCOUNT(T *x) { if (x != (T*)0) x->incRefCount(); }
00039 staticinlinevoid DECREFCOUNT(T *x) { if (x != (T*)0) x->decRefCount(); }
00040
00041 public:
00042inlineStDOMNode(T* node = (T*)0) : m_node(node) { INCREFCOUNT(m_node); }
00043inlineStDOMNode(constStDOMNode& stNode) : m_node(stNode.m_node) { INCREFCOUNT(m_node); }
00044inline~StDOMNode() { DECREFCOUNT(m_node); }
00045
00046inline T* operator= (T *node)
00047 {
00048 if (m_node != node) {
00049 DECREFCOUNT(m_node);
00050 m_node = node;
00051 INCREFCOUNT(m_node);
00052 }
00053 return (m_node);
00054 }
00055
00056inlinebooloperator!= (T* node) const { return (m_node != node); }
00057inlinebooloperator== (T* node) const { return (m_node == node); }
00058
00059inline T& operator* () { return (*m_node); }
00060inlineconst T& operator* () const { return (*m_node); }
00061inline T* operator-> () const { return (m_node); }
00062inlineoperator T*() const { return (m_node); }
00063inlinevoidClearNode() { operator=((T*)(0)); }
00064 };
00065
00066 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)00067 typedefStDOMNode<DOMNode>DOMNodeSPtr;
00068 #else00069typedefDOMNode* DOMNodeSPtr;
00070 #endif00071
00072 /* StDOMNode is a smart pointer implementation over DOMNode interface and00073 ** classes derived from it. It takes care of reference counting automatically.00074 ** Reference counting is optional so use of this class is experimental.00075 */00076 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)00077 typedefStDOMNode<DOMAttr>DOMAttrSPtr;
00078 #else00079typedefDOMAttr* DOMAttrSPtr;
00080 #endif00081
00082 /* StDOMNode is a smart pointer implementation over DOMNode interface and00083 ** classes derived from it. It takes care of reference counting automatically.00084 ** Reference counting is optional so use of this class is experimental.00085 */00086 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)00087 typedefStDOMNode<DOMElement>DOMElementSPtr;
00088 #else00089typedefDOMElement* DOMElementSPtr;
00090 #endif00091
00092 XERCES_CPP_NAMESPACE_END00093
00094 #endif00095