Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liblinphone
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
10
Issues
10
List
Board
Labels
Milestones
Merge Requests
21
Merge Requests
21
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
External Wiki
External Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
BC
public
liblinphone
Commits
fc861ade
Commit
fc861ade
authored
Sep 25, 2017
by
Ronan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(Variant): add getValueAsNumber impl
parent
84df0776
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
21 deletions
+50
-21
utils.h
include/linphone/utils/utils.h
+2
-0
utils.cpp
src/utils/utils.cpp
+16
-20
variant.cpp
src/variant/variant.cpp
+32
-1
No files found.
include/linphone/utils/utils.h
View file @
fc861ade
...
...
@@ -70,11 +70,13 @@ namespace Utils {
LINPHONE_PUBLIC
std
::
string
toString
(
const
void
*
val
);
LINPHONE_PUBLIC
int
stoi
(
const
std
::
string
&
str
,
size_t
*
idx
=
0
,
int
base
=
10
);
LINPHONE_PUBLIC
long
long
stoll
(
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
int
stoi
(
const
char
*
str
,
size_t
*
idx
=
0
,
int
base
=
10
);
LINPHONE_PUBLIC
long
long
stoll
(
const
char
*
str
,
size_t
*
idx
=
0
,
int
base
=
10
);
LINPHONE_PUBLIC
double
stod
(
const
char
*
str
,
size_t
*
idx
=
0
);
LINPHONE_PUBLIC
float
stof
(
const
char
*
str
,
size_t
*
idx
=
0
);
...
...
src/utils/utils.cpp
View file @
fc861ade
...
...
@@ -85,33 +85,19 @@ string Utils::toString (const void *val) {
}
int
Utils
::
stoi
(
const
string
&
str
,
size_t
*
idx
,
int
base
)
{
char
*
p
;
int
v
=
static_cast
<
int
>
(
strtol
(
str
.
c_str
(),
&
p
,
base
));
if
(
idx
)
*
idx
=
static_cast
<
size_t
>
(
p
-
str
.
c_str
());
return
stoi
(
str
.
c_str
(),
idx
,
base
);
}
return
v
;
long
long
Utils
::
stoll
(
const
string
&
str
,
size_t
*
idx
,
int
base
)
{
return
stoll
(
str
.
c_str
(),
idx
,
base
);
}
double
Utils
::
stod
(
const
string
&
str
,
size_t
*
idx
)
{
char
*
p
;
double
v
=
strtod
(
str
.
c_str
(),
&
p
);
if
(
idx
)
*
idx
=
static_cast
<
size_t
>
(
p
-
str
.
c_str
());
return
v
;
return
stod
(
str
.
c_str
(),
idx
);
}
float
Utils
::
stof
(
const
string
&
str
,
size_t
*
idx
)
{
char
*
p
;
float
v
=
strtof
(
str
.
c_str
(),
&
p
);
if
(
idx
)
*
idx
=
static_cast
<
size_t
>
(
p
-
str
.
c_str
());
return
v
;
return
stof
(
str
.
c_str
(),
idx
);
}
bool
Utils
::
stob
(
const
string
&
str
)
{
...
...
@@ -129,6 +115,16 @@ int Utils::stoi (const char *str, size_t *idx, int base) {
return
v
;
}
long
long
Utils
::
stoll
(
const
char
*
str
,
size_t
*
idx
,
int
base
)
{
char
*
p
;
long
long
v
=
static_cast
<
int
>
(
strtoll
(
str
,
&
p
,
base
));
if
(
idx
)
*
idx
=
static_cast
<
size_t
>
(
p
-
str
);
return
v
;
}
double
Utils
::
stod
(
const
char
*
str
,
size_t
*
idx
)
{
char
*
p
;
double
v
=
strtod
(
str
,
&
p
);
...
...
src/variant/variant.cpp
View file @
fc861ade
...
...
@@ -315,7 +315,38 @@ static inline unsigned long long getAssumedUnsignedNumber (const VariantPrivate
// -----------------------------------------------------------------------------
static
inline
long
long
getValueAsNumber
(
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
:
case
Variant
:
:
Double
:
case
Variant
:
:
Float
:
return
getAssumedNumber
(
p
);
case
Variant
:
:
UnsignedInt
:
case
Variant
:
:
UnsignedShort
:
case
Variant
:
:
UnsignedLong
:
case
Variant
:
:
UnsignedLongLong
:
return
static_cast
<
long
long
>
(
getAssumedUnsignedNumber
(
p
));
case
Variant
:
:
Bool
:
return
static_cast
<
long
long
>
(
p
.
value
.
b
);
case
Variant
:
:
String
:
return
Utils
::
stoll
(
*
p
.
value
.
str
);
case
Variant
:
:
Generic
:
return
static_cast
<
long
long
>
(
!!
p
.
value
.
g
);
default
:
*
soFarSoGood
=
false
;
}
return
0
;
}
...
...
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