GEMC  1.8
Geant4 Monte-Carlo Framework
string_utilities.h
Go to the documentation of this file.
1 
6 #ifndef string_utilities_H
7 #define string_utilities_H
8 
9 // %%%%%%%%%%%
10 // Qt4 headers
11 // %%%%%%%%%%%
12 #include <QString>
13 
14 
15 // %%%%%%%%%%%
16 // C++ headers
17 // %%%%%%%%%%%
18 #include <vector>
19 #include <iostream>
20 #include <string>
21 #include <sstream>
22 using namespace std;
23 
24 
25 inline string stringify(double x)
26 {
27  ostringstream o;
28  o << x;
29  return o.str();
30 }
31 
32 inline string stringify(int x)
33 {
34  ostringstream o;
35  o << x;
36  return o.str();
37 }
38 
39 
40 // from QString to string
41 // OS dependance
42 inline string gemc_tostring(QString input)
43 {
44 
45  string output;
46  // In Windows we need to initialize the string from toAscii
47  // In Posix we need the toStdString
48 
49  #ifdef _MSC_VER
50  output = input.toAscii();
51  #else
52  output = input.toStdString();
53  #endif
54 
55  return output;
56 }
57 
58 
59 // Replaces first argument's characters specified in the second argument by spaces
60 inline string replaceCharsWithSpaces(string input, char* x)
61 {
62  string output = "";
63 
64  for(unsigned int k=0; k<input.size(); k++)
65  {
66  int replace = 1;
67  for(unsigned int j=0; j<sizeof(x); j++)
68  {
69 
70  if(input[k] == x[j])
71  {
72  output.append(" ");
73  replace = 0;
74  }
75  }
76  if(replace) output += input[k];
77  }
78  return output;
79 }
80 
81 vector< vector<string> > dimensionstype(string);
82 double get_number(string);
83 string TrimSpaces(string in);
84 vector<string> get_strings(string);
85 void print_vstring(vector<string>);
86 
87 #endif
88 
89 
90 
91 
92 
double get_number(string)
Returns dimension from string, i.e. 100*cm.
STL namespace.
string gemc_tostring(QString input)
string replaceCharsWithSpaces(string input, char *x)
string stringify(double x)
void print_vstring(vector< string >)
prints each element of a string vector
vector< string > get_strings(string)
returns a vector of strings from a stringstream
vector< vector< string > > dimensionstype(string)
Returns dimensions nomenclature for different solid type.
Definition: detector.cc:803
string TrimSpaces(string in)
Removes leading and trailing spaces.