Changeset 1004

Show
Ignore:
Timestamp:
11/03/08 20:48:22 (2 months ago)
Author:
lebrun
Message:

MERGE: merging from trunk into lebrun/devel (rev. 998:1003)
lebrun/devel> svn merge -r 998:1003 https://.../trunk

Synchronization with trunk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/lebrun/devel/lib/src/Base/Common/Path.cxx

    r971 r1004  
    8787      } 
    8888 
     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      } 
    8996 
    9097 
     
    134141 
    135142        // ... search in ${prefix}/wrappers 
    136         FileName directory = DATA_PATH; 
    137         directory += Path::PrefixWrapperSubdirectory_; 
     143        FileName directory = Path::GetStandardWrapperDirectory(); 
    138144        directoryList.push_back(directory); 
    139145 
  • branches/lebrun/devel/lib/src/Base/Common/Path.hxx

    r823 r1004  
    5252 
    5353        typedef std::vector<FileName> DirectoryList; 
     54 
     55        /** The directory where installed wrappers and DTD are */ 
     56        static FileName GetStandardWrapperDirectory(); 
    5457 
    5558        /** 
  • branches/lebrun/devel/lib/src/Base/Common/XMLToolbox.cxx

    r991 r1004  
    9393      } 
    9494 
     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 
    95122 
    96123      String XML::ToString(const xmlString & st) 
     
    133160 
    134161 
    135       String XML::GetAttributeByName(const Node & parent, const String & name) 
     162      String XML::GetAttributeByName(const Node & node, const String & name) 
    136163      { 
    137164        String attrVal; 
    138         if (parent) { 
     165        if (node) { 
    139166          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() ); 
    142169            attrVal = String(val.begin(), val.end()); 
    143170          } 
     
    147174 
    148175 
    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) { 
    152179          xmlString aAttr  = xmlString( attribute.begin(), attribute.end() ); 
    153180          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) 
    160187      { 
    161188        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) { 
    164191            if (IsElement(cur, name)) { 
    165192              break; 
     
    172199 
    173200 
    174       String XML::GetNodeValue(const Node & parent
     201      String XML::GetNodeValue(const Node & node
    175202      { 
    176203        String value; 
    177204        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) { 
    180207            if (IsText(cur)) { 
    181208              xmlString val = cur->content; 
     
    189216 
    190217 
    191       String XML::GetNodeName(const Node & parent
     218      String XML::GetNodeName(const Node & node
    192219      { 
    193220        String name; 
    194         if (parent) { 
    195           xmlString aName = parent->name; 
     221        if (node) { 
     222          xmlString aName = node->name; 
    196223          name = String( aName.begin(), aName.end() ); 
    197224        } 
     
    199226      } 
    200227 
     228 
     229 
     230      UnsignedLong XML::GetNodeLineNumber(const Node & node) 
     231      { 
     232        UnsignedLong lineno = 0; 
     233        if (node) lineno = xmlGetLineNo(node); 
     234        return lineno; 
     235      } 
    201236 
    202237 
     
    255290      } 
    256291 
     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      } 
    257298 
    258299 
  • branches/lebrun/devel/lib/src/Base/Common/XMLToolbox.hxx

    r991 r1004  
    5555      class XMLDoc { 
    5656        xmlDocPtr doc_; 
     57 
    5758      public: 
     59 
    5860        XMLDoc(); 
    59         XMLDoc(const XMLDoc & other); 
    60         XMLDoc(const FileName & pathToFile); 
     61        XMLDoc( const XMLDoc & other ); 
     62        XMLDoc( const FileName & pathToFile ); 
    6163        ~XMLDoc() throw(); 
    62         XMLDoc & operator =(const XMLDoc & other); 
     64 
     65        XMLDoc & operator =( const XMLDoc & other ); 
     66 
    6367        operator xmlDocPtr(); 
    6468        operator const xmlDocPtr() const; 
     69 
    6570        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; 
    6675      }; 
    6776 
     
    8291 
    8392        /** Convert XML string to basic string */ 
    84         static String ToString(const xmlString & st); 
     93        static String ToString( const xmlString & st ); 
    8594 
    8695        /** Returns true if node 'elt' is an XML text node */ 
    87         static Bool IsText(const Node & elt); 
     96        static Bool IsText( const Node & elt ); 
    8897 
    8998        /** Returns true if node 'elt' is an XML Element node */ 
    90         static Bool IsElement(const Node & elt); 
     99        static Bool IsElement( const Node & elt ); 
    91100 
    92101        /** 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 ); 
    94103 
    95104        /** 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 ); 
    97106 
    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 ); 
    100109 
    101110        /** 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 ); 
    103112         
    104113        /** 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 ); 
    106115 
    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 ); 
    109118 
    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 ); 
    112124 
    113125        /** 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 ); 
    117129 
    118130        /** 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 ); 
    120132 
    121133        /** Get/Set the root node of an XML file */ 
     
    127139        static Node GetNextNode( const Node & node ); 
    128140         
     141        /** Set the DTD of the document */ 
     142        static void SetDTD( const XMLDoc & doc, const String & name, const String & path ); 
     143 
    129144      }; /* end class XML */ 
    130145 
  • branches/lebrun/devel/lib/src/Base/Func/WrapperFile.cxx

    r991 r1004  
    5454      using Common::WrapperFileParsingException; 
    5555      using Common::FileNotFoundException; 
     56      using Common::NotYetImplementedException; 
     57      using Common::InternalException; 
    5658      using Common::Log; 
    5759      using Common::Path; 
     
    6062#ifdef XML_SUPPORTED 
    6163      const String WrapperFile::extension_ = ".xml"; 
     64      static const FileName DTDFileName    = "wrapper.dtd"; 
    6265#else 
    6366      const String WrapperFile::extension_ = ".txt"; 
    6467#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"; 
    7468 
    7569 
     
    109103      } 
    110104 
    111 #if defined HAS_LIBXML2 
     105#ifdef XML_SUPPORTED 
    112106 
    113107      using Common::XMLDoc; 
     
    132126        throw(WrapperFileParsingException) 
    133127      { 
     128        Log::Debug(OSS() << "Try parsing file " << pathToFile); 
     129 
    134130        // Load the wrapper file 
    135131        XMLDoc doc( pathToFile ); 
    136132 
     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 
    137138        // Check it is an OpenTURNS' one 
    138         xmlNodePtr wrapperElt = xmlDocGetRootElement( doc ); 
     139        XML::Node wrapperElt = XML::GetRootNode( doc ); 
    139140        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 )) 
    141142          throw WrapperFileParsingException(HERE) << "Wrapper file " << pathToFile 
    142                                                   << " has an invalid root element (" << wrapperElt->name << ")" 
    143                                                   << " at line " << xmlGetLineNo(wrapperElt); 
    144  
    145         xmlNodePtr libraryElt     = XML::FindElementByName( wrapperElt, XMLTag_library ); 
    146         xmlNodePtr libraryPathElt = 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 ); 
    147148        String  libraryPath       = XML::GetNodeValue( libraryPathElt ); 
    148149        if (libraryPath.empty()) throw WrapperFileParsingException(HERE) << "Library path tag not found in wrapper file " << pathToFile; 
     
    153154 
    154155 
    155         xmlNodePtr descriptionElt  = XML::FindElementByName( libraryElt, XMLTag_description ); 
    156         xmlNodePtr variableListElt = 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 ); 
    157158        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)) { 
    160161            if (XML::IsElement(current, XMLTag_variable)) { 
    161162              WrapperDataVariable variable; 
    162163 
    163               xmlNodePtr commentElt = XML::FindElementByName( current, XMLTag_comment ); 
     164              XML::Node commentElt = XML::FindElementByName( current, XMLTag_comment ); 
    164165              if (commentElt) variable.comment_ = XML::GetNodeValue( commentElt ); 
    165166               
    166               xmlNodePtr unitElt    = XML::FindElementByName( current, XMLTag_unit ); 
     167              XML::Node unitElt    = XML::FindElementByName( current, XMLTag_unit ); 
    167168              if (unitElt) variable.unit_ = XML::GetNodeValue( unitElt ); 
    168169               
    169               xmlNodePtr regexpElt  = XML::FindElementByName( current, XMLTag_regexp ); 
     170              XML::Node regexpElt  = XML::FindElementByName( current, XMLTag_regexp ); 
    170171              if (regexpElt) variable.regexp_ = XML::GetNodeValue( regexpElt ); 
    171172               
    172               xmlNodePtr formatElt  = XML::FindElementByName( current, XMLTag_format ); 
     173              XML::Node formatElt  = XML::FindElementByName( current, XMLTag_format ); 
    173174              if (formatElt) variable.format_ = XML::GetNodeValue( formatElt ); 
    174175 
     
    182183                throw WrapperFileParsingException(HERE) << "Unknown type (" << type_ 
    183184                                                        << ") for variable in wrapper file " << pathToFile 
    184                                                         << " at line " << xmlGetLineNo(current); 
     185                                                        << " at line " << XML::GetNodeLineNumber( current ); 
    185186              } 
    186187               
     
    193194                throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_computed_gradient << " attribute (" << computedGradient_ 
    194195                                                        << ") for variable in wrapper file " << pathToFile 
    195                                                         << " at line " << xmlGetLineNo(current); 
     196                                                        << " at line " << XML::GetNodeLineNumber( current ); 
    196197              } 
    197198               
     
    213214 
    214215        WrapperFunctionDescription functionDesc; 
    215         xmlNodePtr functionElt = XML::FindElementByName( descriptionElt, XMLTag_function ); 
     216        XML::Node functionElt = XML::FindElementByName( descriptionElt, XMLTag_function ); 
    216217        functionDesc.name_     = XML::GetNodeValue( functionElt ); 
    217218 
     
    224225          throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_provided << " attribute (" << functionProvided_ 
    225226                                                  << ") for variable in wrapper file " << pathToFile 
    226                                                   << " at line " << xmlGetLineNo(functionElt); 
     227                                                  << " at line " << XML::GetNodeLineNumber( functionElt ); 
    227228        } 
    228229        data_.setFunctionDescription( functionDesc ); 
     
    235236 
    236237        WrapperFunctionDescription gradientDesc; 
    237         xmlNodePtr gradientElt = XML::FindElementByName( descriptionElt, XMLTag_gradient ); 
     238        XML::Node gradientElt = XML::FindElementByName( descriptionElt, XMLTag_gradient ); 
    238239        gradientDesc.name_     = XML::GetNodeValue( gradientElt ); 
    239240 
     
    246247          throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_provided << " attribute (" << gradientProvided_ 
    247248                                                  << ") for variable in wrapper file " << pathToFile 
    248                                                   << " at line " << xmlGetLineNo(gradientElt); 
     249                                                  << " at line " << XML::GetNodeLineNumber( gradientElt ); 
    249250        } 
    250251        data_.setGradientDescription( gradientDesc ); 
     
    257258 
    258259        WrapperFunctionDescription hessianDesc; 
    259         xmlNodePtr hessianElt = XML::FindElementByName( descriptionElt, XMLTag_hessian ); 
     260        XML::Node hessianElt = XML::FindElementByName( descriptionElt, XMLTag_hessian ); 
    260261        hessianDesc.name_     = XML::GetNodeValue( hessianElt ); 
    261262 
     
    268269          throw WrapperFileParsingException(HERE) << "Unknown " << XMLTag_provided << " attribute (" << hessianProvided_ 
    269270                                                  << ") for variable in wrapper file " << pathToFile 
    270                                                   << " at line " << xmlGetLineNo(hessianElt); 
     271                                                  << " at line " << XML::GetNodeLineNumber( hessianElt ); 
    271272        } 
    272273        data_.setHessianDescription( hessianDesc ); 
     
    277278 
    278279 
    279         xmlNodePtr externalCodeElt = XML::FindElementByName( wrapperElt, XMLTag_external_code ); 
    280         xmlNodePtr dataElt         = XML::FindElementByName( externalCodeElt, XMLTag_data ); 
     280        XML::Node externalCodeElt = XML::FindElementByName( wrapperElt, XMLTag_external_code ); 
     281        XML::Node dataElt         = XML::FindElementByName( externalCodeElt, XMLTag_data ); 
    281282        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)) { 
    284285            if (XML::IsElement(current, XMLTag_file)) { 
    285286              WrapperDataFile file; 
    286287 
    287               xmlNodePtr nameElt  = XML::FindElementByName( current, XMLTag_name ); 
     288              XML::Node nameElt  = XML::FindElementByName( current, XMLTag_name ); 
    288289              if (nameElt) file.name_ = XML::GetNodeValue( nameElt ); 
    289290               
    290               xmlNodePtr pathElt  = XML::FindElementByName( current, XMLTag_path ); 
     291              XML::Node pathElt  = XML::FindElementByName( current, XMLTag_path ); 
    291292              file.path_          = XML::GetNodeValue( pathElt ); 
    292293               
    293               xmlNodePtr substElt = XML::FindElementByName( current, XMLTag_subst ); 
     294              XML::Node substElt = XML::FindElementByName( current, XMLTag_subst ); 
    294295              if (substElt) file.subst_ = XML::GetNodeValue( substElt ); 
    295296               
     
    303304                throw WrapperFileParsingException(HERE) << "Unknown type (" << type_ 
    304305                                                        << ") for file in wrapper file " << pathToFile 
    305                                                         << " at line " << xmlGetLineNo(current); 
     306                                                        << " at line " << XML::GetNodeLineNumber( current ); 
    306307              } 
    307308               
     
    321322 
    322323        WrapperParameter parameters; 
    323         xmlNodePtr wrapModeElt = XML::FindElementByName( externalCodeElt, XMLTag_wrap_mode ); 
     324        XML::Node wrapModeElt = XML::FindElementByName( externalCodeElt, XMLTag_wrap_mode ); 
    324325        String  wrapType_      = XML::GetAttributeByName( wrapModeElt, XMLTag_type ); 
    325326        if (wrapType_ == XMLAttr_static_link) parameters.mode_ = WrapperMode::STATICLINK; 
     
    330331          throw WrapperFileParsingException(HERE) << "Unknown type (" << wrapType_ 
    331332                                                  << ") for " << XMLTag_wrap_mode << " in wrapper file " << pathToFile 
    332                                                   << " at line " << xmlGetLineNo(wrapModeElt); 
     333                                                  << " at line " << XML::GetNodeLineNumber( wrapModeElt ); 
    333334        } 
    334335 
     
    341342          throw WrapperFileParsingException(HERE) << "Unknown state (" << wrapState_ 
    342343                                                  << ") for " << XMLTag_wrap_mode << " in wrapper file " << pathToFile 
    343                                                   << " at line " << xmlGetLineNo(wrapModeElt); 
    344         } 
    345  
    346  
    347         xmlNodePtr inDataTransferElt = 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 ); 
    348349        String  inMode_              = XML::GetAttributeByName( inDataTransferElt, XMLTag_mode ); 
    349350        if (inMode_ == XMLAttr_files) parameters.in_ = WrapperDataTransfer::FILES; 
     
    356357          throw WrapperFileParsingException(HERE) << "Unknown mode (" << inMode_ 
    357358                                                  << ") for " << XMLTag_in_data_transfer << " in wrapper file " << pathToFile 
    358                                                   << " at line " << xmlGetLineNo(inDataTransferElt); 
    359         } 
    360  
    361  
    362         xmlNodePtr outDataTransferElt = 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 ); 
    363364        String  outMode_              = XML::GetAttributeByName( outDataTransferElt, XMLTag_mode ); 
    364365        if (outMode_ == XMLAttr_files) parameters.out_ = WrapperDataTransfer::FILES; 
     
    371372          throw WrapperFileParsingException(HERE) << "Unknown mode (" << outMode_ 
    372373                                                  << ") for " << XMLTag_out_data_transfer << " in wrapper file " << pathToFile 
    373                                                   << " at line " << xmlGetLineNo(outDataTransferElt); 
    374         } 
    375  
    376  
    377         xmlNodePtr commandElt = XML::FindElementByName( externalCodeElt, XMLTag_command ); 
     374                                                  << " at line " << XML::GetNodeLineNumber( outDataTransferElt ); 
     375        } 
     376 
     377 
     378        XML::Node commandElt = XML::FindElementByName( externalCodeElt, XMLTag_command ); 
    378379        parameters.command_   = XML::GetNodeValue( commandElt ); 
    379380 
     
    387388 
    388389 
    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      } 
    392545 
    393546#else 
     
    411564      { 
    412565        // 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      } 
    416575#endif 
    417576 
  • branches/lebrun/devel/lib/src/Base/Func/WrapperFile.hxx

    r991 r1004  
    7575        static const String extension_; 
    7676 
    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  
    8877 
    8978      public: 
     
    10897        void setWrapperData(const WrapperData & data); 
    10998        const WrapperData & getWrapperData() const; 
     99 
     100        /** Write the internal data to a wrapper file */ 
     101        void writeFile(const FileName & pathToFile); 
    110102 
    111103