Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_stype 5 #define tools_stype 6 7 //used in rroot leaf template. 8 9 #include "typedefs" 10 11 #include <string> 12 13 namespace tools { 14 15 inline const std::string& stype(unsigned char) { 16 static const std::string s_v("unsigned char"); 17 return s_v; 18 } 19 20 inline const std::string& stype(char) { 21 static const std::string s_v("char"); 22 return s_v; 23 } 24 25 inline const std::string& stype(unsigned short) { 26 static const std::string s_v("unsigned short"); 27 return s_v; 28 } 29 30 inline const std::string& stype(short) { 31 static const std::string s_v("short"); 32 return s_v; 33 } 34 35 inline const std::string& stype(int) { 36 static const std::string s_v("int"); 37 return s_v; 38 } 39 40 inline const std::string& stype(unsigned int) { 41 static const std::string s_v("unsigned int"); 42 return s_v; 43 } 44 45 inline const std::string& stype(float) { 46 static const std::string s_v("float"); 47 return s_v; 48 } 49 50 inline const std::string& stype(double) { 51 static const std::string s_v("double"); 52 return s_v; 53 } 54 55 inline const std::string& stype(bool) { 56 static const std::string s_v("bool"); 57 return s_v; 58 } 59 60 // for tools::mcol<T> : 61 inline const std::string& stype(int64) { 62 static const std::string s_v("tools::int64"); 63 return s_v; 64 } 65 inline const std::string& stype(uint64) { 66 static const std::string s_v("tools::uint64"); 67 return s_v; 68 } 69 inline const std::string& stype(const std::string&) { 70 static const std::string s_v("std::string"); 71 return s_v; 72 } 73 74 // for introspection templated fields or class methods : 75 template <class T> 76 inline const std::string& stype(const T&) {return T::s_class();} 77 78 inline bool stemplate(const std::string& a_s,std::string& a_inc) { 79 // If a_s is of the form "xxx<yyy>zzz<ttt>uuuu", at end a_inc contains "yyy". 80 // It returns true if something had been found, else false. 81 a_inc = a_s; 82 std::string::size_type pos = a_inc.find('<'); 83 if(pos==std::string::npos) {a_inc.clear();return false;} 84 a_inc = a_inc.substr((pos+1),a_inc.size()-(pos+1)); 85 std::string::size_type _pos = a_inc.find('>'); 86 if(_pos==std::string::npos) {a_inc.clear();return false;} 87 a_inc = a_inc.substr(0,_pos); 88 return true; 89 } 90 91 } 92 93 #include <vector> 94 95 namespace tools { 96 97 // for sg::entries mf_vec< std::vector<std::string> ,std::string> opts; 98 inline const std::string& stype(const std::vector<std::string>&) { 99 static const std::string s_v("std::vector<std::string>"); 100 return s_v; 101 } 102 103 } 104 105 #endif