SourceForge.net Logo

StDOMNode.hpp

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: StDOMNode.hpp 570480 2007-08-28 16:36:34Z amassari $
00020  */
00021 
00022 #if !defined(XERCESC_INCLUDE_GUARD_STDOMNODE_HPP)
00023 #define XERCESC_INCLUDE_GUARD_STDOMNODE_HPP
00024 
00025 #include <xercesc/dom/DOMNode.hpp>
00026 #include <xercesc/dom/DOMAttr.hpp>
00027 #include <xercesc/dom/DOMElement.hpp>
00028 
00029 XERCES_CPP_NAMESPACE_BEGIN
00030 
00031 /* This class is a smart pointer implementation over DOMNode interface and
00032 ** classes derived from it. It takes care of reference counting automatically.
00033 ** Reference counting is optional so use of this class is experimental.
00034 */
00035 template <class T> class StDOMNode {
00036         T* m_node;
00037 
00038         static inline void INCREFCOUNT(T *x) { if (x != (T*)0) x->incRefCount(); }
00039         static inline void DECREFCOUNT(T *x) { if (x != (T*)0) x->decRefCount(); }
00040 
00041 public:
00042         inline StDOMNode(T* node = (T*)0) : m_node(node) { INCREFCOUNT(m_node); }
00043         inline StDOMNode(const StDOMNode& stNode) : m_node(stNode.m_node) { INCREFCOUNT(m_node); }
00044         inline ~StDOMNode() { DECREFCOUNT(m_node); }
00045 
00046         inline 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 
00056         inline bool operator!= (T* node) const { return (m_node != node); }
00057         inline bool operator== (T* node) const { return (m_node == node); }
00058 
00059         inline T& operator* () { return (*m_node); }
00060         inline const T& operator* () const { return (*m_node); }
00061         inline T* operator-> () const { return (m_node); }
00062         inline operator T*() const { return (m_node); }
00063         inline void ClearNode() { operator=((T*)(0)); }
00064 };
00065 
00066 #if defined(XML_DOMREFCOUNT_EXPERIMENTAL)
00067     typedef StDOMNode<DOMNode> DOMNodeSPtr;
00068 #else
00069     typedef DOMNode* DOMNodeSPtr;
00070 #endif
00071 
00072 /* StDOMNode is a smart pointer implementation over DOMNode interface and
00073 ** 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     typedef StDOMNode<DOMAttr> DOMAttrSPtr;
00078 #else
00079     typedef DOMAttr* DOMAttrSPtr;
00080 #endif
00081 
00082 /* StDOMNode is a smart pointer implementation over DOMNode interface and
00083 ** 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     typedef StDOMNode<DOMElement> DOMElementSPtr;
00088 #else
00089     typedef DOMElement* DOMElementSPtr;
00090 #endif
00091 
00092 XERCES_CPP_NAMESPACE_END
00093 
00094 #endif
00095