Changeset 220 for osgVisual/trunk/src


Ignore:
Timestamp:
Feb 2, 2011, 10:14:57 AM (14 years ago)
Author:
Torben Dannhauer
Message:

Added util functions to convert string to bool, int or double.
Modified all files to use this functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • osgVisual/trunk/src/util/visual_util.cpp

    r218 r220  
    536536}
    537537
    538 int util::strToDouble(std::string s)
     538double util::strToDouble(std::string s)
    539539{
    540540        double tmp;
    541541        std::stringstream sstr(s);
    542         sstr >> tmp;
    543         return tmp;
    544 }
    545 
    546 double util::strToInt(std::string s)
     542    if (!(sstr >> tmp))
     543        {
     544                OSG_ALWAYS << __FUNCTION__ << "Warning:Unable to convert "<< s <<" to double, using 0.0 as default!" << std::endl;
     545                return 0.0;
     546        }
     547        else
     548                return tmp;
     549}
     550
     551int util::strToInt(std::string s)
    547552{
    548553        int tmp;
    549554        std::stringstream sstr(s);
    550         sstr >> tmp;
    551         return tmp;
     555        if (!(sstr >> tmp))
     556        {
     557                OSG_ALWAYS << __FUNCTION__ << "Warning:Unable to convert "<< s <<" to int, using 0 as default!" << std::endl;
     558                return 0;
     559        }
     560        else
     561                return tmp;
    552562}
    553563
Note: See TracChangeset for help on using the changeset viewer.