freConvert.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freConvert.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #include <sstream>
00024 
00025 #include "freConvert.h"
00026 #include "freConstantValues.h"
00027 
00028 namespace FREE
00029 {
00030 
00031 namespace Convert
00032 {
00033 
00034 std::string ToStr(const double& dValue, const int iPrecision)
00035 {
00036   std::string sResult;
00037   std::ostringstream stream;
00038 
00039   stream.precision(iPrecision);
00040   stream << std::showpoint << dValue;
00041 
00042   sResult = stream.str();
00043   return sResult;
00044 };
00045 
00046 std::string ToStr(const float& fValue, const int iPrecision)
00047 {
00048   std::string sResult;
00049   std::ostringstream stream;
00050 
00051   stream.precision(iPrecision);
00052   stream << std::showpoint << fValue;
00053 
00054   sResult = stream.str();
00055   return sResult;
00056 };
00057 
00058 std::string ToStr(const bool& bValue)
00059 { 
00060   if (bValue) return "1";
00061   else return "0";
00062 };
00063 
00064 std::string ToStr(const int& iValue)
00065 {
00066   std::string sResult;
00067   std::ostringstream stream;
00068 
00069   stream << iValue;
00070 
00071   sResult = stream.str();
00072   return sResult;
00073 };
00074 
00075 std::string ToStr(const unsigned int& iValue)
00076 {
00077   std::string sResult;
00078   std::ostringstream stream;
00079 
00080   stream << iValue;
00081 
00082   sResult = stream.str();
00083   return sResult;
00084 };
00085 
00086 std::string ToStr(const long& lValue)
00087 {
00088   std::string sResult;
00089   std::ostringstream stream;
00090 
00091   stream << lValue;
00092 
00093   sResult = stream.str();
00094   return sResult;
00095 };
00096 
00097 std::string ToStr(const unsigned long& lValue)
00098 {
00099   std::string sResult;
00100   std::ostringstream stream;
00101 
00102   stream << lValue;
00103 
00104   sResult = stream.str();
00105   return sResult;
00106 };
00107 
00108 std::string ToStr(const DataAccessType& da)
00109 {
00110   switch (da)
00111   {
00112         case DASet: return "set";
00113         case DAGet: return "get";
00114         default: return "any";
00115   };
00116 };
00117 
00118 double ToDouble(const std::string& sValue)
00119 {
00120   char* pStopstring;
00121   double x;
00122   x = strtod( sValue.c_str(), &pStopstring );
00123   return x;
00124 };
00125 
00126 bool IsADouble(const std::string& sValue)
00127 {
00128   char* pStopstring;
00129   double x;
00130   x = strtod( sValue.c_str(), &pStopstring );
00131   std::string sTemp = pStopstring;
00132   return (sTemp == "")&(sValue != "");
00133 };
00134 
00135 float ToFloat(const std::string& sValue)
00136 {
00137   float result;
00138   std::stringstream strstrm(sValue);
00139   strstrm >> result;
00140         return result;
00141 };
00142 
00143 int ToInt(const std::string& sValue)
00144 {
00145   return atoi(sValue.c_str());
00146 };
00147 
00148 bool IsAInt(const std::string& sValue)
00149 {
00150   int iTest = ToInt(sValue);
00151   std::string sTest = ToStr(iTest);
00152   return sValue == sTest;
00153 };
00154 
00155 unsigned int ToUInt(const std::string& sValue)
00156 {
00157   unsigned int iResult;
00158 
00159   std::istringstream stream(sValue);
00160   stream >> iResult;
00161 
00162   return iResult;
00163 };
00164 
00165 long ToLong(const std::string& sValue)
00166 {
00167   long result;
00168 
00169   std::istringstream stream(sValue);
00170   stream >> result;
00171 
00172   return result;
00173 };
00174 
00175 bool IsALong(const std::string& sValue)
00176 {
00177   long lTest = ToLong(sValue);
00178   std::string sTest = ToStr(lTest);
00179   return sValue == sTest;
00180 };
00181 
00182 unsigned long ToULong(const std::string& sValue)
00183 {
00184   unsigned long result;
00185 
00186   std::istringstream stream(sValue);
00187   stream >> result;
00188 
00189   return result;
00190 };
00191 
00192 bool ToBool(const std::string& sValue)
00193 {
00194         if (sValue=="0") return false;
00195         if (sValue=="false") return false;
00196         if (sValue=="FALSE") return false;
00197         if (sValue=="False") return false;
00198         return true;
00199 };
00200 
00201 DataAccessType ToDataAccessType(const std::string& sValue)
00202 {
00203         if (sValue==ToStr(DASet)) return DASet;
00204         if (sValue==ToStr(DAGet)) return DAGet;
00205         
00206         return DAAny;
00207 };
00208 
00209 }
00210 
00211 } //end of namespace free

Generated at Sat Oct 13 15:39:59 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000