Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
28729700
Commit
28729700
authored
Aug 19, 2021
by
LEFEBVREJP email
Browse files
Merge branch 'commandline-patch' into 'master'
Commandline patch See merge request
!122
parents
5bbeef85
3efb66c8
Pipeline
#159980
passed with stages
in 19 minutes and 39 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixcore/CMakeLists.txt
View file @
28729700
...
@@ -31,7 +31,7 @@ TRIBITS_ADD_LIBRARY(radixcore
...
@@ -31,7 +31,7 @@ TRIBITS_ADD_LIBRARY(radixcore
IF
(
MINGW
)
IF
(
MINGW
)
FIND_LIBRARY
(
PSAPI psapi
)
FIND_LIBRARY
(
PSAPI psapi
)
MESSAGE
(
STATUS
"Checking required PSAPI library"
)
MESSAGE
(
STATUS
"Checking required PSAPI library"
)
TARGET_LINK_LIBRARIES
(
radixcore
"
${
PSAPI
}
"
)
TARGET_LINK_LIBRARIES
(
radixcore
"
-lpsapi
"
)
ENDIF
()
ENDIF
()
#
#
# Add testing directory
# Add testing directory
...
...
radixcore/commandline.i.hh
View file @
28729700
...
@@ -3,8 +3,11 @@
...
@@ -3,8 +3,11 @@
#include <iomanip>
#include <iomanip>
#include <sstream>
#include <sstream>
#include <typeinfo>
#include <typeinfo>
#include "radixcore/bug.hh"
#include "radixcore/commandline.hh"
#include "radixbug/bug.hh"
#include "radixcommand/commandline.hh"
#include "radixcore/stringfunctions.hh"
namespace
radix
namespace
radix
{
{
template
<
typename
return_type
>
template
<
typename
return_type
>
...
@@ -31,7 +34,16 @@ return_type CommandLine::get(const std::string &name) const
...
@@ -31,7 +34,16 @@ return_type CommandLine::get(const std::string &name) const
// ss >> result;
// ss >> result;
// Fortify does not like >> operator (string termination)
// Fortify does not like >> operator (string termination)
if
(
typeid
(
int
)
==
typeid
(
return_type
))
if
(
typeid
(
bool
)
==
typeid
(
return_type
))
{
if
(
value
[
0
]
==
'1'
)
return
true
;
if
(
value
[
0
]
==
'0'
)
return
false
;
std
::
string
lower
=
radix
::
string_tolower
(
value
);
if
(
lower
.
compare
(
"true"
)
==
0
)
return
true
;
return
false
;
}
else
if
(
typeid
(
int
)
==
typeid
(
return_type
))
result
=
stoi
(
value
);
result
=
stoi
(
value
);
else
if
(
typeid
(
long
)
==
typeid
(
return_type
))
else
if
(
typeid
(
long
)
==
typeid
(
return_type
))
result
=
stol
(
value
);
result
=
stol
(
value
);
...
...
radixcore/tests/tstCommandLine.cc
View file @
28729700
...
@@ -94,3 +94,26 @@ TEST(radixcommand, args)
...
@@ -94,3 +94,26 @@ TEST(radixcommand, args)
std
::
string
a5
=
line
.
arg
<
std
::
string
>
(
5
);
std
::
string
a5
=
line
.
arg
<
std
::
string
>
(
5
);
EXPECT_EQ
(
"input 6"
,
a5
);
EXPECT_EQ
(
"input 6"
,
a5
);
}
}
TEST
(
radixcommand
,
GetBool
)
{
int
fake_argc
=
6
;
char
*
fake_argv
[]
=
{(
char
*
)(
"/Users/jap/build/release/dummy"
),
(
char
*
)
"-a=1"
,
(
char
*
)
"-b=0"
,
(
char
*
)
"-c=true"
,
(
char
*
)
"-d=false"
,
(
char
*
)
"-r=random"
};
CommandLine
line
(
fake_argc
,
fake_argv
);
line
.
addOption
(
"a"
,
"Numeric true bool."
,
true
);
line
.
addOption
(
"b"
,
"Numeric false bool."
,
true
);
line
.
addOption
(
"c"
,
"Alpha true bool."
,
true
);
line
.
addOption
(
"d"
,
"Alpha false bool."
,
true
);
line
.
addOption
(
"r"
,
"Default Alpha false bool."
,
true
);
EXPECT_TRUE
(
line
.
get
<
bool
>
(
"a"
));
EXPECT_FALSE
(
line
.
get
<
bool
>
(
"b"
));
EXPECT_TRUE
(
line
.
get
<
bool
>
(
"c"
));
EXPECT_FALSE
(
line
.
get
<
bool
>
(
"d"
));
EXPECT_FALSE
(
line
.
get
<
bool
>
(
"r"
));
}
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