Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
acce40ef
Commit
acce40ef
authored
Sep 15, 2017
by
Ronan
Browse files
feat(Variant): add getValueAsFloat impl
parent
d619eba2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
3 deletions
+50
-3
include/linphone/utils/utils.h
include/linphone/utils/utils.h
+1
-0
src/utils/utils.cpp
src/utils/utils.cpp
+12
-2
src/variant/variant.cpp
src/variant/variant.cpp
+37
-1
No files found.
include/linphone/utils/utils.h
View file @
acce40ef
...
...
@@ -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
);
...
...
src/utils/utils.cpp
View file @
acce40ef
...
...
@@ -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
;
}
...
...
src/variant/variant.cpp
View file @
acce40ef
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment