From Mathias Froehlich, "We are currently getting issues with locale settings and some osg plugins.

Therefore I have changed all the occurances of atof by asciiToFloat or
asciiToDouble.

I believe that it is safe to do so at least for all the plugins.
Included here are also asciiToFloat conversion of environment variables. One
might argue that these should be locale dependent. But IMO these should be
set and interpreted by osg independent of the current locale.
"
This commit is contained in:
Robert Osfield
2009-06-25 16:07:49 +00:00
parent d167142a59
commit 06abd75198
19 changed files with 50 additions and 46 deletions

View File

@@ -1126,7 +1126,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
}
else if (cur->name == "duration")
{
constructor.setLayerDuration(atof(cur->contents.c_str()));
constructor.setLayerDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (getKeyPosition(cur, keyPosition))
{
@@ -1370,7 +1370,7 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
}
else if (cur->name == "duration")
{
constructor.setSlideDuration(atof(cur->contents.c_str()));
constructor.setSlideDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (getKeyPosition(cur, keyPosition))
{
@@ -1892,7 +1892,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Inp
}
else if (cur->name == "duration")
{
constructor.setPresentationDuration(atof(cur->contents.c_str()));
constructor.setPresentationDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (getKeyPosition(cur, keyPosition))
{

View File

@@ -16,6 +16,7 @@
#include <osg/ArgumentParser>
#include <osg/ApplicationUsage>
#include <osg/Math>
#include <osg/Notify>
#include <set>
@@ -163,8 +164,8 @@ bool ArgumentParser::Parameter::assign(const char* str)
*_value._bool = (strcmp(str,"True")==0 || strcmp(str,"true")==0 || strcmp(str,"TRUE")==0);
break;
}
case Parameter::FLOAT_PARAMETER: *_value._float = atof(str); break;
case Parameter::DOUBLE_PARAMETER: *_value._double = atof(str); break;
case Parameter::FLOAT_PARAMETER: *_value._float = osg::asciiToFloat(str); break;
case Parameter::DOUBLE_PARAMETER: *_value._double = osg::asciiToDouble(str); break;
case Parameter::INT_PARAMETER: *_value._int = atoi(str); break;
case Parameter::UNSIGNED_INT_PARAMETER: *_value._uint = atoi(str); break;
case Parameter::STRING_PARAMETER: *_value._string = str; break;

View File

@@ -111,7 +111,7 @@ void CullSettings::readEnvironmentalVariables()
if ((ptr = getenv("OSG_NEAR_FAR_RATIO")) != 0)
{
_nearFarRatio = atof(ptr);
_nearFarRatio = osg::asciiToDouble(ptr);
osg::notify(osg::INFO)<<"Set near/far ratio to "<<_nearFarRatio<<std::endl;
}

View File

@@ -13,6 +13,7 @@
#include <osg/DisplaySettings>
#include <osg/ArgumentParser>
#include <osg/ApplicationUsage>
#include <osg/Math>
#include <osg/Notify>
#include <osg/ref_ptr>
@@ -268,22 +269,22 @@ void DisplaySettings::readEnvironmentalVariables()
if( (ptr = getenv("OSG_EYE_SEPARATION")) != 0)
{
_eyeSeparation = atof(ptr);
_eyeSeparation = osg::asciiToFloat(ptr);
}
if( (ptr = getenv("OSG_SCREEN_WIDTH")) != 0)
{
_screenWidth = atof(ptr);
_screenWidth = osg::asciiToFloat(ptr);
}
if( (ptr = getenv("OSG_SCREEN_HEIGHT")) != 0)
{
_screenHeight = atof(ptr);
_screenHeight = osg::asciiToFloat(ptr);
}
if( (ptr = getenv("OSG_SCREEN_DISTANCE")) != 0)
{
_screenDistance = atof(ptr);
_screenDistance = osg::asciiToFloat(ptr);
}
if( (ptr = getenv("OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING")) != 0)

View File

@@ -1,4 +1,4 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
@@ -907,7 +907,7 @@ DatabasePager::DatabasePager()
_expiryDelay = 10.0;
if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0)
{
_expiryDelay = atof(ptr);
_expiryDelay = osg::asciiToDouble(ptr);
osg::notify(osg::NOTICE)<<"Expiry delay = "<<_expiryDelay<<std::endl;
}
@@ -926,7 +926,7 @@ DatabasePager::DatabasePager()
}
else
{
setReleaseDelay(atof(ptr));
setReleaseDelay(osg::asciiToDouble(ptr));
}
osg::notify(osg::NOTICE)<<"Release delay = "<<_releaseDelay<<std::endl;
@@ -965,7 +965,7 @@ DatabasePager::DatabasePager()
_maximumNumOfObjectsToCompilePerFrame = 4;
if( (ptr = getenv("OSG_MINIMUM_COMPILE_TIME_PER_FRAME")) != 0)
{
_minimumTimeAvailableForGLCompileAndDeletePerFrame = atof(ptr);
_minimumTimeAvailableForGLCompileAndDeletePerFrame = osg::asciiToDouble(ptr);
}
if( (ptr = getenv("OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME")) != 0)

View File

@@ -36,7 +36,7 @@ static double getHeightOfDriver()
double height = 1.5;
if (getenv("OSG_DRIVE_MANIPULATOR_HEIGHT"))
{
height = atof(getenv("OSG_DRIVE_MANIPULATOR_HEIGHT"));
height = osg::asciiToDouble(getenv("OSG_DRIVE_MANIPULATOR_HEIGHT"));
}
osg::notify(osg::INFO)<<"DriveManipulator::_height set to =="<<height<<std::endl;
return height;

View File

@@ -181,7 +181,7 @@ void VBSPEntity::processItem()
Vec3f VBSPEntity::getVector(std::string str)
{
double x, y, z;
float x, y, z;
// Look for the first non-whitespace
std::string::size_type start = str.find_first_not_of(" \t\r\n", 0);
@@ -190,7 +190,7 @@ Vec3f VBSPEntity::getVector(std::string str)
std::string::size_type end = str.find_first_of(" \t\r\n", start);
if ((end > start) && (start != std::string::npos))
x = atof(str.substr(start, end-start).c_str());
x = osg::asciiToFloat(str.substr(start, end-start).c_str());
else
return Vec3f();
@@ -201,7 +201,7 @@ Vec3f VBSPEntity::getVector(std::string str)
end = str.find_first_of(" \t\r\n", start);
if ((end > start) && (start != std::string::npos))
y = atof(str.substr(start, end-start).c_str());
y = osg::asciiToFloat(str.substr(start, end-start).c_str());
else
return Vec3f();
@@ -214,7 +214,7 @@ Vec3f VBSPEntity::getVector(std::string str)
end = str.length();
if ((end > start) && (start != std::string::npos))
z = atof(str.substr(start, end-start).c_str());
z = osg::asciiToFloat(str.substr(start, end-start).c_str());
else
return Vec3f();

View File

@@ -1932,21 +1932,21 @@ yyreduce:
case 114:
{
yyval.real = atof(flexer->YYText());
yyval.real = osg::asciiToFloat(flexer->YYText());
;}
break;
case 115:
{
yyval.real = atof(flexer->YYText());
yyval.real = osg::asciiToFloat(flexer->YYText());
;}
break;
case 116:
{
yyval.real = atof(flexer->YYText());
yyval.real = osg::asciiToFloat(flexer->YYText());
;}
break;

View File

@@ -518,18 +518,18 @@ input_area_entry :
real : PRTOKEN_FLOAT
{
$$ = atof(flexer->YYText());
$$ = osg::asciiToFloat(flexer->YYText());
}
| PRTOKEN_INTEGER
{
$$ = atof(flexer->YYText());
$$ = osg::asciiToFloat(flexer->YYText());
}
;
floatparam : PRTOKEN_FLOAT
{
$$ = atof(flexer->YYText());
$$ = osg::asciiToFloat(flexer->YYText());
}
;

View File

@@ -858,33 +858,33 @@ class ReaderWriterDW : public osgDB::ReaderWriter
} else if (strncmp(buff, "CurrPhase:",10)==0) {
} else if (strncmp(buff, "numPhases:",10)==0) {
} else if (strncmp(buff, "Opacity:",8)==0) {
float opacity=atof(buff+8);
float opacity=osg::asciiToFloat(buff+8);
matpalet[nmat].setopacity(opacity);
} else if (strncmp(buff, "FallOff:",8)==0) {
float fo=atof(buff+8);
float fo=osg::asciiToFloat(buff+8);
matpalet[nmat].setFallOff(fo);
} else if (strncmp(buff, "InnerHalfAngle:",15)==0) {
float ha=atof(buff+15);
float ha=osg::asciiToFloat(buff+15);
matpalet[nmat].setHalfAngleIn(ha);
} else if (strncmp(buff, "OuterHalfAngle:",15)==0) {
float ha=atof(buff+15);
float ha=osg::asciiToFloat(buff+15);
matpalet[nmat].setHalfAngleOut(ha);
} else if (strncmp(buff, "Brightness:",11)==0) {
float br=atof(buff+11);
float br=osg::asciiToFloat(buff+11);
matpalet[nmat].setBright(br);
} else if (strncmp(buff, "Attentuation:",13)==0) { // oops - they can't spell
matpalet[nmat].setAtten(buff+13);
} else if (strncmp(buff, "MaterialType:",13)==0) {
matpalet[nmat].setType(buff+14);
} else if (strncmp(buff, "SpecularReflectivity:",21)==0) {
float spec=atof(buff+21);
float spec=osg::asciiToFloat(buff+21);
matpalet[nmat].setspecular(spec);
} else if (strncmp(buff, "SmoothnessExponent:",19)==0) {
float spec=atof(buff+19);
float spec=osg::asciiToFloat(buff+19);
matpalet[nmat].setspecexp(spec*128.0f/100.0f); // convert to 0-128 range from percent
} else if (strncmp(buff, "TextureWidthAndHeight:",22)==0) {
char *ct=strchr(buff+22,',');
float repx=atof(buff+23), repy=atof(ct+1);
float repx=osg::asciiToFloat(buff+23), repy=osg::asciiToFloat(ct+1);
matpalet[nmat].settxrep(repx, repy);
} else if (strncmp(buff, "PictureFile:",12)==0) {
char *end=strchr(buff,'\n'); // end of line

View File

@@ -183,7 +183,7 @@ DataOutputStream::DataOutputStream(std::ostream * ostream, const osgDB::ReaderWr
if (numOfCharInNumber>0)
{
std::string numberString = optionsString.substr(endOfToken+1, numOfCharInNumber);
_maximumErrorToSizeRatio = atof(numberString.c_str());
_maximumErrorToSizeRatio = osg::asciiToDouble(numberString.c_str());
osg::notify(osg::DEBUG_INFO)<<"TerrainMaximumErrorToSizeRatio = "<<_maximumErrorToSizeRatio<<std::endl;
}

View File

@@ -58,7 +58,7 @@ class NormalsReader: public osgDB::ReaderWriter
std::string value = opt.substr(index+1);
if( key == "scale" || key == "SCALE" )
{
scale = atof( value.c_str() );
scale = osg::asciiToFloat( value.c_str() );
}
else if( key == "mode" || key == "MODE" )
{

View File

@@ -1126,7 +1126,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
}
else if (cur->name == "duration")
{
constructor.setLayerDuration(atof(cur->contents.c_str()));
constructor.setLayerDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (getKeyPosition(cur, keyPosition))
{
@@ -1370,7 +1370,7 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
}
else if (cur->name == "duration")
{
constructor.setSlideDuration(atof(cur->contents.c_str()));
constructor.setSlideDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (getKeyPosition(cur, keyPosition))
{
@@ -1891,7 +1891,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Inp
}
else if (cur->name == "duration")
{
constructor.setPresentationDuration(atof(cur->contents.c_str()));
constructor.setPresentationDuration(osg::asciiToDouble(cur->contents.c_str()));
}
else if (getKeyPosition(cur, keyPosition))
{

View File

@@ -46,6 +46,8 @@ WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
#include <math.h>
#include <string.h>
#include <osg/Math>
#if defined(_MSC_VER) && defined(OSG_DISABLE_MSVC_WARNINGS)
#pragma warning( disable : 4996 )
#endif
@@ -857,7 +859,7 @@ PlyFile *ply_read(FILE *fp, int *nelems, char ***elem_names)
free (words);
return (NULL);
}
plyfile->version = atof (words[2]);
plyfile->version = osg::asciiToDouble (words[2]);
}
else if (equal_strings (words[0], "element"))
add_element (plyfile, words, nwords);
@@ -2483,7 +2485,7 @@ void get_ascii_item(
case PLY_FLOAT:
case PLY_FLOAT32:
case PLY_DOUBLE:
*double_val = atof (word);
*double_val = osg::asciiToDouble(word);
*int_val = (int) *double_val;
*uint_val = (unsigned int) *double_val;
break;

View File

@@ -539,14 +539,14 @@ bool ReaderWriterTXP::extractChildrenLocations(const std::string& name, int pare
token = strtok(0, "_");
if(!token)
break;
locs[idx].zmin = (float)atof(token);
locs[idx].zmin = osg::asciiToFloat(token);
nbTokenRead++;
// ZMAX
token = strtok(0, "_");
if(!token)
break;
locs[idx].zmax= (float)atof(token);
locs[idx].zmax = osg::asciiToFloat(token);
nbTokenRead++;
locs[idx].lod = parentLod+1;

View File

@@ -102,7 +102,7 @@ TXPParser::TXPParser():
if (getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY"))
{
_defaultMaxAnisotropy = atof(getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY"));
_defaultMaxAnisotropy = osg::asciiToFloat(getenv("OSG_TXP_DEFAULT_MAX_ANISOTROPY"));
}
}

View File

@@ -35,7 +35,7 @@ IncrementalCompileOperation::IncrementalCompileOperation():
const char* ptr = 0;
if( (ptr = getenv("OSG_MINIMUM_COMPILE_TIME_PER_FRAME")) != 0)
{
_minimumTimeAvailableForGLCompileAndDeletePerFrame = atof(ptr);
_minimumTimeAvailableForGLCompileAndDeletePerFrame = osg::asciiToDouble(ptr);
}
if( (ptr = getenv("OSG_MAXIMUM_OBJECTS_TO_COMPILE_PER_FRAME")) != 0)

View File

@@ -76,7 +76,7 @@ void ViewerBase::viewerBaseInit()
str = getenv("OSG_RUN_MAX_FRAME_RATE");
if (str)
{
_runMaxFrameRate = atof(str);
_runMaxFrameRate = osg::asciiToDouble(str);
}
}

View File

@@ -400,7 +400,7 @@ RecordCameraPathHandler::RecordCameraPathHandler(const std::string& filename, fl
const char* str = getenv("OSG_RECORD_CAMERA_PATH_FPS");
if (str)
{
_interval = 1.0f / atof(str);
_interval = 1.0f / osg::asciiToDouble(str);
}
else
{