/* Copyright 2005 Nicholas Bishop * * This file is part of SharpConstruct. * * SharpConstruct is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * SharpConstruct is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with SharpConstruct; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Utilities.h" #include "config.h" #include std::stringstream Converter; std::string SharpConstruct::ToString( const double x ) { Converter.str( "" ); Converter << x; return Converter.str(); } std::string SharpConstruct::ToString( const float x ) { // Slow for some reason Converter.str( "" ); Converter << x; return Converter.str(); } std::string SharpConstruct::ToString( const char x ) { Converter.str( "" ); Converter << x; return Converter.str(); } std::string SharpConstruct::ToString( const bool x ) { Converter.str( "" ); Converter << x; return Converter.str(); } float SharpConstruct::ToFloat( std::string x ) { float tmp; std::stringstream v; v << x; v >> tmp; return tmp; } int SharpConstruct::ToInt( std::string x ) { int tmp; std::stringstream v; v << x; v >> tmp; return tmp; } std::string SharpConstruct::StripSpaces( std::string x ) { for( int i = 0; i < static_cast< int >( x.length() ); i++ ) { if( x[ i ] == ' ' ) { x.erase( i, 1 ); i--; } } return x; } double SharpConstruct::Time() { timeval tv; gettimeofday( &tv, NULL ); static long int orig = tv.tv_sec; return tv.tv_sec - orig + ( tv.tv_usec / 1000000.0f ); } std::string SharpConstruct::GetVersion() { return VERSION; }