Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:00

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_DOMCASTS_HPP)
0023 #define XERCESC_INCLUDE_GUARD_DOMCASTS_HPP
0024 
0025 //
0026 //  This file is part of the internal implementation of the C++ XML DOM.
0027 //  It should NOT be included or used directly by application programs.
0028 //
0029 //  Applications should include the file <xercesc/dom/DOM.hpp> for the entire
0030 //  DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class
0031 //  name is substituded for the *.
0032 //
0033 
0034 //
0035 //  Define inline casting functions to convert from
0036 //    (DOMNode*) to the embedded instances of DOMNodeImpl,
0037 //    DOMParentNode, and DOMChildNode.
0038 //
0039 //  Each type of embedded object corresponds to a HasXXX virtual
0040 //  interface class that a given DOM implementation class will
0041 //  support to expose its embedded object(s) to other implementation
0042 //  classes.
0043 //
0044 //  This replaces the previous implementation that relied upon unsafe
0045 //  casts and member offsets that rely on unspecified behavior in C++,
0046 //  with a hopefully small cost in memory and performance.
0047 //
0048 
0049 #include <xercesc/dom/DOMException.hpp>
0050 #include "DOMNodeBase.hpp"
0051 #include "DOMElementImpl.hpp"
0052 #include "DOMTextImpl.hpp"
0053 
0054 XERCES_CPP_NAMESPACE_BEGIN
0055 
0056 
0057 static inline const DOMNodeImpl *castToNodeImpl(const DOMNode *p)
0058 {
0059     const HasDOMNodeImpl* pE = dynamic_cast<const HasDOMNodeImpl*>(p);
0060     if (!pE || !pE->getNodeImpl()) {
0061         throw DOMException(DOMException::INVALID_STATE_ERR, 0, XMLPlatformUtils::fgMemoryManager);
0062     }
0063     return pE->getNodeImpl();
0064 }
0065 
0066 static inline DOMNodeImpl *castToNodeImpl(DOMNode *p)
0067 {
0068     HasDOMNodeImpl *pE = dynamic_cast<HasDOMNodeImpl*>(p);
0069     if (!pE || !pE->getNodeImpl()) {
0070         throw DOMException(DOMException::INVALID_STATE_ERR, 0, XMLPlatformUtils::fgMemoryManager);
0071     }
0072     return pE->getNodeImpl();
0073 }
0074 
0075 static inline const DOMParentNode *castToParentImpl(const DOMNode *p) {
0076     const HasDOMParentImpl *pE = dynamic_cast<const HasDOMParentImpl*>(p);
0077     if (!pE || !pE->getParentNodeImpl()) {
0078         throw DOMException(DOMException::INVALID_STATE_ERR, 0, XMLPlatformUtils::fgMemoryManager);
0079     }
0080     return pE->getParentNodeImpl();
0081 }
0082 
0083 static inline DOMParentNode *castToParentImpl(DOMNode *p) {
0084     HasDOMParentImpl *pE = dynamic_cast<HasDOMParentImpl*>(p);
0085     if (!pE || !pE->getParentNodeImpl()) {
0086         throw DOMException(DOMException::INVALID_STATE_ERR, 0, XMLPlatformUtils::fgMemoryManager);
0087     }
0088     return pE->getParentNodeImpl();
0089 }
0090 
0091 static inline const DOMChildNode *castToChildImpl(const DOMNode *p) {
0092     const HasDOMChildImpl *pE = dynamic_cast<const HasDOMChildImpl*>(p);
0093     if (!pE || !pE->getChildNodeImpl()) {
0094         throw DOMException(DOMException::INVALID_STATE_ERR, 0, XMLPlatformUtils::fgMemoryManager);
0095     }
0096     return pE->getChildNodeImpl();
0097 }
0098 
0099 static inline DOMChildNode *castToChildImpl(DOMNode *p) {
0100     HasDOMChildImpl *pE = dynamic_cast<HasDOMChildImpl*>(p);
0101     if (!pE || !pE->getChildNodeImpl()) {
0102         throw DOMException(DOMException::INVALID_STATE_ERR, 0, XMLPlatformUtils::fgMemoryManager);
0103     }
0104     return pE->getChildNodeImpl();
0105 }
0106 
0107 XERCES_CPP_NAMESPACE_END
0108 
0109 #endif