40 std::string scaleNumericalStringRepresentation(
const std::string & sValue)
42 std::string sTmpParameter(sValue);
44 std::uint8_t u8PowerOf10 = 0;
46 switch(*(sValue.end() - 1))
49 sTmpParameter.assign(sValue,0,sValue.size() - 1);
54 sTmpParameter.assign(sValue,0,sValue.size() - 1);
59 sTmpParameter.assign(sValue,0,sValue.size() - 1);
67 std::string::size_type notWhiteSpace{sTmpParameter.find_first_not_of(
" \t")};
69 if(notWhiteSpace != std::string::npos)
71 sTmpParameter = sTmpParameter.substr(notWhiteSpace,std::string::npos);
75 std::string::size_type indexPoint = sTmpParameter.find(
".",0);
77 if(indexPoint != std::string::npos)
79 std::string::size_type numberOfDigitsAfterPoint =
80 sTmpParameter.size() - indexPoint - 1;
82 if(numberOfDigitsAfterPoint > u8PowerOf10)
85 sTmpParameter.insert(indexPoint + u8PowerOf10,
".");
90 sTmpParameter.append(u8PowerOf10 - numberOfDigitsAfterPoint,
'0');
94 sTmpParameter.erase(indexPoint,1);
99 sTmpParameter.append(u8PowerOf10,
'0');
105 if(sTmpParameter.front() ==
'+' ||
106 sTmpParameter.front() ==
'-')
108 sSign = sTmpParameter.front();
111 std::string::size_type not0Index{sTmpParameter.find_first_not_of(
"0",sSign.size())};
113 if(not0Index != sSign.size())
115 sTmpParameter = sSign + sTmpParameter.substr(not0Index,std::string::npos);
119 return sTmpParameter;
125 sParameter_{sParameter}{}
133 long long llValue = 0;
135 if(sParameter_.empty())
141 std::string sTmpParameter(scaleNumericalStringRepresentation(sParameter_));
149 llValue = std::strtoll(sTmpParameter.c_str(),&pEnd,0);
151 if(errno == ERANGE ||
155 std::stringstream sstream;
156 sstream<<sParameter_<<
" out of range ["<<i64Min<<
","<<i64Max<<
"]"<<std::ends;
159 else if(pEnd != 0 && *pEnd !=
'\0')
161 std::stringstream sstream;
162 sstream<<sParameter_<<
" invalid character in numeric: '"<<*pEnd<<
"'"<<std::ends;
173 unsigned long long ullValue = 0;
175 if(sParameter_.empty())
181 std::string sTmpParameter(scaleNumericalStringRepresentation(sParameter_));
189 ullValue = strtoull(sTmpParameter.c_str(),&pEnd,0);
191 if(errno == ERANGE ||
195 std::stringstream sstream;
196 sstream<<sParameter_<<
" out of range ["<<u64Min<<
","<<u64Max<<
"]"<<std::ends;
199 else if(pEnd != 0 && *pEnd !=
'\0')
201 std::stringstream sstream;
202 sstream<<sParameter_<<
" invalid character in numeric: '"<<*pEnd<<
"'"<<std::ends;
213 return static_cast<std::int32_t
>(
toINT64(i32Min,i32Max));
219 return static_cast<std::uint32_t
>(
toUINT64(u32Min,u32Max));
225 return static_cast<std::int16_t
>(
toINT64(i16Min,i16Max));
231 return static_cast<std::uint16_t
>(
toUINT64(u16Min,u16Max));
237 return static_cast<std::int8_t
>(
toINT64(i8Min,i8Max));
243 return static_cast<std::uint8_t
>(
toUINT64(u8Min,u8Max));
249 if(!strcasecmp(sParameter_.c_str(),
"on") ||
250 !strcasecmp(sParameter_.c_str(),
"yes") ||
251 !strcasecmp(sParameter_.c_str(),
"true") ||
252 !strcasecmp(sParameter_.c_str(),
"1"))
256 else if(!strcasecmp(sParameter_.c_str(),
"off") ||
257 !strcasecmp(sParameter_.c_str(),
"no") ||
258 !strcasecmp(sParameter_.c_str(),
"false") ||
259 !strcasecmp(sParameter_.c_str(),
"0"))
265 std::stringstream sstream;
266 sstream<<
"'"<<sParameter_<<
"' invalid boolean conversion"<<std::ends;
278 addr.
set(sParameter_);
282 std::stringstream sstream;
283 sstream<<
"'"<<sParameter_<<
"' Invalid IP Address"<<std::ends;
295 if(sParameter_.empty())
301 std::string sTmpParameter(scaleNumericalStringRepresentation(sParameter_));
309 dValue = std::strtod(sTmpParameter.c_str(),&pEnd);
311 if(errno == ERANGE ||
315 std::stringstream sstream;
316 sstream<<sParameter_<<
" out of range ["<<dMin<<
","<<dMax<<
"]"<<std::ends;
319 else if(pEnd != 0 && *pEnd !=
'\0')
321 std::stringstream sstream;
322 sstream<<sParameter_<<
" invalid character in numeric: '"<<*pEnd<<
"'"<<std::ends;
333 return static_cast<float>(
toDouble(fMin,fMax));
INETAddr toINETAddr() const
std::int8_t toINT8(std::int8_t i8Min=std::numeric_limits< std::int8_t >::min(), std::int8_t i8Max=std::numeric_limits< std::int8_t >::max()) const
std::uint8_t toUINT8(std::uint8_t u8Min=std::numeric_limits< std::uint8_t >::min(), std::uint8_t u8Max=std::numeric_limits< std::uint8_t >::max()) const
Parameter conversion exception class.
std::uint16_t toUINT16(std::uint16_t u16Min=std::numeric_limits< std::uint16_t >::min(), std::uint16_t u16Max=std::numeric_limits< std::uint16_t >::max()) const
float toFloat(float fMin=std::numeric_limits< float >::lowest(), float fMax=std::numeric_limits< float >::max()) const
std::uint64_t toUINT64(std::uint64_t u64Min=std::numeric_limits< std::uint64_t >::min(), std::uint64_t u64Max=std::numeric_limits< std::uint64_t >::max()) const
std::uint32_t toUINT32(std::uint32_t u32Min=std::numeric_limits< std::uint32_t >::min(), std::uint32_t u32Max=std::numeric_limits< std::uint32_t >::max()) const
double toDouble(double dMin=std::numeric_limits< double >::lowest(), double dMax=std::numeric_limits< double >::max()) const
void set(const std::string &sAddress, std::uint16_t u16Port)
ParameterConvert(const std::string &sParameter)
std::int16_t toINT16(std::int16_t i16Min=std::numeric_limits< std::int16_t >::min(), std::int16_t i16Max=std::numeric_limits< std::int16_t >::max()) const
std::int32_t toINT32(std::int32_t i32Min=std::numeric_limits< std::int32_t >::min(), std::int32_t i32Max=std::numeric_limits< std::int32_t >::max()) const
std::int64_t toINT64(std::int64_t i64Min=std::numeric_limits< std::int64_t >::min(), std::int64_t i64Max=std::numeric_limits< std::int64_t >::max()) const