1 /****************************************************************************** 2 * $Id: XMLNode.i a2d4bcda7874bbc6de9942874f8d549219e9403d 2016-01-08 21:00:50Z Kurt Schwehr $ 3 * 4 * Project: GDAL SWIG Interface 5 * Purpose: GDAL XML SWIG Interface declarations. 6 * Author: Tamas Szekeres (szekerest@gmail.com) 7 * 8 ****************************************************************************** 9 * Copyright (c) 2005, Tamas Szekeres 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining a 12 * copy of this software and associated documentation files (the "Software"), 13 * to deal in the Software without restriction, including without limitation 14 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 * and/or sell copies of the Software, and to permit persons to whom the 16 * Software is furnished to do so, subject to the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be included 19 * in all copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 * DEALINGS IN THE SOFTWARE. 28 *****************************************************************************/ 29 30 %rename (XMLNodeType) CPLXMLNodeType; 31 typedef enum 32 { 33 CXT_Element = 0, 34 CXT_Text = 1, 35 CXT_Attribute = 2, 36 CXT_Comment = 3, 37 CXT_Literal = 4 38 } CPLXMLNodeType; 39 40 %rename (XMLNode) CPLXMLNode; 41 %rename (Type) CPLXMLNode::eType; 42 %rename (Value) CPLXMLNode::pszValue; 43 %rename (Next) CPLXMLNode::psNext; 44 %rename (Child) CPLXMLNode::psChild; 45 typedef struct CPLXMLNode 46 { 47 %immutable; 48 CPLXMLNodeType eType; 49 char *pszValue; 50 struct CPLXMLNode *psNext; 51 struct CPLXMLNode *psChild; 52 %mutable; 53 } CPLXMLNode; 54 55 %extend CPLXMLNode 56 { CPLXMLNode(const char * pszString)57 CPLXMLNode(const char *pszString) 58 { 59 return CPLParseXMLString( pszString ); 60 } 61 62 /* Interface method added for GDAL 1.7.0 */ CPLXMLNode(CPLXMLNodeType eType,const char * pszText)63 CPLXMLNode(CPLXMLNodeType eType, const char *pszText ) 64 { 65 return CPLCreateXMLNode(NULL, eType, pszText); 66 } 67 ~CPLXMLNode()68 ~CPLXMLNode() 69 { 70 CPLDestroyXMLNode( self ); 71 } 72 73 /* Interface method added for GDAL 1.7.0 */ 74 #ifdef SWIGJAVA 75 %newobject ParseXMLFile; ParseXMLFile(const char * pszFilename)76 static CPLXMLNode* ParseXMLFile( const char *pszFilename ) 77 { 78 return CPLParseXMLFile(pszFilename); 79 } 80 #endif 81 82 #if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPERL) SerializeXMLTree()83 retStringAndCPLFree *SerializeXMLTree( ) 84 #else 85 char *SerializeXMLTree( ) 86 #endif 87 { 88 return CPLSerializeXMLTree( self ); 89 } 90 91 /* Interface method added for GDAL 1.7.0 */ 92 #if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPERL) toString()93 retStringAndCPLFree * toString() 94 { 95 return CPLSerializeXMLTree( self ); 96 } 97 #endif 98 SearchXMLNode(const char * pszElement)99 CPLXMLNode *SearchXMLNode( const char *pszElement ) 100 { 101 return CPLSearchXMLNode(self, pszElement); 102 } 103 GetXMLNode(const char * pszPath)104 CPLXMLNode *GetXMLNode( const char *pszPath ) 105 { 106 return CPLGetXMLNode( self, pszPath ); 107 } 108 GetXMLValue(const char * pszPath,const char * pszDefault)109 const char *GetXMLValue( const char *pszPath, 110 const char *pszDefault ) 111 { 112 return CPLGetXMLValue( self, pszPath, pszDefault ); 113 } 114 115 // For Java, I don't want to deal with ownership issues, 116 // so I just clone. 117 #ifdef SWIGJAVA 118 %apply Pointer NONNULL {CPLXMLNode *psChild}; AddXMLChild(CPLXMLNode * psChild)119 void AddXMLChild( CPLXMLNode *psChild ) 120 { 121 CPLAddXMLChild( self, CPLCloneXMLTree(psChild) ); 122 } 123 %clear CPLXMLNode *psChild; 124 125 %apply Pointer NONNULL {CPLXMLNode *psNewSibling}; AddXMLSibling(CPLXMLNode * psNewSibling)126 void AddXMLSibling( CPLXMLNode *psNewSibling ) 127 { 128 CPLAddXMLSibling( self, CPLCloneXMLTree(psNewSibling) ); 129 } 130 %clear CPLXMLNode *psNewSibling; 131 #else AddXMLChild(CPLXMLNode * psChild)132 void AddXMLChild( CPLXMLNode *psChild ) 133 { 134 CPLAddXMLChild( self, psChild ); 135 } 136 RemoveXMLChild(CPLXMLNode * psChild)137 int RemoveXMLChild( CPLXMLNode *psChild ) 138 { 139 return CPLRemoveXMLChild( self, psChild ); 140 } 141 AddXMLSibling(CPLXMLNode * psNewSibling)142 void AddXMLSibling( CPLXMLNode *psNewSibling ) 143 { 144 CPLAddXMLSibling( self, psNewSibling ); 145 } 146 CreateXMLElementAndValue(const char * pszName,const char * pszValue)147 CPLXMLNode *CreateXMLElementAndValue( const char *pszName, 148 const char *pszValue ) 149 { 150 return CPLCreateXMLElementAndValue( self, pszName, pszValue ); 151 } 152 153 %newobject CloneXMLTree; CloneXMLTree(CPLXMLNode * psTree)154 CPLXMLNode *CloneXMLTree( CPLXMLNode *psTree ) 155 { 156 return CPLCloneXMLTree( psTree ); 157 } 158 #endif 159 160 /* Interface method added for GDAL 1.7.0 */ 161 %newobject Clone; Clone()162 CPLXMLNode *Clone() 163 { 164 return CPLCloneXMLTree( self ); 165 } 166 SetXMLValue(const char * pszPath,const char * pszValue)167 int SetXMLValue( const char *pszPath, 168 const char *pszValue ) 169 { 170 return CPLSetXMLValue( self, pszPath, pszValue ); 171 } 172 StripXMLNamespace(const char * pszNamespace,int bRecurse)173 void StripXMLNamespace( const char *pszNamespace, 174 int bRecurse ) 175 { 176 CPLStripXMLNamespace( self, pszNamespace, bRecurse ); 177 } 178 } 179