Changeset - 857d43889502
[Not reviewed]
default
0 2 0
Roeland Merks - 15 years ago 2010-05-26 15:51:52
roeland.merks@cwi.nl
I have replaced the instances of strtod for the Qt conversion functions via QLocale. Possibly there is some remaining usage of atof and atoi.

user: Roeland Merks <roeland.merks@cwi.nl>
branch 'default'
changed src/perl/make_parameter_source.pl
changed src/xmlwrite.cpp
2 files changed with 97 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/perl/make_parameter_source.pl
Show inline comments
 
@@ -101,6 +101,8 @@ print cppfile <<END_HEADER;
 
#include "output.h"
 
#include "parse.h"
 
#include "xmlwrite.h"
 
#include "warning.h"
 
#include <QLocale>
 

	
 
using namespace std;
 

	
 
@@ -282,7 +284,8 @@ print cppfile "}\n";
 

	
 
print cppfile "void Parameter::AssignValToPar(const char *namec, const char *valc) {\n";
 
print cppfile;
 

	
 
print cppfile "  QLocale standardlocale(QLocale::C);\n";
 
print cppfile "  bool ok;\n";
 
for ($i=0;$i<$lines;$i++) {
 

	
 
  if ($convtype[$i] eq "label" || $convtype[$i] eq "title") {
 
@@ -300,9 +303,13 @@ for ($i=0;$i<$lines;$i++) {
 
	print cppfile "  $param[$i]=strdup(valc);\n";
 
      } else {
 
	if ($convtype[$i] eq "int") {
 
	  print cppfile "  $param[$i] = (int)strtol(valc, 0, 10);\n";
 
	  print cppfile "  $param[$i] = standardlocale.toInt(valc, &ok);\n";
 
	  print cppfile "  if (!ok) { MyWarning::error(\"Read error: cannot convert string \\\"%s\\\" to integer while reading parameter '$param[$i]' from XML file.\",valc); }\n";
 
	  # print cppfile "  $param[$i] = (int)strtol(valc, 0, 10);\n";
 
	} else {
 
	  print cppfile "  $param[$i] = strtod(valc, 0);\n";
 
	  # print cppfile "  $param[$i] = strtod(valc, 0);\n";
 
	  print cppfile "  $param[$i] = standardlocale.toDouble(valc, &ok);\n";
 
	  print cppfile "  if (!ok) { MyWarning::error(\"Read error: cannot convert string \\\"%s\\\" to double while reading parameter '$param[$i]' from XML file.\",valc); }\n";
 
	}
 
      }
 
    }
src/xmlwrite.cpp
Show inline comments
 
@@ -31,6 +31,7 @@
 
#include <libxml/tree.h>
 
#include <libxml/xpath.h>
 
#include <libxml/xmlreader.h>
 
#include <QLocale>
 
#include "xmlwrite.h"
 
#include "nodeset.h"
 
#include "warning.h"
 
@@ -319,6 +320,8 @@ getnodeset (xmlDocPtr doc, xmlChar *xpat
 
int Cell::XMLRead(xmlNode *cur)  {
 
  
 
  xmlNode *n = cur->xmlChildrenNode;
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 
  
 
  vector<int> tmp_nodes;
 

	
 
@@ -370,7 +373,9 @@ int Cell::XMLRead(xmlNode *cur)  {
 
				  if (nc==0) {
 
					  unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 1002");
 
				  }
 
				  double v = strtod( (char *)nc, 0 );
 
		//double v = strtod( (char *)nc, 0 );
 
		double v=standardlocale.toDouble((char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)nc);
 
				  chem[nv++]=v;
 
				  xmlFree(nc);
 
			  }
 
@@ -388,7 +393,9 @@ int Cell::XMLRead(xmlNode *cur)  {
 
			unique_warning("Token \"area\" not found in xmlwrite.cpp at or around line no. 1018");
 
		}
 
		if (v_str != NULL) {
 
			area = strtod( (char *)v_str, 0);
 
		  //area = strtod( (char *)v_str, 0);
 
			area=standardlocale.toDouble((char *)v_str, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
			xmlFree(v_str);
 
		}
 
	}
 
@@ -400,7 +407,9 @@ int Cell::XMLRead(xmlNode *cur)  {
 
			unique_warning("Token \"target_area\" not found in xmlwrite.cpp at or around line no. 1029");
 
		}
 
    if (v_str != NULL) {
 
      target_area = strtod( (char *)v_str, 0);
 
      //target_area = strtod( (char *)v_str, 0);
 
      	target_area=standardlocale.toDouble((char *)v_str, &ok);
 
	if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 
@@ -413,7 +422,9 @@ int Cell::XMLRead(xmlNode *cur)  {
 
      unique_warning("Token \"target_length\" not found in xmlwrite.cpp at or around line no. 1041");
 
    }
 
    if (v_str != NULL) {
 
      target_length = strtod( (char *)v_str, 0);
 
      //target_length = strtod( (char *)v_str, 0);
 
      target_length=standardlocale.toDouble((char *)v_str, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 
@@ -425,7 +436,9 @@ int Cell::XMLRead(xmlNode *cur)  {
 
      unique_warning("Token \"lambda_celllength\" not found in xmlwrite.cpp at or around line no. 1052");
 
    }
 
    if (v_str != NULL) {
 
      lambda_celllength = strtod( (char *)v_str, 0);
 
      //lambda_celllength = strtod( (char *)v_str, 0);
 
      lambda_celllength=standardlocale.toDouble((char *)v_str, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 
@@ -437,7 +450,9 @@ int Cell::XMLRead(xmlNode *cur)  {
 
      unique_warning("Token \"stiffness\" not found in xmlwrite.cpp at or around line no. 1063");
 
    }
 
    if (v_str != NULL) {
 
      stiffness = strtod( (char *)v_str, 0);
 
      //stiffness = strtod( (char *)v_str, 0);
 
      stiffness=standardlocale.toDouble((char *)v_str, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)v_str);
 
      xmlFree(v_str);
 
    }
 
  }
 
@@ -692,13 +707,17 @@ void Wall::XMLAdd(xmlNode *parent) const
 
vector<double> XMLIO::XMLReadValArray(xmlNode *cur) {
 
  
 
  vector<double> result;
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 
  
 
  xmlNode *valarray_node = cur->xmlChildrenNode;
 
  while (valarray_node!=NULL) {
 
    if (!xmlStrcmp(valarray_node->name, (const xmlChar *)"val")) {
 
      xmlChar *vc = xmlGetProp(valarray_node, BAD_CAST "v");
 
      if (vc) {
 
		  result.push_back(strtod( (const char *)vc, 0));
 
	//result.push_back(strtod( (const char *)vc, 0));
 
	result.push_back(standardlocale.toDouble((char *)vc, &ok));
 
	if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)vc);
 
		  xmlFree(vc);
 
      }
 
      
 
@@ -890,8 +909,15 @@ void Mesh::XMLReadSimtime(const xmlNode 
 
	root_node = (xmlNode *)a_node;
 
	xmlNode *cur;
 
	xmlChar *strsimtime = xmlGetProp(root_node, BAD_CAST "simtime");
 
  
 
  
 
    if (strsimtime) {
 
		double simtime = strtod((const char *)strsimtime, 0);
 
    //double simtime = strtod((const char *)strsimtime, 0);
 
    QLocale standardlocale(QLocale::C);
 
    bool ok;
 
    
 
    double simtime=standardlocale.toDouble((char *)strsimtime, &ok);
 
    if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(char *)strsimtime);
 
		time = simtime;
 
		cerr << "Simtime = " << strsimtime << endl;
 
	} else {
 
@@ -910,10 +936,12 @@ void Mesh::XMLReadPars(const xmlNode * a
 

	
 
void Mesh::XMLReadGeometry(const xmlNode * a_node)
 
{
 
  
 
	xmlNode *root_node;
 
	root_node = (xmlNode *)a_node;
 
	xmlNode *cur;
 
	
 
	QLocale standardlocale(QLocale::C);
 
	bool ok;
 
	// allocate Nodes
 
	cur = root_node->xmlChildrenNode;
 
	while (cur!=NULL) {
 
@@ -950,19 +978,26 @@ void Mesh::XMLReadGeometry(const xmlNode
 
		if ((!xmlStrcmp(cur->name, (const xmlChar *)"cells"))){
 
			xmlChar *offsetxc = xmlGetProp(cur, BAD_CAST "offsetx");
 
			xmlChar *offsetyc = xmlGetProp(cur, BAD_CAST "offsety");
 
			double ox = strtod((const char*)offsetxc, 0);
 
			double oy = strtod((const char*)offsetyc, 0);
 
			
 
			//double ox = strtod((const char*)offsetxc, 0);
 
			double ox=standardlocale.toDouble((const char *)offsetxc, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)offsetxc);
 
			//double oy = strtod((const char*)offsetyc, 0);
 
			double oy=standardlocale.toDouble((const char *)offsetyc, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)offsetyc);
 
			Cell::setOffset(ox, oy);
 
			xmlFree(offsetxc);
 
			xmlFree(offsetyc);
 
			
 
			xmlChar *magnificationc = xmlGetProp(cur, BAD_CAST "magnification");
 
			Cell::SetMagnification(strtod((const char*)magnificationc, 0 ));
 
			//Cell::SetMagnification(strtod((const char*)magnificationc, 0 ));
 
			Cell::SetMagnification(standardlocale.toDouble((const char *)magnificationc, &ok));
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)magnificationc);
 
			xmlFree(magnificationc);
 
			
 
			xmlChar *baseareac = xmlGetProp(cur, BAD_CAST "base_area");
 
			Cell::BaseArea()= strtod((const char *)baseareac, 0 );
 
			//Cell::BaseArea()= strtod((const char *)baseareac, 0 );
 
			Cell::BaseArea() = standardlocale.toDouble((const char *)baseareac, &ok);
 
			if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)baseareac);
 
			xmlFree(baseareac);
 
			
 
			
 
@@ -1021,6 +1056,9 @@ void Mesh::XMLParseTree(const xmlNode *r
 

	
 
void Mesh::XMLReadNodes(xmlNode *root) {
 
	
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
	xmlNode *cur = root;
 
	cur = cur->xmlChildrenNode;
 
	
 
@@ -1036,7 +1074,11 @@ void Mesh::XMLReadNodes(xmlNode *root) {
 
	xmlChar *tlc = xmlGetProp(root, BAD_CAST "target_length");
 
	
 
	if (tlc != 0) {
 
		Node::target_length = strtod( (const char *)tlc, 0 );
 
    //Node::target_length = strtod( (const char *)tlc, 0 );
 
	  
 
    Node::target_length = standardlocale.toDouble((const char *)tlc, &ok);
 
    if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)tlc);
 
		
 
		xmlFree(tlc);
 
	} else {
 
		// note that libxml2 also defines a token "warning"
 
@@ -1073,8 +1115,13 @@ void Mesh::XMLReadNodes(xmlNode *root) {
 
				unique_warning("Token \"sam\" not found in xmlwrite.cpp at or around line.");
 
			}
 
			
 
			double x = strtod( (char *)xc , 0);
 
			double y = strtod( (char *)yc , 0 );
 
      //double x = strtod( (char *)xc , 0);
 
      double x = standardlocale.toDouble((const char *)xc, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)xc);
 
		
 
      //double y = strtod( (char *)yc , 0 );
 
      double y = standardlocale.toDouble((const char *)yc, &ok);
 
      if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)yc);
 
			
 
			Node *new_node = new Node(x,y);
 
			nodes.push_back(new_node);
 
@@ -1121,6 +1168,9 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
	//Node::nnodes=0;
 
	
 
	
 
  QLocale standardlocale(QLocale::C);
 
  bool ok;
 

	
 
	while (cur!=NULL) {
 
		
 
		vector<int> tmp_nodes;
 
@@ -1164,7 +1214,10 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
				if (	nc==0) {
 
					unique_warning("Token \"length\" not found in xmlwrite.cpp at or around line no. 809");
 
				}
 
				double length = strtod( (char *)nc, 0);
 
	//double length = strtod( (char *)nc, 0);
 
	double length = standardlocale.toDouble((const char *)nc, &ok);
 
	if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
				xmlFree(nc);
 
				
 
				
 
@@ -1172,7 +1225,10 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
				
 
				double viz_flux;
 
				if (nc!=0) {
 
					viz_flux = strtod( (char *)nc, 0);
 
	  //viz_flux = strtod( (char *)nc, 0);
 
	  double viz_flux = standardlocale.toDouble((const char *)nc, &ok);
 
	  if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
				} else {
 
					// if the info is not there, we really don't care.
 
					// It is just for visualization anyhow.
 
@@ -1250,7 +1306,10 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
								if (nc==0) {
 
									unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 835");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
		//double v = strtod( (char *)nc, 0 );
 
		double v = standardlocale.toDouble((const char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
								w->transporters1[nv++]=v;
 
								xmlFree(nc);
 
								
 
@@ -1282,7 +1341,10 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
								if (nc==0) {
 
									unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 861");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
		//double v = strtod( (char *)nc, 0 );
 
		double v = standardlocale.toDouble((const char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
								w->transporters2[nv++]=v;
 
								xmlFree(nc);
 
							}
 
@@ -1312,7 +1374,10 @@ void Mesh::XMLReadWalls(xmlNode *root, v
 
								if (nc==0) {
 
									unique_warning("Token \"v\" not found in xmlwrite.cpp at or around line no. 887");
 
								}
 
								double v = strtod( (char *)nc, 0 );
 
		//double v = strtod( (char *)nc, 0 );
 
		double v = standardlocale.toDouble((const char *)nc, &ok);
 
		if (!ok) MyWarning::error("Could not convert \"%s\" to double in XMLRead.",(const char *)nc);
 

	
 
								w->apoplast[nv++]=v;
 
								xmlFree(nc);
 
							}
0 comments (0 inline, 0 general)