mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 19:18:06 +00:00
feat(Variant): add getValueAsFloat impl
This commit is contained in:
parent
d619eba238
commit
acce40efc3
3 changed files with 50 additions and 3 deletions
|
|
@ -50,6 +50,7 @@ namespace Utils {
|
|||
|
||||
LINPHONE_PUBLIC int stoi (const std::string &str, size_t *idx = 0, int base = 10);
|
||||
LINPHONE_PUBLIC double stod (const std::string &str, size_t *idx = 0);
|
||||
LINPHONE_PUBLIC float stof (const std::string &str, size_t *idx = 0);
|
||||
LINPHONE_PUBLIC bool stob (const std::string &str);
|
||||
|
||||
LINPHONE_PUBLIC std::string stringToLower (const std::string &str);
|
||||
|
|
|
|||
|
|
@ -94,12 +94,22 @@ int Utils::stoi (const string &str, size_t *idx, int base) {
|
|||
return v;
|
||||
}
|
||||
|
||||
double Utils::stod (const std::string &str, size_t *idx) {
|
||||
double Utils::stod (const string &str, size_t *idx) {
|
||||
char *p;
|
||||
double v = strtod(str.c_str(), &p);
|
||||
|
||||
if (idx)
|
||||
*idx = p - str.c_str();
|
||||
*idx = p - str.c_str();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
float Utils::stof (const string &str, size_t *idx) {
|
||||
char *p;
|
||||
float v = strtof(str.c_str(), &p);
|
||||
|
||||
if (idx)
|
||||
*idx = p - str.c_str();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -407,7 +407,43 @@ static inline double getValueAsDouble (const VariantPrivate &p, bool *soFarSoGoo
|
|||
}
|
||||
|
||||
static inline float getValueAsFloat (const VariantPrivate &p, bool *soFarSoGood) {
|
||||
// TODO.
|
||||
const int type = p.getType();
|
||||
L_ASSERT(type > Variant::Invalid && type < Variant::MaxDefaultTypes);
|
||||
|
||||
switch (static_cast<Variant::Type>(type)) {
|
||||
case Variant::Int:
|
||||
case Variant::Short:
|
||||
case Variant::Long:
|
||||
case Variant::LongLong:
|
||||
case Variant::Char:
|
||||
return static_cast<double>(getAssumedNumber(p));
|
||||
|
||||
case Variant::UnsignedInt:
|
||||
case Variant::UnsignedShort:
|
||||
case Variant::UnsignedLong:
|
||||
case Variant::UnsignedLongLong:
|
||||
return static_cast<double>(getAssumedUnsignedNumber(p));
|
||||
|
||||
case Variant::Float:
|
||||
return p.value.f;
|
||||
|
||||
case Variant::Double:
|
||||
return static_cast<float>(p.value.d);
|
||||
|
||||
case Variant::Bool:
|
||||
return static_cast<double>(p.value.b);
|
||||
|
||||
case Variant::String:
|
||||
return Utils::stof(*p.value.str);
|
||||
|
||||
case Variant::Generic:
|
||||
return static_cast<double>(!!p.value.g);
|
||||
|
||||
default:
|
||||
*soFarSoGood = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue