14 #include <boost/regex.hpp>
15 #include <boost/algorithm/string.hpp>
19 using namespace boost;
28 const string TYPE =
"type"
37 , RETRPER =
"retrialperiod"
38 , MAXRETR =
"maxretrials"
39 , USEFRONT =
"usefrontier"
45 const string SEP =
";";
51 const string e_pair_open(R
"(\s*\()")
52 , e_pair_separate(
",")
53 , e_pair_close(R
"(\)\s*)")
54 , e_uint_core_dec(
"\\d+")
55 , e_uint_core_oct(
"0[0-7]+")
56 , e_uint_core_hex(
"0x[\\da-f]+")
58 , e_uint_neg_zero(
"-0+|-0x0+")
59 , e_list_open(R
"(\s*\[)")
60 , e_list_separate(
",")
61 , e_list_close(R
"(\]\s*)")
63 , e_param_open(R
"((?:^|)"
74 , e_param_val(R
"(\s*(.*?)\s*)")
86 const string e_uint(R
"(\s*(?:\+?(?:)" + e_uint_core_hex + "|"
87 + e_uint_core_oct +
"|"
88 + e_uint_core_dec +
")|"
89 + e_uint_neg_zero + R
"()\s*)");
92 const string e_pair(e_pair_open +
"(" + e_uint +
")"
93 + e_pair_separate +
"(" + e_uint +
")"
97 const string e_list_empty(e_list_open +
"\\s*" + e_list_close);
99 const string e_list(e_list_open + e_pair
100 +
"(?:" + e_list_separate + e_pair +
")*"
101 + e_list_close +
"|" + e_list_empty);
104 const regex re_uint(e_uint),
109 unsigned int getUInt(
const string&
str,
const string&
aname)
111 int ret = stoi(
str,
nullptr, 0);
113 throw invalid_argument(
"The string specifying the " +
aname +
" does not "
114 "represent a valid non-negative integer: " +
str);
124 if(regex_match(
str, re_list))
126 for(sregex_iterator
it = make_regex_iterator(
str, re_pair);
127 it != sregex_iterator(); ++
it)
129 ret.push_back(make_pair(stoi((*
it)[1],
nullptr, 0),
130 stoi((*
it)[2],
nullptr, 0)));
132 throw invalid_argument(
"The string specifying the HLT PS Keys is badly "
138 string extractValue(
const string&
name,
const string&
str)
141 regex re_param(e_param_open
148 for(sregex_iterator
it = make_regex_iterator(
str, re_param);
149 it != sregex_iterator(); ++
it)
156 template <
typename T>
157 void outputParam(ostringstream& oss,
const string&
name,
const T&
value,
171 const string& hltPsKeyStr)
181 diggestStr(connectionStr);
189 outputParam(oss,
SERVER, m_server);
190 outputParam(oss, SMKEY, m_smkey);
191 outputParam(oss, LVL1KEY, m_lvl1key);
192 outputParam(oss, SCHEMA, m_schema);
193 outputParam(oss, USER, m_user);
194 outputParam(oss, PWD, m_password);
195 outputParam(oss, RETRPER, m_retrialPeriod);
196 outputParam(oss, MAXRETR, m_maxRetrials);
197 outputParam(oss, USEFRONT, m_useFrontier);
200 outputParam(oss, HLTKEY, m_hltkey);
202 outputParam(oss, HLTKEYS, hltKeysToString());
217 if(!(
val = extractValue(SMKEY,
str)).empty())
218 setSmKeyFromStr(
val);
219 if(!(
val = extractValue(LVL1KEY,
str)).empty())
220 setLvl1KeyFromStr(
val);
221 if(!(
val = extractValue(SCHEMA,
str)).empty())
223 if(!(
val = extractValue(USER,
str)).empty())
225 if(!(
val = extractValue(PWD,
str)).empty())
227 if(!(
val = extractValue(RETRPER,
str)).empty())
228 setRetrialPeriodFromStr(
val);
229 if(!(
val = extractValue(MAXRETR,
str)).empty())
230 setMaxRetrialsFromStr(
val);
231 if(!(
val = extractValue(USEFRONT,
str)).empty())
232 setUseFrontierFromStr(
val);
235 if(!(
val = extractValue(HLTKEY,
str)).empty())
236 setHltKeysFromStr(
val);
237 if(!m_hltkey && !(
val = extractValue(HLTKEYS,
str)).empty())
238 setHltKeysFromStr(
val);
244 string low = algorithm::to_lower_copy(typeStr);
247 else if(low ==
"mysql")
249 else if(low ==
"sqlite")
259 if(regex_match(hltKeyStr, re_uint))
260 m_hltkey = stoi(hltKeyStr,
nullptr, 0);
262 m_hltkeys = parseHltPsKeys(hltKeyStr);
268 m_smkey = getUInt(smKeyStr, SMKEY);
275 m_lvl1key = getUInt(lvl1KeyStr, LVL1KEY);
282 m_retrialPeriod = getUInt(retrialPeriodStr, RETRPER);
289 m_maxRetrials = getUInt(maxRetrialsStr, MAXRETR);
296 m_useFrontier =
static_cast<bool>(getUInt(useFrontier, USEFRONT));
305 for(PSKeys::const_iterator
it = m_hltkeys.begin();
306 it != m_hltkeys.end(); ++
it)
308 if(
it != m_hltkeys.begin())
310 oss <<
'(' <<
it->first <<
',' <<
it->second <<
')';