mesh_conv::MC_string_converter Class Reference

A helper class to manipulate string (token, convert, ...). More...

#include <MC_string_helper.hpp>

List of all members.

Static Public Member Functions

template<typename T >
static T value_of (const std::string &in, bool *is_ok=0)
 return the value of the given string
template<typename T >
static std::vector< T > value_of (const std::vector< std::string > &in, bool *is_ok=0)
 return the value of the given vector of string
template<typename T >
static std::string to_string (const T &t)
 get the string corresponding to the given value
static std::string zero_padding (const std::string &input, const int &zero_number=4)
 fill the appropriate number of zero to have the same size
static std::string to_lower (const std::string &input)
 return the lower case of a string
static std::string to_upper (const std::string &input)
 return the upper case of a string
static std::vector< std::string > delete_empty (const std::vector< std::string > &in)
 delete the empty space of a vector of string
static std::pair< std::pair
< int, int >, std::pair
< std::string, std::string > > 
extract_number_part (const std::string &filename)
 extract the last number part of a string and give the number of zeros
static std::vector< std::string > load_filename_sequence (const std::string filename, const unsigned int &iteration=1)
 load file sequence

Detailed Description

A helper class to manipulate string (token, convert, ...).

A class to convert a string into value or value into string

Definition at line 39 of file MC_string_helper.hpp.


Member Function Documentation

std::vector< std::string > mesh_conv::MC_string_converter::delete_empty ( const std::vector< std::string > &  in  )  [static]

delete the empty space of a vector of string

Definition at line 69 of file MC_string_helper.cpp.

Referenced by mesh_conv::MC_io_obj::read_obj(), mesh_conv::MC_io_obj::read_obj_texture(), mesh_conv::MC_io_off::read_off(), mesh_conv::MC_curve::read_vect(), and mesh_conv::MC_matrix::transformation().

00070   {
00071       std::vector <std::string> res;
00072 
00073       int N=in.size();
00074       for(int k=0;k<N;++k)
00075           if(in[k]!=" " && in[k]!="")
00076               res.push_back(in[k]);
00077       return res;
00078   }

Here is the caller graph for this function:

std::pair< std::pair< int, int >, std::pair< std::string, std::string > > mesh_conv::MC_string_converter::extract_number_part ( const std::string &  filename  )  [static]

extract the last number part of a string and give the number of zeros

Parameters:
int,: number found (-1 if failed)
int,: number of zeros (-1 if failed)
string,: first part of the word
string,: last part of the word

ex. my_file_001.dat -> number=1, zeros=2, part_1="my_file_" part_2=".dat"

Definition at line 106 of file MC_string_helper.cpp.

Referenced by load_filename_sequence().

00107   {
00108     int N=filename.length();
00109 
00110     bool is_number=false;
00111     int last_position_number=-1;
00112     int first_position_number=-1;
00113     for(int k=N-1;k>=0;--k)
00114     {
00115         if(filename[k]>='0' && filename[k]<='9')
00116             is_number=true;
00117         else
00118             is_number=false;
00119         if(last_position_number==-1 && is_number==true)
00120             last_position_number=k;
00121         if(first_position_number==-1 && is_number==false && last_position_number!=-1)
00122             first_position_number=k;
00123     }
00124 
00125 
00126     std::string part_1=filename.substr(0,first_position_number+1);
00127     std::string part_2=filename.substr(last_position_number+1,filename.length());
00128 
00129 
00130     std::string number=filename.substr(first_position_number+1,last_position_number-first_position_number);
00131 
00132     int N_zero=-1;
00133     for(unsigned int k=0;k<number.length();++k)
00134     {
00135         if(number[k]!='0' && N_zero==-1)
00136             N_zero=k;
00137     }
00138     if(N_zero==-1)
00139         N_zero=number.length()-1;
00140 
00141     bool is_ok=true;
00142     int current_number=value_of<int>(number,&is_ok);
00143 
00144     if(is_ok==false)
00145         return std::make_pair(std::make_pair(-1,-1),std::make_pair(filename,std::string()));
00146 
00147     return std::make_pair(std::make_pair(current_number,N_zero),std::make_pair(part_1,part_2));
00148 
00149   }

Here is the caller graph for this function:

std::vector< std::string > mesh_conv::MC_string_converter::load_filename_sequence ( const std::string  filename,
const unsigned int &  iteration = 1 
) [static]

load file sequence

Try to load every filename following the numbers on disk

Definition at line 151 of file MC_string_helper.cpp.

References extract_number_part(), to_string(), and zero_padding().

00152   {
00153       //extract informations from the filename
00154       std::pair<std::pair<int,int>,std::pair<std::string,std::string> > info=MC_string_converter::extract_number_part(filename);
00155 
00156 
00157       std::vector<std::string> v_file;
00158 
00159       //std::cout<<info.first.first<<","<<info.first.second<<std::endl;
00160       if(info.first.second==-1)
00161       {
00162           v_file.push_back(filename);
00163           return v_file;
00164       }
00165 
00166       int zero_pad=info.first.second+(MC_string_converter::to_string(info.first.first).length());
00167 
00168       bool is_continue=true;
00169       std::ifstream file;
00170       int k=info.first.first;
00171       do
00172       {
00173           std::string number=MC_string_converter::zero_padding(MC_string_converter::to_string(k),zero_pad);
00174           std::string current_file=info.second.first+number+info.second.second;
00175 
00176 
00177 
00178           file.open(current_file.c_str());
00179           if(file.good()==false)
00180               is_continue=false;
00181           else
00182               v_file.push_back(current_file);
00183 
00184           //std::cout<<current_file<<" "<<is_continue<<std::endl;
00185           file.close();
00186           k+=iteration;
00187       }while(is_continue==true);
00188 
00189       return v_file;
00190 
00191   }

Here is the call graph for this function:

std::string mesh_conv::MC_string_converter::to_lower ( const std::string &  input  )  [static]

return the lower case of a string

Definition at line 54 of file MC_string_helper.cpp.

00055   {
00056       std::string res("");
00057       for(unsigned int k=0;k<input.length();++k)
00058           res+=std::tolower(input[k],std::cout.getloc ());
00059       return res;
00060   }

template<typename T >
static std::string mesh_conv::MC_string_converter::to_string ( const T &  t  )  [inline, static]

get the string corresponding to the given value

example: std::string val=mesh_convMC_string_converter::to_string(4.0*78.5);

Definition at line 87 of file MC_string_helper.hpp.

Referenced by mesh_conv::MC_grid_3d< VALUE >::assert_is_in_range(), draw_fps(), and load_filename_sequence().

00088     {
00089       std::ostringstream oss;
00090       oss<<t;
00091       return std::string(oss.str());
00092     }

Here is the caller graph for this function:

std::string mesh_conv::MC_string_converter::to_upper ( const std::string &  input  )  [static]

return the upper case of a string

Definition at line 61 of file MC_string_helper.cpp.

00062   {
00063       std::string res("");
00064       for(unsigned int k=0;k<input.length();++k)
00065           res+=std::toupper(input[k],std::cout.getloc ());
00066       return res;
00067   }

template<typename T >
static std::vector<T> mesh_conv::MC_string_converter::value_of ( const std::vector< std::string > &  in,
bool *  is_ok = 0 
) [inline, static]

return the value of the given vector of string

Definition at line 64 of file MC_string_helper.hpp.

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       }

template<typename T >
static T mesh_conv::MC_string_converter::value_of ( const std::string &  in,
bool *  is_ok = 0 
) [inline, static]

return the value of the given string

Returns:
the value asked and a boolean is set to 0(!=0) if the conversion succed (failed)

example: double val=mesh_convMC_string_converter::value_of<double> ("4.54");

Definition at line 52 of file MC_string_helper.hpp.

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       }

std::string mesh_conv::MC_string_converter::zero_padding ( const std::string &  input,
const int &  zero_number = 4 
) [static]

fill the appropriate number of zero to have the same size

exemple zero_padding("62",5)="00062"

exemple zero_padding("c;7",4)="0x;7"

Definition at line 46 of file MC_string_helper.cpp.

Referenced by load_filename_sequence().

00047   {
00048       std::string current_string=input;
00049       int current_length=input.size();
00050       for(int k=0;k<zero_number-current_length;k++)
00051           current_string=std::string("0")+current_string;
00052       return current_string;
00053   }

Here is the caller graph for this function:


The documentation for this class was generated from the following files:

Generated on Sun Apr 18 20:24:48 2010 by  doxygen 1.6.1