[2674] | 1 | #ifndef DOMSPtr_HEADER_GUARD_ |
---|
| 2 | #define DOMSPtr_HEADER_GUARD_ |
---|
| 3 | |
---|
| 4 | /* |
---|
| 5 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
| 6 | * contributor license agreements. See the NOTICE file distributed with |
---|
| 7 | * this work for additional information regarding copyright ownership. |
---|
| 8 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
| 9 | * (the "License"); you may not use this file except in compliance with |
---|
| 10 | * the License. You may obtain a copy of the License at |
---|
| 11 | * |
---|
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 13 | * |
---|
| 14 | * Unless required by applicable law or agreed to in writing, software |
---|
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 17 | * See the License for the specific language governing permissions and |
---|
| 18 | * limitations under the License. |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | /* |
---|
| 22 | * $Id: StDOMNode.hpp 570125 2007-08-27 13:57:11Z amassari $ |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include <xercesc/dom/DOMNode.hpp> |
---|
| 26 | #include <xercesc/dom/DOMAttr.hpp> |
---|
| 27 | #include <xercesc/dom/DOMElement.hpp> |
---|
| 28 | |
---|
| 29 | XERCES_CPP_NAMESPACE_BEGIN |
---|
| 30 | |
---|
| 31 | /* This class is a smart pointer implementation over DOMNode interface and |
---|
| 32 | ** classes derived from it. It takes care of reference counting automatically. |
---|
| 33 | ** Reference counting is optional so use of this class is experimental. |
---|
| 34 | */ |
---|
| 35 | template <class T> class StDOMNode { |
---|
| 36 | T* m_node; |
---|
| 37 | |
---|
| 38 | static inline void INCREFCOUNT(T *x) { if (x != (T*)0) x->incRefCount(); } |
---|
| 39 | static inline void DECREFCOUNT(T *x) { if (x != (T*)0) x->decRefCount(); } |
---|
| 40 | |
---|
| 41 | public: |
---|
| 42 | inline StDOMNode(T* node = (T*)0) : m_node(node) { INCREFCOUNT(m_node); } |
---|
| 43 | inline StDOMNode(const StDOMNode& stNode) : m_node(stNode.m_node) { INCREFCOUNT(m_node); } |
---|
| 44 | inline ~StDOMNode() { DECREFCOUNT(m_node); } |
---|
| 45 | |
---|
| 46 | inline T* operator= (T *node) |
---|
| 47 | { |
---|
| 48 | if (m_node != node) { |
---|
| 49 | DECREFCOUNT(m_node); |
---|
| 50 | m_node = node; |
---|
| 51 | INCREFCOUNT(m_node); |
---|
| 52 | } |
---|
| 53 | return (m_node); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | inline bool operator!= (T* node) const { return (m_node != node); } |
---|
| 57 | inline bool operator== (T* node) const { return (m_node == node); } |
---|
| 58 | |
---|
| 59 | inline T& operator* () { return (*m_node); } |
---|
| 60 | inline const T& operator* () const { return (*m_node); } |
---|
| 61 | inline T* operator-> () const { return (m_node); } |
---|
| 62 | inline operator T*() const { return (m_node); } |
---|
| 63 | inline void ClearNode() { operator=((T*)(0)); } |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | #if defined(XML_DOMREFCOUNT_EXPERIMENTAL) |
---|
| 67 | typedef StDOMNode<DOMNode> DOMNodeSPtr; |
---|
| 68 | #else |
---|
| 69 | typedef DOMNode* DOMNodeSPtr; |
---|
| 70 | #endif |
---|
| 71 | |
---|
| 72 | /* StDOMNode is a smart pointer implementation over DOMNode interface and |
---|
| 73 | ** classes derived from it. It takes care of reference counting automatically. |
---|
| 74 | ** Reference counting is optional so use of this class is experimental. |
---|
| 75 | */ |
---|
| 76 | #if defined(XML_DOMREFCOUNT_EXPERIMENTAL) |
---|
| 77 | typedef StDOMNode<DOMAttr> DOMAttrSPtr; |
---|
| 78 | #else |
---|
| 79 | typedef DOMAttr* DOMAttrSPtr; |
---|
| 80 | #endif |
---|
| 81 | |
---|
| 82 | /* StDOMNode is a smart pointer implementation over DOMNode interface and |
---|
| 83 | ** classes derived from it. It takes care of reference counting automatically. |
---|
| 84 | ** Reference counting is optional so use of this class is experimental. |
---|
| 85 | */ |
---|
| 86 | #if defined(XML_DOMREFCOUNT_EXPERIMENTAL) |
---|
| 87 | typedef StDOMNode<DOMElement> DOMElementSPtr; |
---|
| 88 | #else |
---|
| 89 | typedef DOMElement* DOMElementSPtr; |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | XERCES_CPP_NAMESPACE_END |
---|
| 93 | |
---|
| 94 | #endif |
---|
| 95 | |
---|