Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
G
gflags
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
gflags
Commits
a1e461d6
Commit
a1e461d6
authored
Aug 01, 2016
by
dreamer.dead
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change template FlagValue::OfType() to Type() getter.
parent
46ea10f0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
18 deletions
+16
-18
gflags.cc
src/gflags.cc
+16
-18
No files found.
src/gflags.cc
View file @
a1e461d6
...
@@ -191,6 +191,17 @@ static void ReportError(DieWhenReporting should_die, const char* format, ...) {
...
@@ -191,6 +191,17 @@ static void ReportError(DieWhenReporting should_die, const char* format, ...) {
class
CommandLineFlag
;
class
CommandLineFlag
;
class
FlagValue
{
class
FlagValue
{
public
:
public
:
enum
ValueType
{
FV_BOOL
=
0
,
FV_INT32
=
1
,
FV_UINT32
=
2
,
FV_INT64
=
3
,
FV_UINT64
=
4
,
FV_DOUBLE
=
5
,
FV_STRING
=
6
,
FV_MAX_INDEX
=
6
,
};
template
<
typename
FlagType
>
template
<
typename
FlagType
>
FlagValue
(
FlagType
*
valbuf
,
bool
transfer_ownership_of_value
);
FlagValue
(
FlagType
*
valbuf
,
bool
transfer_ownership_of_value
);
~
FlagValue
();
~
FlagValue
();
...
@@ -198,8 +209,7 @@ class FlagValue {
...
@@ -198,8 +209,7 @@ class FlagValue {
bool
ParseFrom
(
const
char
*
spec
);
bool
ParseFrom
(
const
char
*
spec
);
string
ToString
()
const
;
string
ToString
()
const
;
template
<
typename
FlagType
>
ValueType
Type
()
const
{
return
static_cast
<
ValueType
>
(
type_
);
}
bool
OfType
()
const
{
return
type_
==
FlagValueTraits
<
FlagType
>::
kValueType
;
}
private
:
private
:
friend
class
CommandLineFlag
;
// for many things, including Validate()
friend
class
CommandLineFlag
;
// for many things, including Validate()
...
@@ -209,17 +219,6 @@ class FlagValue {
...
@@ -209,17 +219,6 @@ class FlagValue {
friend
bool
TryParseLocked
(
const
CommandLineFlag
*
,
FlagValue
*
,
friend
bool
TryParseLocked
(
const
CommandLineFlag
*
,
FlagValue
*
,
const
char
*
,
string
*
);
// for New(), CopyFrom()
const
char
*
,
string
*
);
// for New(), CopyFrom()
enum
ValueType
{
FV_BOOL
=
0
,
FV_INT32
=
1
,
FV_UINT32
=
2
,
FV_INT64
=
3
,
FV_UINT64
=
4
,
FV_DOUBLE
=
5
,
FV_STRING
=
6
,
FV_MAX_INDEX
=
6
,
};
template
<
typename
FlagType
>
template
<
typename
FlagType
>
struct
FlagValueTraits
;
struct
FlagValueTraits
;
...
@@ -533,8 +532,7 @@ class CommandLineFlag {
...
@@ -533,8 +532,7 @@ class CommandLineFlag {
ValidateFnProto
validate_function
()
const
{
return
validate_fn_proto_
;
}
ValidateFnProto
validate_function
()
const
{
return
validate_fn_proto_
;
}
const
void
*
flag_ptr
()
const
{
return
current_
->
value_buffer_
;
}
const
void
*
flag_ptr
()
const
{
return
current_
->
value_buffer_
;
}
template
<
typename
FlagType
>
FlagValue
::
ValueType
Type
()
const
{
return
defvalue_
->
Type
();
}
bool
OfType
()
const
{
return
defvalue_
->
OfType
<
FlagType
>
();
}
void
FillCommandLineFlagInfo
(
struct
CommandLineFlagInfo
*
result
);
void
FillCommandLineFlagInfo
(
struct
CommandLineFlagInfo
*
result
);
...
@@ -826,7 +824,7 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg,
...
@@ -826,7 +824,7 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg,
kError
,
key
->
c_str
());
kError
,
key
->
c_str
());
return
NULL
;
return
NULL
;
}
}
if
(
!
flag
->
OfType
<
bool
>
()
)
{
if
(
flag
->
Type
()
!=
FlagValue
::
FV_BOOL
)
{
// 'x' exists but is not boolean, so we're not in the exception case.
// 'x' exists but is not boolean, so we're not in the exception case.
*
error_message
=
StringPrintf
(
*
error_message
=
StringPrintf
(
"%sboolean value (%s) specified for %s command line flag
\n
"
,
"%sboolean value (%s) specified for %s command line flag
\n
"
,
...
@@ -840,7 +838,7 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg,
...
@@ -840,7 +838,7 @@ CommandLineFlag* FlagRegistry::SplitArgumentLocked(const char* arg,
}
}
// Assign a value if this is a boolean flag
// Assign a value if this is a boolean flag
if
(
*
v
==
NULL
&&
flag
->
OfType
<
bool
>
()
)
{
if
(
*
v
==
NULL
&&
flag
->
Type
()
==
FlagValue
::
FV_BOOL
)
{
*
v
=
"1"
;
// the --nox case was already handled, so this is the --x case
*
v
=
"1"
;
// the --nox case was already handled, so this is the --x case
}
}
...
@@ -1124,7 +1122,7 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
...
@@ -1124,7 +1122,7 @@ uint32 CommandLineFlagParser::ParseNewCommandLineFlags(int* argc, char*** argv,
// "-lat -30.5" would trigger the warning. The common cases we
// "-lat -30.5" would trigger the warning. The common cases we
// want to solve talk about true and false as values.
// want to solve talk about true and false as values.
if
(
value
[
0
]
==
'-'
if
(
value
[
0
]
==
'-'
&&
flag
->
OfType
<
string
>
()
&&
flag
->
Type
()
!=
FlagValue
::
FV_STRING
&&
(
strstr
(
flag
->
help
(),
"true"
)
&&
(
strstr
(
flag
->
help
(),
"true"
)
||
strstr
(
flag
->
help
(),
"false"
)))
{
||
strstr
(
flag
->
help
(),
"false"
)))
{
LOG
(
WARNING
)
<<
"Did you really mean to set flag '"
LOG
(
WARNING
)
<<
"Did you really mean to set flag '"
...
...
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