MC_string_helper.hpp

Go to the documentation of this file.
00001 /*
00002 **    Mesh Converter
00003 **    Copyright (C) 2009  Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 #ifndef MC_STRING_HELPER_H_
00021 #define MC_STRING_HELPER_H_
00022 
00023 #include <stdlib.h>
00024 #include <vector>
00025 #include <iostream>
00026 #include <sstream>
00027 #include <string>
00028 
00029 
00030 
00031 namespace mesh_conv
00032 {
00033 
00034 
00035 
00037 
00039   class MC_string_converter
00040   {
00041 
00042 
00043   public:
00044 
00045 
00051       template <typename T>
00052               static T value_of(const std::string& in,bool *is_ok=0)
00053       {
00054           T obj;
00055           std::istringstream is(in);
00056           bool _is_ok=bool(is>>obj);
00057           if(is_ok!=0)
00058               *is_ok=_is_ok;
00059           return obj;
00060       }
00061 
00063       template <typename T>
00064               static std::vector <T> value_of(const std::vector <std::string>& in,bool *is_ok=0)
00065       {
00066 
00067           if(is_ok!=0)
00068               *is_ok=true;
00069 
00070           int N=in.size();
00071           std::vector <T> obj(N);
00072           bool temp_is_ok=true;
00073           for(int k=0;k<N;++k)
00074           {
00075               obj[k]=value_of<T> (in[k],&temp_is_ok);
00076               if(is_ok!=0 && temp_is_ok==false)
00077                   *is_ok=false;
00078           }
00079           return obj;
00080       }
00081 
00086     template <typename T>
00087     static std::string to_string(const T& t)
00088     {
00089       std::ostringstream oss;
00090       oss<<t;
00091       return std::string(oss.str());
00092     }
00093 
00100     static std::string zero_padding(const std::string& input,const int& zero_number=4);
00101 
00103     static std::string to_lower(const std::string& input);
00105     static std::string to_upper(const std::string& input);
00106 
00108     static std::vector <std::string> delete_empty(const std::vector <std::string>& in);
00109 
00110   private:
00111   };
00112 
00113 
00115   class MC_string_tokenizer
00116   {
00117 
00118   public:
00126       static std::vector <std::string> tokenize(const std::string& str,const std::string& delimiters=" ");
00127   private:
00128   };
00129 
00131   class MC_file_helper
00132   {
00133       public:
00134 
00140       static MC_file_helper copy(const std::string& input_filename,const std::string& output_filename);
00141 
00142       private:
00143   };
00144 
00145 
00146 }
00147 
00148 #endif

Generated on Fri Sep 25 13:31:35 2009 by  doxygen 1.5.8