S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_conversion.h

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
00022  */
00023 
00033 #ifndef S3_CONVERSION_H
00034 #define S3_CONVERSION_H
00035 
00036 #include <s3fc/s3_exception.h>
00037 #include <string>
00038 #include <vector>
00039 #include <sstream>
00040 
00044 class s3_conversion
00045 {
00046 public:
00047 
00052    template<typename T> 
00053    static std::string to_string(const T &t)
00054    {
00055       std::ostringstream os;
00056       os << t;
00057       return os.str();
00058    }
00059    
00064    template<class T>
00065    static T from_string(const std::string& s)
00066    {
00067       std::istringstream is( s );
00068       T t;
00069       is >> t;
00070       return t;
00071    } 
00072    
00079    static std::vector<std::string> string_to_vec_string(const std::string& str);
00085    static std::vector<int> string_to_vec_int(const std::string& str);
00091    static std::vector<float> string_to_vec_float(const std::string& str);
00102    static std::vector<std::string> split_string(const std::string& str,
00103                   const char* delim = 0);
00107    class exception : public s3_generic_exception
00108    {
00109      public:
00115       exception(const std::string& where,
00116       const std::string& what);
00117    };
00118 };
00119 
00120 template<>
00121 std::string s3_conversion::from_string<std::string>(const std::string& s);
00122 
00123 
00124 #endif //S3_CONVERSION_H

Send comments to: s3fc@stonethree.com SourceForge Logo