]> Creatis software - clitk.git/blobdiff - common/clitkCommon.txx
Merge branch 'master' of /home/dsarrut/clitk3.server
[clitk.git] / common / clitkCommon.txx
index d7c91405dda8f45ff76138c341784f4d05b16b4c..dc7f1653c45d5d9e3538043297ca89408c64b80e 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
 #ifndef CLITKCOMMON_TXX
 #define CLITKCOMMON_TXX
-/**
-   -------------------------------------------------
-   * @file   clitkCommon.txx
-   * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
-   * @date   18 May 2006
-   *
-   -------------------------------------------------*/
 
 //-------------------------------------------------------
 // Utility functions for text file parsing (author: joel schaerer)
 
+//--------------------------------------------------------------------
 template<class ElementType>
 ElementType parse_value(std::string str)
 {
@@ -37,7 +31,10 @@ ElementType parse_value(std::string str)
   assert(!parser.fail());
   return value;
 }
+//--------------------------------------------------------------------
 
+
+//--------------------------------------------------------------------
 template<class ElementType>
 std::vector<ElementType> parse_string(std::string str,char delim)
 {
@@ -49,7 +46,10 @@ std::vector<ElementType> parse_string(std::string str,char delim)
   }
   return result;
 }
+//--------------------------------------------------------------------
+
 
+//--------------------------------------------------------------------
 template<class ElementType>
 std::vector<std::vector<ElementType> > parse_file(const char* filename,char delim)
 {
@@ -62,6 +62,8 @@ std::vector<std::vector<ElementType> > parse_file(const char* filename,char deli
   }
   return result;
 }
+//--------------------------------------------------------------------
+
 
 //--------------------------------------------------------------------
 // Convert float, double ... to string
@@ -74,6 +76,19 @@ std::string toString(const T & t)
 }
 //--------------------------------------------------------------------
 
+
+//--------------------------------------------------------------------
+// http://www.codeguru.com/forum/showthread.php?t=231054
+template <class T>
+bool fromString(T& t, const std::string& s, 
+                std::ios_base& (*f)(std::ios_base&))
+{
+  std::istringstream iss(s);
+  return !(iss >> f >> t).fail();
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 // Convert float*, double* ... to string
 template<class T>