$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_StringMacros_h_ 00002 #define _ots_StringMacros_h_ 00003 00004 #include "otsdaq-core/Macros/CoutMacros.h" 00005 00006 #include <map> 00007 #include <set> 00008 #include <typeinfo> // operator typeid 00009 #include <vector> 00010 #include <memory> //shared_ptr 00011 00012 namespace ots 00013 { 00014 struct StringMacros 00015 { 00016 private: // private constructor because all static members, should never instantiate 00017 // this class 00018 StringMacros(void); 00019 ~StringMacros(void); 00020 00021 public: 00022 // Here is the list of static helper functions: 00023 // 00024 // wildCardMatch 00025 // inWildCardSet 00026 // getWildCardMatchFromMap 00027 // 00028 // decodeURIComponent 00029 // convertEnvironmentVariables 00030 // isNumber 00031 // getNumber 00032 // validateValueForDefaultStringDataType 00033 // 00034 // getSetFromString 00035 // getVectorFromString 00036 // getMapFromString 00037 // 00038 // setToString 00039 // vectorToString 00040 // mapToString 00041 // 00042 // demangleTypeName 00043 00044 static bool wildCardMatch(const std::string& needle, 00045 const std::string& haystack, 00046 unsigned int* priorityIndex = 0); 00047 static bool inWildCardSet(const std::string& needle, 00048 const std::set<std::string>& haystack); 00049 00050 //======================================================================================================================== 00051 // getWildCardMatchFromMap ~ 00052 // returns value if needle is in haystack otherwise throws exception 00053 // (considering wildcards AND match priority as defined by 00054 // StringMacros::wildCardMatch) 00055 template<class T> 00056 static T& getWildCardMatchFromMap( 00057 const std::string& needle, 00058 std::map<std::string, T>& haystack, 00059 std::string* foundKey = 0); // defined in included .icc source 00060 00061 static std::string decodeURIComponent(const std::string& data); 00062 static std::string convertEnvironmentVariables(const std::string& data); 00063 static bool isNumber(const std::string& stringToCheck); 00064 00065 template<class T> 00066 static bool getNumber(const std::string& s, 00067 T& retValue); // defined in included .icc source 00068 static std::string getTimestampString(const std::string& linuxTimeInSeconds); 00069 static std::string getTimestampString(const time_t& linuxTimeInSeconds = time(0)); 00070 00071 // special validation ignoring any table info - just assuming type string 00072 template<class T> 00073 static T validateValueForDefaultStringDataType( 00074 const std::string& value, 00075 bool doConvertEnvironmentVariables = true); // defined in included .icc source 00076 static std::string validateValueForDefaultStringDataType( 00077 const std::string& value, bool doConvertEnvironmentVariables = true); 00078 00079 static void getSetFromString(const std::string& inputString, 00080 std::set<std::string>& setToReturn, 00081 const std::set<char>& delimiter = {',', '|', '&'}, 00082 const std::set<char>& whitespace = { 00083 ' ', '\t', '\n', '\r'}); 00084 00085 template<class T /*value type*/, 00086 class S = std::string /*name string or const string*/> 00087 static void getMapFromString( 00088 const std::string& inputString, 00089 std::map<S, T>& mapToReturn, 00090 const std::set<char>& pairPairDelimiter = {',', '|', '&'}, 00091 const std::set<char>& nameValueDelimiter = {'=', ':'}, 00092 const std::set<char>& whitespace = {' ', '\t', '\n', '\r'}); 00093 static void getMapFromString( 00094 const std::string& inputString, 00095 std::map<std::string, std::string>& mapToReturn, 00096 const std::set<char>& pairPairDelimiter = {',', '|', '&'}, 00097 const std::set<char>& nameValueDelimiter = {'=', ':'}, 00098 const std::set<char>& whitespace = {' ', '\t', '\n', '\r'}); 00099 static void getVectorFromString( 00100 const std::string& inputString, 00101 std::vector<std::string>& listToReturn, 00102 const std::set<char>& delimiter = {',', '|', '&'}, 00103 const std::set<char>& whitespace = {' ', '\t', '\n', '\r'}, 00104 std::vector<char>* listOfDelimiters = 0); 00105 00106 //*ToString declarations (template definitions are in included .icc source) 00107 template<class T> 00108 static std::string mapToString(const std::map<std::string, T>& mapToReturn, 00109 const std::string& primaryDelimeter = ", ", 00110 const std::string& secondaryDelimeter = ": "); 00111 template<class T> 00112 static std::string mapToString( 00113 const std::map<std::pair<std::string, std::string>, T>& mapToReturn, 00114 const std::string& primaryDelimeter = ", ", 00115 const std::string& secondaryDelimeter = ": "); 00116 template<class T> 00117 static std::string mapToString( 00118 const std::map<std::pair<std::string, std::pair<std::string, std::string>>, T>& 00119 mapToReturn, 00120 const std::string& primaryDelimeter = ", ", 00121 const std::string& secondaryDelimeter = ": "); 00122 template<class T> 00123 static std::string mapToString( 00124 const std::map<std::string, std::pair<std::string, T>>& mapToReturn, 00125 const std::string& primaryDelimeter = ", ", 00126 const std::string& secondaryDelimeter = ": "); 00127 template<class T> 00128 static std::string mapToString( 00129 const std::map<std::string, std::map<std::string, T>>& mapToReturn, 00130 const std::string& primaryDelimeter = ", ", 00131 const std::string& secondaryDelimeter = ": "); 00132 template<class T> 00133 static std::string mapToString(const std::map<std::string, std::set<T>>& mapToReturn, 00134 const std::string& primaryDelimeter = ", ", 00135 const std::string& secondaryDelimeter = ": "); 00136 template<class T> 00137 static std::string mapToString( 00138 const std::map<std::string, std::vector<T>>& mapToReturn, 00139 const std::string& primaryDelimeter = ", ", 00140 const std::string& secondaryDelimeter = ": "); 00141 static std::string mapToString(const std::map<std::string, uint8_t>& mapToReturn, 00142 const std::string& primaryDelimeter = ", ", 00143 const std::string& secondaryDelimeter = ": "); 00144 00145 template<class T> 00146 static std::string setToString(const std::set<T>& setToReturn, 00147 const std::string& delimeter = ", "); 00148 static std::string setToString(const std::set<uint8_t>& setToReturn, 00149 const std::string& delimeter = ", "); 00150 00151 template<class T> 00152 static std::string vectorToString(const std::vector<T>& setToReturn, 00153 const std::string& delimeter = ", "); 00154 static std::string vectorToString(const std::vector<uint8_t>& setToReturn, 00155 const std::string& delimeter = ", "); 00156 template<class S, class T> 00157 static std::string vectorToString(const std::vector<std::pair<S, T>>& setToReturn, 00158 const std::string& primaryDelimeter = "; ", 00159 const std::string& secondaryDelimeter = ":"); 00160 00161 static std::string demangleTypeName(const char* name); 00162 static std::string stackTrace(); 00163 static std::string exec(const char* cmd); 00164 00165 }; // end StringMarcos static class 00166 00167 #include "otsdaq-core/Macros/StringMacros.icc" //define template functions 00168 00169 } // namespace ots 00170 #endif