gwenhywfar 4.0.3
|
00001 /*************************************************************************** 00002 begin : Wed Feb 27 2008 00003 copyright : (C) 2008 by Martin Preuss 00004 email : martin@libchipcard.de 00005 00006 *************************************************************************** 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00021 * MA 02111-1307 USA * 00022 * * 00023 ***************************************************************************/ 00024 00025 #ifdef HAVE_CONFIG_H 00026 # include <config.h> 00027 #endif 00028 00029 00030 #include "xsdnode_p.h" 00031 00032 #include <gwenhywfar/debug.h> 00033 #include <gwenhywfar/misc.h> 00034 00035 #include <stdlib.h> 00036 #include <assert.h> 00037 #include <string.h> 00038 #include <ctype.h> 00039 00040 00041 GWEN_INHERIT_FUNCTIONS(GWEN_XSD_NODE) 00042 GWEN_LIST_FUNCTIONS(GWEN_XSD_NODE, GWEN_XsdNode) 00043 00044 00045 00046 GWEN_XSD_NODE *GWEN_XsdNode_new(GWEN_XSD_NODE *parent, 00047 GWEN_XSD_NODETYPE t, 00048 const char *name) { 00049 GWEN_XSD_NODE *xsdNode; 00050 00051 GWEN_NEW_OBJECT(GWEN_XSD_NODE, xsdNode); 00052 GWEN_INHERIT_INIT(GWEN_XSD_NODE, xsdNode); 00053 GWEN_LIST_INIT(GWEN_XSD_NODE, xsdNode); 00054 xsdNode->nodeType=t; 00055 xsdNode->parent=parent; 00056 xsdNode->children=GWEN_XsdNode_List_new(); 00057 if (name) 00058 xsdNode->name=strdup(name); 00059 00060 return xsdNode; 00061 } 00062 00063 00064 00065 void GWEN_XsdNode_free(GWEN_XSD_NODE *xsdNode) { 00066 if (xsdNode) { 00067 GWEN_LIST_FINI(GWEN_XSD_NODE, xsdNode); 00068 GWEN_INHERIT_FINI(GWEN_XSD_NODE, xsdNode); 00069 GWEN_XsdNode_List_free(xsdNode->children); 00070 free(xsdNode->name); 00071 GWEN_FREE_OBJECT(xsdNode); 00072 } 00073 } 00074 00075 00076 00077 GWEN_XSD_NODETYPE GWEN_XsdNode_GetNodeType(const GWEN_XSD_NODE *xsdNode) { 00078 assert(xsdNode); 00079 return xsdNode->nodeType; 00080 } 00081 00082 00083 00084 const char *GWEN_XsdNode_GetName(const GWEN_XSD_NODE *xsdNode) { 00085 assert(xsdNode); 00086 return xsdNode->name; 00087 } 00088 00089 00090 00091 uint32_t GWEN_XsdNode_GetFlags(const GWEN_XSD_NODE *xsdNode) { 00092 assert(xsdNode); 00093 return xsdNode->flags; 00094 } 00095 00096 00097 00098 void GWEN_XsdNode_SetFlags(GWEN_XSD_NODE *xsdNode, uint32_t fl) { 00099 assert(xsdNode); 00100 xsdNode->flags=fl; 00101 } 00102 00103 00104 00105 void GWEN_XsdNode_AddFlags(GWEN_XSD_NODE *xsdNode, uint32_t fl) { 00106 assert(xsdNode); 00107 xsdNode->flags|=fl; 00108 } 00109 00110 00111 00112 void GWEN_XsdNode_SubFlags(GWEN_XSD_NODE *xsdNode, uint32_t fl) { 00113 assert(xsdNode); 00114 xsdNode->flags&=~fl; 00115 } 00116 00117 00118 00119 GWEN_XSD_NODE *GWEN_XsdNode_GetParent(const GWEN_XSD_NODE *xsdNode) { 00120 assert(xsdNode); 00121 return xsdNode->parent; 00122 } 00123 00124 00125 00126 GWEN_XSD_NODE_LIST *GWEN_XsdNode_GetChildren(const GWEN_XSD_NODE *xsdNode) { 00127 assert(xsdNode); 00128 return xsdNode->children; 00129 } 00130 00131 00132 00133 void GWEN_XsdNode_AddChild(GWEN_XSD_NODE *xsdNode, GWEN_XSD_NODE *newChild) { 00134 assert(xsdNode); 00135 assert(newChild); 00136 GWEN_XsdNode_List_Add(newChild, xsdNode->children); 00137 newChild->parent=xsdNode; 00138 } 00139 00140 00141 00142 void GWEN_XsdNode_Unlink(GWEN_XSD_NODE *xsdNode) { 00143 GWEN_XsdNode_List_Del(xsdNode); 00144 xsdNode->parent=NULL; 00145 } 00146 00147 00148 00149 GWEN_XSDNODE_READ_FN GWEN_XsdNode_SetReadFn(GWEN_XSD_NODE *xsdNode, 00150 GWEN_XSDNODE_READ_FN fn) { 00151 GWEN_XSDNODE_READ_FN oldFn; 00152 00153 assert(xsdNode); 00154 oldFn=xsdNode->readFn; 00155 xsdNode->readFn=fn; 00156 return oldFn; 00157 } 00158 00159 00160 00161 GWEN_XSDNODE_WRITE_FN GWEN_XsdNode_SetWriteFn(GWEN_XSD_NODE *xsdNode, 00162 GWEN_XSDNODE_WRITE_FN fn) { 00163 GWEN_XSDNODE_WRITE_FN oldFn; 00164 00165 assert(xsdNode); 00166 oldFn=xsdNode->writeFn; 00167 xsdNode->writeFn=fn; 00168 return oldFn; 00169 } 00170 00171 00172 00173 int GWEN_XsdNode_Read(GWEN_XSD_NODE *xsdNode, 00174 GWEN_XMLNODE *xmlNode, 00175 GWEN_DB_NODE *db) { 00176 assert(xsdNode); 00177 if (xsdNode->readFn) 00178 return xsdNode->readFn(xsdNode, xmlNode, db); 00179 else 00180 return GWEN_ERROR_NOT_SUPPORTED; 00181 } 00182 00183 00184 00185 int GWEN_XsdNode_Write(GWEN_XSD_NODE *xsdNode, 00186 GWEN_XMLNODE *xmlNode, 00187 GWEN_DB_NODE *db) { 00188 assert(xsdNode); 00189 if (xsdNode->writeFn) 00190 return xsdNode->writeFn(xsdNode, xmlNode, db); 00191 else 00192 return GWEN_ERROR_NOT_SUPPORTED; 00193 } 00194 00195 00196 00197