source: NonGTP/Xerces/xerces/include/xercesc/dom/StDOMNode.hpp @ 358

Revision 358, 3.0 KB checked in by bittner, 19 years ago (diff)

xerces added

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