Changeset 1003
- Timestamp:
- 11/03/08 17:48:47 (2 months ago)
- Files:
-
- trunk/lib/src/Base/Common/Path.cxx (modified) (2 diffs)
- trunk/lib/src/Base/Common/Path.hxx (modified) (1 diff)
- trunk/lib/src/Base/Common/XMLToolbox.cxx (modified) (7 diffs)
- trunk/lib/src/Base/Common/XMLToolbox.hxx (modified) (3 diffs)
- trunk/lib/src/Base/Func/WrapperFile.cxx (modified) (22 diffs)
- trunk/lib/src/Base/Func/WrapperFile.hxx (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/src/Base/Common/Path.cxx
r963 r1003 87 87 } 88 88 89 /* The directory where installed wrappers and DTD are */ 90 FileName Path::GetStandardWrapperDirectory() 91 { 92 FileName directory = DATA_PATH; 93 directory += Path::PrefixWrapperSubdirectory_; 94 return directory; 95 } 89 96 90 97 … … 134 141 135 142 // ... search in ${prefix}/wrappers 136 FileName directory = DATA_PATH; 137 directory += Path::PrefixWrapperSubdirectory_; 143 FileName directory = Path::GetStandardWrapperDirectory(); 138 144 directoryList.push_back(directory); 139 145 trunk/lib/src/Base/Common/Path.hxx
r818 r1003 52 52 53 53 typedef std::vector<FileName> DirectoryList; 54 55 /** The directory where installed wrappers and DTD are */ 56 static FileName GetStandardWrapperDirectory(); 54 57 55 58 /** trunk/lib/src/Base/Common/XMLToolbox.cxx
r990 r1003 93 93 } 94 94 95 Bool XMLDoc::hasDTD() const 96 { 97 xmlDtdPtr dtd = xmlGetIntSubset( doc_ ); 98 return (dtd != NULL); 99 } 100 101 Bool XMLDoc::validate() const 102 { 103 xmlValidCtxtPtr validCtxt = xmlNewValidCtxt(); 104 int ok = xmlValidateDocument( validCtxt, doc_ ); 105 xmlFreeValidCtxt( validCtxt ); 106 return (ok == 1); 107 } 108 109 Bool XMLDoc::validate(const String & name, const FileName & dtd) const 110 { 111 XML::xmlString aName = XML::xmlString( name.begin(), name.end() ); 112 XML::xmlString aDtd = XML::xmlString( dtd.begin(), dtd.end() ); 113 xmlDtdPtr theDTD = xmlNewDtd( doc_, aName.c_str(), NULL, aDtd.c_str() ); 114 xmlValidCtxtPtr validCtxt = xmlNewValidCtxt(); 115 int ok = xmlValidateDtd( validCtxt, doc_, theDTD ); 116 xmlFreeValidCtxt( validCtxt ); 117 xmlFreeDtd( theDTD ); 118 return (ok == 1); 119 } 120 121 95 122 96 123 String XML::ToString(const xmlString & st) … … 133 160 134 161 135 String XML::GetAttributeByName(const Node & parent, const String & name)162 String XML::GetAttributeByName(const Node & node, const String & name) 136 163 { 137 164 String attrVal; 138 if ( parent) {165 if (node) { 139 166 xmlString aName = xmlString( name.begin(), name.end() ); 140 if ( xmlHasProp( parent, aName.c_str() ) ) {141 xmlString val = xmlGetProp( parent, aName.c_str() );167 if ( xmlHasProp( node, aName.c_str() ) ) { 168 xmlString val = xmlGetProp(node, aName.c_str() ); 142 169 attrVal = String(val.begin(), val.end()); 143 170 } … … 147 174 148 175 149 void XML::SetAttribute(const Node & parent, const String & attribute, const String & value)150 { 151 if ( parent) {176 void XML::SetAttribute(const Node & node, const String & attribute, const String & value) 177 { 178 if (node) { 152 179 xmlString aAttr = xmlString( attribute.begin(), attribute.end() ); 153 180 xmlString aValue = xmlString( value.begin(), value.end() ); 154 xmlNewProp( parent, aAttr.c_str(), aValue.c_str() );155 } 156 } 157 158 159 XML::Node XML::FindElementByName(const Node & parent, const String & name)181 xmlNewProp( node, aAttr.c_str(), aValue.c_str() ); 182 } 183 } 184 185 186 XML::Node XML::FindElementByName(const Node & node, const String & name) 160 187 { 161 188 Node cur = NULL; 162 if ( parent) {163 for(cur = parent->children; cur; cur = cur->next) {189 if (node) { 190 for(cur = node->children; cur; cur = cur->next) { 164 191 if (IsElement(cur, name)) { 165 192 break; … … 172 199 173 200 174 String XML::GetNodeValue(const Node & parent)201 String XML::GetNodeValue(const Node & node) 175 202 { 176 203 String value; 177 204 Node cur = NULL; 178 if ( parent) {179 for(cur = parent->children; cur; cur = cur->next) {205 if (node) { 206 for(cur = node->children; cur; cur = cur->next) { 180 207 if (IsText(cur)) { 181 208 xmlString val = cur->content; … … 189 216 190 217 191 String XML::GetNodeName(const Node & parent)218 String XML::GetNodeName(const Node & node) 192 219 { 193 220 String name; 194 if ( parent) {195 xmlString aName = parent->name;221 if (node) { 222 xmlString aName = node->name; 196 223 name = String( aName.begin(), aName.end() ); 197 224 } … … 199 226 } 200 227 228 229 230 UnsignedLong XML::GetNodeLineNumber(const Node & node) 231 { 232 UnsignedLong lineno = 0; 233 if (node) lineno = xmlGetLineNo(node); 234 return lineno; 235 } 201 236 202 237 … … 255 290 } 256 291 292 void XML::SetDTD( const XMLDoc & doc, const String & name, const String & path ) 293 { 294 xmlString aName = xmlString( name.begin(), name.end() ); 295 xmlString aPath = xmlString( path.begin(), path.end() ); 296 xmlCreateIntSubset( doc, aName.c_str(), NULL, aPath.c_str() ); 297 } 257 298 258 299 trunk/lib/src/Base/Common/XMLToolbox.hxx
r990 r1003 55 55 class XMLDoc { 56 56 xmlDocPtr doc_; 57 57 58 public: 59 58 60 XMLDoc(); 59 XMLDoc( const XMLDoc & other);60 XMLDoc( const FileName & pathToFile);61 XMLDoc( const XMLDoc & other ); 62 XMLDoc( const FileName & pathToFile ); 61 63 ~XMLDoc() throw(); 62 XMLDoc & operator =(const XMLDoc & other); 64 65 XMLDoc & operator =( const XMLDoc & other ); 66 63 67 operator xmlDocPtr(); 64 68 operator const xmlDocPtr() const; 69 65 70 void save( const FileName & fileName ) const; 71 72 Bool hasDTD() const; 73 Bool validate() const; 74 Bool validate( const String & name, const FileName & dtd ) const; 66 75 }; 67 76 … … 82 91 83 92 /** Convert XML string to basic string */ 84 static String ToString( const xmlString & st);93 static String ToString( const xmlString & st ); 85 94 86 95 /** Returns true if node 'elt' is an XML text node */ 87 static Bool IsText( const Node & elt);96 static Bool IsText( const Node & elt ); 88 97 89 98 /** Returns true if node 'elt' is an XML Element node */ 90 static Bool IsElement( const Node & elt);99 static Bool IsElement( const Node & elt ); 91 100 92 101 /** Returns true if node 'elt' is an XML element node named 'name' */ 93 static Bool IsElement( const Node & elt, const String & name);102 static Bool IsElement( const Node & elt, const String & name ); 94 103 95 104 /** Returns true if node 'elt' has a attribute named 'name' */ 96 static Bool ElementHasAttribute( const Node & elt, const String & name);105 static Bool ElementHasAttribute( const Node & elt, const String & name ); 97 106 98 /** Returns the value of the attribute named 'name' hold by node 'parent' */99 static String GetAttributeByName( const Node & parent, const String & name);107 /** Returns the value of the attribute named 'name' hold by 'node' */ 108 static String GetAttributeByName( const Node & node, const String & name ); 100 109 101 110 /** Set the attribute of a node */ 102 static void SetAttribute( const Node & parent, const String & attribute, const String & value);111 static void SetAttribute( const Node & node, const String & attribute, const String & value ); 103 112 104 113 /** Returns the child node named 'name' of node 'parent' */ 105 static Node FindElementByName( const Node & parent, const String & name);114 static Node FindElementByName( const Node & parent, const String & name ); 106 115 107 /** Returns the content of node 'parent' */108 static String GetNodeValue( const Node & parent);116 /** Returns the content of 'node' */ 117 static String GetNodeValue( const Node & node ); 109 118 110 /** Returns the name of node 'parent' */ 111 static String GetNodeName(const Node & parent); 119 /** Returns the name of 'node' */ 120 static String GetNodeName( const Node & node ); 121 122 /** Returns the line number where 'node' appears */ 123 static UnsignedLong GetNodeLineNumber( const Node & node ); 112 124 113 125 /** Create a new node */ 114 static Node NewNode( const String & name);115 static Node NewNode( const String & name, const String & value);116 static Node NewTextNode( const String & value);126 static Node NewNode( const String & name ); 127 static Node NewNode( const String & name, const String & value ); 128 static Node NewTextNode( const String & value ); 117 129 118 130 /** Link a child node to its parent */ 119 static void AddChild( const Node & parent, const Node & child);131 static void AddChild( const Node & parent, const Node & child ); 120 132 121 133 /** Get/Set the root node of an XML file */ … … 127 139 static Node GetNextNode( const Node & node ); 128 140 141 /** Set the DTD of the document */ 142 static void SetDTD( const XMLDoc & doc, const String & name, const String & path ); 143 129 144 }; /* end class XML */ 130 145 trunk/lib/src/Base/Func/WrapperFile.cxx
r990 r1003 54 54 using Common::WrapperFileParsingException; 55 55 using Common::FileNotFoundException; 56 using Common::NotYetImplementedException; 57 using Common::InternalException; 56 58 using Common::Log; 57 59 using Common::Path; … … 60 62 #ifdef XML_SUPPORTED 61 63 const String WrapperFile::extension_ = ".xml"; 64 static const FileName DTDFileName = "wrapper.dtd"; 62 65 #else 63 66 const String WrapperFile::extension_ = ".txt"; 64 67 #endif 65 66 /* The environment variable name */67 const String WrapperFile::openturnsWrapperPathVariableName_ = "OPENTURNS_WRAPPER_PATH";68 69 /* The HOME subdirectory path */70 const String WrapperFile::homeSubdirectory_ = "/openturns/wrappers";71 72 /* The 'prefix' subdirectory path */73 const String WrapperFile::prefixSubdirectory_ = "/openturns/wrappers";74 68 75 69 … … 109 103 } 110 104 111 #if defined HAS_LIBXML2105 #ifdef XML_SUPPORTED 112 106 113 107 using Common::XMLDoc; … … 132 126 throw(WrapperFileParsingException) 133 127 { 128 Log::Debug(OSS() << "Try parsing file " << pathToFile); 129 134 130 // Load the wrapper file 135 131 XMLDoc doc( pathToFile ); 136 132 133 const FileName DTDPath = Path::GetStandardWrapperDirectory() + "/" + DTDFileName; 134 Bool ok = doc.hasDTD() ? doc.validate() : doc.validate( XMLTag_wrapper, DTDPath ); 135 if (!ok) throw WrapperFileParsingException(HERE) << "The generated wrapper does not conform to DTD"; 136 else Log::Debug( OSS() << "Wrapper file " << pathToFile << " is valid according to DTD" ); 137 137 138 // Check it is an OpenTURNS' one 138 xmlNodePtr wrapperElt = xmlDocGetRootElement( doc );139 XML::Node wrapperElt = XML::GetRootNode( doc ); 139 140 if (wrapperElt == NULL) throw WrapperFileParsingException(HERE) << "Wrapper file has no root element (" << pathToFile << ")"; 140 if ( xmlStrcmp( wrapperElt->name, REINTERPRET_CAST(const xmlChar *, XMLTag_wrapper)))141 if (! XML::IsElement( wrapperElt, XMLTag_wrapper )) 141 142 throw WrapperFileParsingException(HERE) << "Wrapper file " << pathToFile 142 << " has an invalid root element (" << wrapperElt->name<< ")"143 << " at line " << xmlGetLineNo(wrapperElt);144 145 xmlNodePtrlibraryElt = XML::FindElementByName( wrapperElt, XMLTag_library );146 xmlNodePtrlibraryPathElt = XML::FindElementByName( libraryElt, XMLTag_path );143 << " has an invalid root element (" << XML::GetNodeName( wrapperElt ) << ")" 144 << " at line " << XML::GetNodeLineNumber( wrapperElt ); 145 146 XML::Node libraryElt = XML::FindElementByName( wrapperElt, XMLTag_library ); 147 XML::Node libraryPathElt = XML::FindElementByName( libraryElt, XMLTag_path ); 147 148 String libraryPath = XML::GetNodeValue( libraryPathElt ); 148 149 if (libraryPath.empty()) throw WrapperFileParsingException(HERE) << "Library path tag not found in wrapper file " << pathToFile; … … 153 154 154 155 155 xmlNodePtrdescriptionElt = XML::FindElementByName( libraryElt, XMLTag_description );156 xmlNodePtrvariableListElt = XML::FindElementByName( descriptionElt, XMLTag_variable_list );156 XML::Node descriptionElt = XML::FindElementByName( libraryElt, XMLTag_description ); 157 XML::Node variableListElt = XML::FindElementByName( descriptionElt, XMLTag_variable_list ); 157 158 WrapperData::VariableListType variableList; 158 if ( variableListElt && variableListElt->children) {159 for ( xmlNodePtr current = variableListElt->children; current; current = current->next) {159 if (XML::IsElement(variableListElt)) { 160 for (XML::Node current = XML::GetFirstChild(variableListElt); current; current = XML::GetNextNode(current)) { 160 161 if (XML::IsElement(current, XMLTag_variable)) { 161 162 WrapperDataVariable variable; 162 163 163 xmlNodePtrcommentElt = XML::FindElementByName( current, XMLTag_comment );164 XML::Node commentElt = XML::FindElementByName( current, XMLTag_comment ); 164 165 if (commentElt) variable.comment_ = XML::GetNodeValue( commentElt ); 165 166 166 xmlNodePtrunitElt = XML::FindElementByName( current, XMLTag_unit );167 XML::Node unitElt = XML::FindElementByName( current, XMLTag_unit ); 167 168 if (unitElt) variable.unit_ = XML::GetNodeValue( unitElt ); 168 169 169 xmlNodePtrregexpElt = XML::FindElementByName( current, XMLTag_regexp );170 XML::Node regexpElt = XML::FindElementByName( current, XMLTag_regexp ); 170 171 if (regexpElt) variable.regexp_ = XML::GetNodeValue( regexpElt ); 171 172 172 xmlNodePtrformatElt = XML::FindElementByName( current, XMLTag_format );173 XML::Node formatElt = XML::FindElementByName( current, XMLTag_format ); 173 174 if (formatElt) variable.format_ = XML::GetNodeValue( formatElt ); 174 175 … … 182 183 throw WrapperFileParsingException(HERE) << "Unknown type (" << type_ 183 184 << ") for variable in wrapper file " << pathToFile 184 << " at line " << xmlGetLineNo(current);185 << " at line " << XML::GetNodeLineNumber( current ); 185 186 } 186 187 … … 193 194 throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_computed_gradient << " attribute (" << computedGradient_ 194 195 << ") for variable in wrapper file " << pathToFile 195 << " at line " << xmlGetLineNo(current);196 << " at line " << XML::GetNodeLineNumber( current ); 196 197 } 197 198 … … 213 214 214 215 WrapperFunctionDescription functionDesc; 215 xmlNodePtrfunctionElt = XML::FindElementByName( descriptionElt, XMLTag_function );216 XML::Node functionElt = XML::FindElementByName( descriptionElt, XMLTag_function ); 216 217 functionDesc.name_ = XML::GetNodeValue( functionElt ); 217 218 … … 224 225 throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_provided << " attribute (" << functionProvided_ 225 226 << ") for variable in wrapper file " << pathToFile 226 << " at line " << xmlGetLineNo(functionElt);227 << " at line " << XML::GetNodeLineNumber( functionElt ); 227 228 } 228 229 data_.setFunctionDescription( functionDesc ); … … 235 236 236 237 WrapperFunctionDescription gradientDesc; 237 xmlNodePtrgradientElt = XML::FindElementByName( descriptionElt, XMLTag_gradient );238 XML::Node gradientElt = XML::FindElementByName( descriptionElt, XMLTag_gradient ); 238 239 gradientDesc.name_ = XML::GetNodeValue( gradientElt ); 239 240 … … 246 247 throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_provided << " attribute (" << gradientProvided_ 247 248 << ") for variable in wrapper file " << pathToFile 248 << " at line " << xmlGetLineNo(gradientElt);249 << " at line " << XML::GetNodeLineNumber( gradientElt ); 249 250 } 250 251 data_.setGradientDescription( gradientDesc ); … … 257 258 258 259 WrapperFunctionDescription hessianDesc; 259 xmlNodePtrhessianElt = XML::FindElementByName( descriptionElt, XMLTag_hessian );260 XML::Node hessianElt = XML::FindElementByName( descriptionElt, XMLTag_hessian ); 260 261 hessianDesc.name_ = XML::GetNodeValue( hessianElt ); 261 262 … … 268 269 throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_provided << " attribute (" << hessianProvided_ 269 270 << ") for variable in wrapper file " << pathToFile 270 << " at line " << xmlGetLineNo(hessianElt);271 << " at line " << XML::GetNodeLineNumber( hessianElt ); 271 272 } 272 273 data_.setHessianDescription( hessianDesc ); … … 277 278 278 279 279 xmlNodePtrexternalCodeElt = XML::FindElementByName( wrapperElt, XMLTag_external_code );280 xmlNodePtrdataElt = XML::FindElementByName( externalCodeElt, XMLTag_data );280 XML::Node externalCodeElt = XML::FindElementByName( wrapperElt, XMLTag_external_code ); 281 XML::Node dataElt = XML::FindElementByName( externalCodeElt, XMLTag_data ); 281 282 WrapperData::FileListType fileList; 282 if ( dataElt && dataElt->children) {283 for ( xmlNodePtr current = dataElt->children; current; current = current->next) {283 if (XML::IsElement(dataElt)) { 284 for (XML::Node current = XML::GetFirstChild(dataElt); current; current = XML::GetNextNode(current)) { 284 285 if (XML::IsElement(current, XMLTag_file)) { 285 286 WrapperDataFile file; 286 287 287 xmlNodePtrnameElt = XML::FindElementByName( current, XMLTag_name );288 XML::Node nameElt = XML::FindElementByName( current, XMLTag_name ); 288 289 if (nameElt) file.name_ = XML::GetNodeValue( nameElt ); 289 290 290 xmlNodePtrpathElt = XML::FindElementByName( current, XMLTag_path );291 XML::Node pathElt = XML::FindElementByName( current, XMLTag_path ); 291 292 file.path_ = XML::GetNodeValue( pathElt ); 292 293 293 xmlNodePtrsubstElt = XML::FindElementByName( current, XMLTag_subst );294 XML::Node substElt = XML::FindElementByName( current, XMLTag_subst ); 294 295 if (substElt) file.subst_ = XML::GetNodeValue( substElt ); 295 296 … … 303 304 throw WrapperFileParsingException(HERE) << "Unknown type (" << type_ 304 305 << ") for file in wrapper file " << pathToFile 305 << " at line " << xmlGetLineNo(current);306 << " at line " << XML::GetNodeLineNumber( current ); 306 307 } 307 308 … … 321 322 322 323 WrapperParameter parameters; 323 xmlNodePtrwrapModeElt = XML::FindElementByName( externalCodeElt, XMLTag_wrap_mode );324 XML::Node wrapModeElt = XML::FindElementByName( externalCodeElt, XMLTag_wrap_mode ); 324 325 String wrapType_ = XML::GetAttributeByName( wrapModeElt, XMLTag_type ); 325 326 if (wrapType_ == XMLAttr_static_link) parameters.mode_ = WrapperMode::STATICLINK; … … 330 331 throw WrapperFileParsingException(HERE) << "Unknown type (" << wrapType_ 331 332 << ") for " << XMLTag_wrap_mode << " in wrapper file " << pathToFile 332 << " at line " << xmlGetLineNo(wrapModeElt);333 << " at line " << XML::GetNodeLineNumber( wrapModeElt ); 333 334 } 334 335 … … 341 342 throw WrapperFileParsingException(HERE) << "Unknown state (" << wrapState_ 342 343 << ") for " << XMLTag_wrap_mode << " in wrapper file " << pathToFile 343 << " at line " << xmlGetLineNo(wrapModeElt);344 } 345 346 347 xmlNodePtrinDataTransferElt = XML::FindElementByName( wrapModeElt, XMLTag_in_data_transfer );344 << " at line " << XML::GetNodeLineNumber( wrapModeElt ); 345 } 346 347 348 XML::Node inDataTransferElt = XML::FindElementByName( wrapModeElt, XMLTag_in_data_transfer ); 348 349 String inMode_ = XML::GetAttributeByName( inDataTransferElt, XMLTag_mode ); 349 350 if (inMode_ == XMLAttr_files) parameters.in_ = WrapperDataTransfer::FILES; … … 356 357 throw WrapperFileParsingException(HERE) << "Unknown mode (" << inMode_ 357 358 << ") for " << XMLTag_in_data_transfer << " in wrapper file " << pathToFile 358 << " at line " << xmlGetLineNo(inDataTransferElt);359 } 360 361 362 xmlNodePtroutDataTransferElt = XML::FindElementByName( wrapModeElt, XMLTag_out_data_transfer );359 << " at line " << XML::GetNodeLineNumber( inDataTransferElt ); 360 } 361 362 363 XML::Node outDataTransferElt = XML::FindElementByName( wrapModeElt, XMLTag_out_data_transfer ); 363 364 String outMode_ = XML::GetAttributeByName( outDataTransferElt, XMLTag_mode ); 364 365 if (outMode_ == XMLAttr_files) parameters.out_ = WrapperDataTransfer::FILES; … … 371 372 throw WrapperFileParsingException(HERE) << "Unknown mode (" << outMode_ 372 373 << ") for " << XMLTag_out_data_transfer << " in wrapper file " << pathToFile 373 << " at line " << xmlGetLineNo(outDataTransferElt);374 } 375 376 377 xmlNodePtrcommandElt = XML::FindElementByName( externalCodeElt, XMLTag_command );374 << " at line " << XML::GetNodeLineNumber( outDataTransferElt ); 375 } 376 377 378 XML::Node commandElt = XML::FindElementByName( externalCodeElt, XMLTag_command ); 378 379 parameters.command_ = XML::GetNodeValue( commandElt ); 379 380 … … 387 388 388 389 389 Log::Debug(OSS() << "file " << pathToFile << " parsed"); 390 } 391 390 Log::Debug(OSS() << "File " << pathToFile << " parsed"); 391 } 392 393 394 /* Write the internal data to a wrapper file */ 395 void WrapperFile::writeFile(const FileName & pathToFile) 396 { 397 XMLDoc doc; 398 399 // Set the DTD of the wrapper file 400 const FileName DTDPath = Path::GetStandardWrapperDirectory() + "/" + DTDFileName; 401 XML::SetDTD( doc, XMLTag_wrapper, DTDPath ); 402 403 // Create <wrappper> node 404 XML::Node wrapper = XML::NewNode( XMLTag_wrapper ); 405 XML::SetRootNode( doc, wrapper ); 406 407 // TODO: Add DTD node 408 409 // Create <library> node 410 XML::Node library = XML::NewNode( XMLTag_library ); 411 XML::AddChild( wrapper, library ); 412 413 // Create <path> node 414 XML::Node libraryPath = XML::NewNode( XMLTag_path, data_.getLibraryPath() ); 415 XML::AddChild( library, libraryPath ); 416 417 // Create <description> node 418 XML::Node description = XML::NewNode( XMLTag_description ); 419 XML::AddChild( library, description ); 420 421 // Create <variable-list> node 422 XML::Node variableList = XML::NewNode( XMLTag_variable_list ); 423 XML::AddChild( description, variableList ); 424 425 // Create <variable> node 426 const WrapperData::VariableListType vList = data_.getVariableList(); 427 for (WrapperData::VariableListType::const_iterator it = vList.begin(); it != vList.end(); ++it) { 428 const WrapperDataVariable & theVar = (*it); 429 XML::Node variable = XML::NewNode( XMLTag_variable ); 430 XML::SetAttribute( variable, XMLTag_id, theVar.id_ ); 431 XML::SetAttribute( variable, XMLTag_type, (theVar.type_ != WrapperDataVariableType::OUT) ? XMLAttr_in : XMLAttr_out ); 432 if (theVar.gradient_ == WrapperComputedGradient::YES) XML::SetAttribute( variable, XMLTag_computed_gradient, XMLAttr_yes ); 433 XML::AddChild( variableList, variable ); 434 435 // Create <comment> node 436 if (! theVar.comment_.empty()) { 437 XML::Node comment = XML::NewNode( XMLTag_comment, theVar.comment_ ); 438 XML::AddChild( variable, comment ); 439 } 440 441 // Create <unit> node 442 if (! theVar.unit_.empty()) { 443 XML::Node unit = XML::NewNode( XMLTag_unit, theVar.unit_ ); 444 XML::AddChild( variable, unit ); 445 } 446 447 // Create <regexp> node 448 if (! theVar.regexp_.empty()) { 449 XML::Node regexp = XML::NewNode( XMLTag_regexp, theVar.regexp_ ); 450 XML::AddChild( variable, regexp ); 451 } 452 453 // Create <format> node 454 if (! theVar.format_.empty()) { 455 XML::Node format = XML::NewNode( XMLTag_format, theVar.format_ ); 456 XML::AddChild( variable, format ); 457 } 458 } /* end for ( it = vList.begin() ; ... ) */ 459 460 461 // Create <function> node 462 const WrapperFunctionDescription funcDescription = data_.getFunctionDescription(); 463 XML::Node function = XML::NewNode( XMLTag_function, funcDescription.name_ ); 464 XML::SetAttribute( function, XMLTag_provided, (funcDescription.provided_ == WrapperSymbolProvided::YES) ? XMLAttr_yes : XMLAttr_no ); 465 XML::AddChild( description, function ); 466 467 // Create <gradient> node 468 const WrapperFunctionDescription gradDescription = data_.getGradientDescription(); 469 XML::Node gradient = XML::NewNode( XMLTag_gradient, gradDescription.name_ ); 470 XML::SetAttribute( gradient, XMLTag_provided, (gradDescription.provided_ == WrapperSymbolProvided::YES) ? XMLAttr_yes : XMLAttr_no ); 471 XML::AddChild( description, gradient ); 472 473 // Create <hessian> node 474 const WrapperFunctionDescription hessDescription = data_.getHessianDescription(); 475 XML::Node hessian = XML::NewNode( XMLTag_hessian, hessDescription.name_ ); 476 XML::SetAttribute( hessian, XMLTag_provided, (hessDescription.provided_ == WrapperSymbolProvided::YES) ? XMLAttr_yes : XMLAttr_no ); 477 XML::AddChild( description, hessian ); 478 479 480 481 // Create <external-code> node 482 XML::Node externalCode = XML::NewNode( XMLTag_external_code ); 483 XML::AddChild( wrapper, externalCode ); 484 485 // Create <data> node 486 XML::Node data = XML::NewNode( XMLTag_data ); 487 XML::AddChild( externalCode, data ); 488 489 // Create <file> node 490 const WrapperData::FileListType fList = data_.getFileList(); 491 for (WrapperData::FileListType::const_iterator it = fList.begin(); it != fList.end(); ++it) { 492 const WrapperDataFile & theFile = (*it); 493 XML::Node file = XML::NewNode( XMLTag_file ); 494 XML::SetAttribute( file, XMLTag_id, theFile.id_ ); 495 XML::SetAttribute( file, XMLTag_type, (theFile.type_ != WrapperDataFileType::OUT) ? XMLAttr_in : XMLAttr_out ); 496 XML::AddChild( data, file ); 497 498 // Create <name> node 499 if (! theFile.name_.empty()) { 500 XML::Node name = XML::NewNode( XMLTag_name, theFile.name_ ); 501 XML::AddChild( file, name ); 502 } 503 504 // Create <path> node 505 if (! theFile.path_.empty()) { 506 XML::Node path = XML::NewNode( XMLTag_path, theFile.path_ ); 507 XML::AddChild( file, path ); 508 } 509 510 // Create <subst> node 511 if (! theFile.subst_.empty()) { 512 XML::Node subst = XML::NewNode( XMLTag_subst, theFile.subst_ ); 513 XML::AddChild( file, subst ); 514 } 515 } /* end for ( it = fList.begin() ; ... ) */ 516 517 518 // Create <wrap-mode> node 519 const WrapperParameter & parameters = data_.getParameters(); 520 XML::Node wrapMode = XML::NewNode( XMLTag_wrap_mode ); 521 XML::SetAttribute( wrapMode, XMLTag_type, WrapperConfigurationModeAsString[ parameters.mode_ ]); 522 XML::SetAttribute( wrapMode, XMLTag_state, WrapperConfigurationStateAsString[ parameters.state_ ]); 523 XML::AddChild( externalCode, wrapMode ); 524 525 // Create <in-data-transfer> node 526 XML::Node inDataTransfer = XML::NewNode( XMLTag_in_data_transfer ); 527 XML::SetAttribute( inDataTransfer, XMLTag_mode, WrapperDataTransferModeAsString[ parameters.in_ ]); 528 XML::AddChild( wrapMode, inDataTransfer ); 529 530 // Create <out-data-transfer> node 531 XML::Node outDataTransfer = XML::NewNode( XMLTag_out_data_transfer ); 532 XML::SetAttribute( outDataTransfer, XMLTag_mode, WrapperDataTransferModeAsString[ parameters.out_ ]); 533 XML::AddChild( wrapMode, outDataTransfer ); 534 535 // Create <command> node 536 XML::Node command = XML::NewNode( XMLTag_command, parameters.command_ ); 537 XML::AddChild( externalCode, command ); 538 539 Bool ok = doc.validate(); 540 if (!ok) throw InternalException(HERE) << "The generated wrapper does not conform to DTD. Report bug."; 541 542 // Write out the document to a file 543 doc.save( pathToFile ); 544 } 392 545 393 546 #else … … 411 564 { 412 565 // TODO 413 throw WrapperFileParsingException("In void WrapperFile::parseFile(const FileName & pathToFile). Not yet implemented."); 414 } 415 566 throw WrapperFileParsingException(HERE) << "In void WrapperFile::parseFile(const FileName & pathToFile). Not yet implemented."; 567 } 568 569 /* Write the internal data to a wrapper file */ 570 void WrapperFile::writeFile(const FileName & pathToFile) 571 { 572 // TODO 573 throw NotYetImplementedException(HERE) << "In void WrapperFile::writeFile(const FileName & pathToFile)."; 574 } 416 575 #endif 417 576 trunk/lib/src/Base/Func/WrapperFile.hxx
r990 r1003 75 75 static const String extension_; 76 76 77 /** The environment variable name */78 static const String openturnsWrapperPathVariableName_;79 80 /** The HOME subdirectory path */81 static const String homeSubdirectory_;82 83 /** The 'prefix' subdirectory path */84 static const String prefixSubdirectory_;85 86 87 88 77 89 78 public: … … 108 97 void setWrapperData(const WrapperData & data); 109 98 const WrapperData & getWrapperData() const; 99 100 /** Write the internal data to a wrapper file */ 101 void writeFile(const FileName & pathToFile); 110 102 111 103
