00001 #ifndef IDCasts_HEADER_GUARD_ 00002 #define IDCasts_HEADER_GUARD_ 00003 00004 /* 00005 * The Apache Software License, Version 1.1 00006 * 00007 * Copyright (c) 2001 The Apache Software Foundation. All rights 00008 * reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * 1. Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * 00017 * 2. Redistributions in binary form must reproduce the above copyright 00018 * notice, this list of conditions and the following disclaimer in 00019 * the documentation and/or other materials provided with the 00020 * distribution. 00021 * 00022 * 3. The end-user documentation included with the redistribution, 00023 * if any, must include the following acknowledgment: 00024 * "This product includes software developed by the 00025 * Apache Software Foundation (http://www.apache.org/)." 00026 * Alternately, this acknowledgment may appear in the software itself, 00027 * if and wherever such third-party acknowledgments normally appear. 00028 * 00029 * 4. The names "Xerces" and "Apache Software Foundation" must 00030 * not be used to endorse or promote products derived from this 00031 * software without prior written permission. For written 00032 * permission, please contact apache\@apache.org. 00033 * 00034 * 5. Products derived from this software may not be called "Apache", 00035 * nor may "Apache" appear in their name, without prior written 00036 * permission of the Apache Software Foundation. 00037 * 00038 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00039 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00040 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00041 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00042 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00043 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00044 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00045 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00046 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00047 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00048 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00049 * SUCH DAMAGE. 00050 * ==================================================================== 00051 * 00052 * This software consists of voluntary contributions made by many 00053 * individuals on behalf of the Apache Software Foundation, and was 00054 * originally based on software copyright (c) 2001, International 00055 * Business Machines, Inc., http://www.ibm.com . For more information 00056 * on the Apache Software Foundation, please see 00057 * <http://www.apache.org/>. 00058 */ 00059 00060 /* 00061 * $Id: IDCasts.hpp,v 1.1 2002/05/11 20:05:36 bhavani Exp $ 00062 */ 00063 00064 // 00065 // This file is part of the internal implementation of the C++ XML DOM. 00066 // It should NOT be included or used directly by application programs. 00067 // 00068 // Applications should include the file <dom/DOM.hpp> for the entire 00069 // DOM API, or DOM_*.hpp for individual DOM classes, where the class 00070 // name is substituded for the *. 00071 // 00072 00073 00074 // 00075 // Define inline casting functions to convert from 00076 // (IDOM_Node *) to IDParentNode or IDChildNode *. 00077 // 00078 // This requires knowledge of the structure of the fields of 00079 // for all node types. There are three categories - 00080 // 00081 // Nodetypes that can have children and can be a child themselves. 00082 // e.g. Elements 00083 // 00084 // Object 00085 // IDNodeImpl fNode; 00086 // IDParentNode fParent; 00087 // IDChildNode fChild; 00088 // ... // other fields, depending on node type. 00089 // 00090 // Nodetypes that can not have children, e.g. TEXT 00091 // 00092 // Object 00093 // IDNodeImpl fNode; 00094 // IDChildNode fChild; 00095 // ... // other fields, depending on node type 00096 // 00097 // Nodetypes that can not be a child of other nodes, but that can 00098 // have children (are a parent) e.g. ATTR 00099 // Object 00100 // IDNodeImpl fNode; 00101 // IDParentNode fParent 00102 // ... // other fields, depending on node type 00103 // 00104 // The casting functions make these assumptions: 00105 // 1. The cast is possible. Using code will not attempt to 00106 // cast to something that does not exist, such as the child 00107 // part of an ATTR 00108 // 00109 // 2. The nodes belong to this implementation. 00110 // 00111 // Some of the casts use the LEAFNODE flag in the common fNode part to 00112 // determine whether an fParent field exists, and thus the 00113 // position of the fChild part within the node. 00114 // 00115 // These functions also cast off const. It was either do that, or make 00116 // a second overloaded set that took and returned const arguements. 00117 // 00118 00119 #include "IDElementImpl.hpp" 00120 #include "IDTextImpl.hpp" 00121 00122 static inline IDNodeImpl *castToNodeImpl(const IDOM_Node *p) 00123 { 00124 IDElementImpl *pE = (IDElementImpl *)p; 00125 return &(pE->fNode); 00126 } 00127 00128 00129 static inline IDParentNode *castToParentImpl(const IDOM_Node *p) { 00130 IDElementImpl *pE = (IDElementImpl *)p; 00131 return &(pE->fParent); 00132 } 00133 00134 00135 static inline IDChildNode *castToChildImpl(const IDOM_Node *p) { 00136 IDElementImpl *pE = (IDElementImpl *)p; 00137 if (pE->fNode.isLeafNode()) { 00138 IDTextImpl *pT = (IDTextImpl *)p; 00139 return &(pT->fChild); 00140 } 00141 return &(pE->fChild); 00142 } 00143 00144 00145 static inline IDOM_Node *castToNode(const IDParentNode *p ) { 00146 int parentOffset = (char *)&(((IDElementImpl *)0)->fParent) - (char *)0; 00147 char *retPtr = (char *)p - parentOffset; 00148 return (IDOM_Node *)retPtr; 00149 } 00150 00151 static inline IDOM_Node *castToNode(const IDNodeImpl *p) { 00152 int nodeImplOffset = (char *)&(((IDElementImpl *)0)->fNode) - (char *)0; 00153 char *retPtr = (char *)p - nodeImplOffset; 00154 return (IDOM_Node *)retPtr; 00155 } 00156 00157 00158 static inline IDNodeImpl *castToNodeImpl(const IDParentNode *p) 00159 { 00160 int nodeImplOffset = (char *)&(((IDElementImpl *)0)->fNode) - (char *)0; 00161 int parentOffset = (char *)&(((IDElementImpl *)0)->fParent) - (char *)0; 00162 char *retPtr = (char *)p - parentOffset + nodeImplOffset; 00163 return (IDNodeImpl *)retPtr; 00164 } 00165 00166 #endif