00001 //====================================================================== 00002 // File: util.h 00003 // Author: Matthias Toussaint 00004 // Created: Sun Dec 3 16:27:25 CET 2006 00005 // Project: QtDMM 00006 // Description: Utility class 00007 //---------------------------------------------------------------------- 00008 // This file may be used under the terms of the GNU General Public 00009 // License version 2.0 as published by the Free Software Foundation 00010 // and appearing in the file LICENSE.GPL included in the packaging of 00011 // this file. 00012 // 00013 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING 00014 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00015 // PURPOSE. 00016 //---------------------------------------------------------------------- 00017 // Copyright 2006 Matthias Toussaint 00018 //====================================================================== 00019 00020 #ifndef UTIL_HH 00021 #define UTIL_HH 00022 00023 #include <string> 00024 #include <vector> 00025 00026 typedef std::vector<std::string> TokenList; 00027 00030 class Util 00031 { 00032 public: 00033 00034 static std::string strip_whitespace( const std::string & str ); 00035 static TokenList tokenize( const std::string & str, 00036 const std::string & separators ); 00037 00043 template <typename T> 00044 static bool fromString( T * value, const std::string & str ) 00045 { 00046 std::stringstream ss( str ); 00047 return ss >> *value; 00048 } 00049 00050 }; 00051 00052 #endif // UTIL_HH