MC_string_helper.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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