Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CT Input Output Library
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
kulvait
CT Input Output Library
Commits
109bb971
Commit
109bb971
authored
Jan 28, 2020
by
kulvait
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Time reporting
*Improved program reporting of the time
parent
1a2eaba5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
16 deletions
+44
-16
include/PROG/Arguments.hpp
include/PROG/Arguments.hpp
+17
-10
src/PROG/Arguments.cpp
src/PROG/Arguments.cpp
+6
-3
src/PROG/Program.cpp
src/PROG/Program.cpp
+21
-3
No files found.
include/PROG/Arguments.hpp
View file @
109bb971
#pragma once
#include "PROG/parseArgs.h"
#include "CLI/CLI.hpp" //Command line parser
#include "PROG/parseArgs.h"
namespace
CTL
::
util
{
class
Arguments
{
public:
Arguments
(
int
argc
,
char
**
argv
,
std
::
string
appName
=
""
);
Arguments
(
int
argc
,
char
**
argv
,
std
::
string
appName
=
""
);
std
::
shared_ptr
<
CLI
::
App
>
getCliApp
();
//Call this function for parsing
int
parse
();
virtual
void
defineArguments
()
=
0
;
virtual
int
preParse
()
=
0
;
virtual
int
postParse
()
=
0
;
// Call this function for parsing
/**
* @brief
*
* @param helpOnError Whether to print a help message on parsing error.
*
* @return
*/
int
parse
(
bool
helpOnError
=
true
);
virtual
void
defineArguments
()
=
0
;
virtual
int
preParse
()
=
0
;
virtual
int
postParse
()
=
0
;
protected:
std
::
shared_ptr
<
CLI
::
App
>
cliApp
;
int
argc
;
char
**
argv
;
int
argc
;
char
**
argv
;
};
}
// namespace CTL
}
// namespace CTL
::util
src/PROG/Arguments.cpp
View file @
109bb971
...
...
@@ -9,7 +9,7 @@ Arguments::Arguments(int argc, char* argv[], std::string appName)
cliApp
=
std
::
make_shared
<
CLI
::
App
>
(
appName
);
}
int
Arguments
::
parse
()
int
Arguments
::
parse
(
bool
helpOnError
)
{
this
->
defineArguments
();
try
...
...
@@ -33,8 +33,11 @@ int Arguments::parse()
}
catch
(
const
CLI
::
ParseError
&
e
)
{
int
exitcode
=
cliApp
->
exit
(
e
);
LOGE
<<
io
::
xprintf
(
"There was perse error with exit code %d catched.
\n
%s"
,
exitcode
,
cliApp
->
help
().
c_str
());
LOGE
<<
io
::
xprintf
(
"There was perse error with exit code %d catched."
,
exitcode
);
if
(
helpOnError
)
{
std
::
cout
<<
cliApp
->
help
();
}
return
-
1
;
}
catch
(...)
{
...
...
src/PROG/Program.cpp
View file @
109bb971
...
...
@@ -25,12 +25,30 @@ void Program::startLog() { LOGI << io::xprintf("START %s", rti.getExecutableName
void
Program
::
endLog
(
bool
reportTimings
)
{
using
namespace
std
::
chrono
;
if
(
reportTimings
)
{
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
auto
t
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
steady_clock
::
now
()
-
start_time
);
LOGI
<<
io
::
xprintf
(
"END %s, duration %0.3f s."
,
rti
.
getExecutableName
().
c_str
(),
float
(
duration
.
count
()
/
1000.0
f
));
auto
min
=
duration_cast
<
minutes
>
(
t
);
t
-=
duration_cast
<
milliseconds
>
(
min
);
auto
h
=
duration_cast
<
hours
>
(
min
);
min
-=
duration_cast
<
minutes
>
(
h
);
if
(
h
.
count
()
>
0
)
{
LOGI
<<
io
::
xprintf
(
"END %s, duration %02dh %02dm %02.3fs."
,
rti
.
getExecutableName
().
c_str
(),
h
.
count
(),
min
.
count
(),
float
(
t
.
count
()
/
1000.0
f
));
}
else
if
(
min
.
count
()
>
0
)
{
LOGI
<<
io
::
xprintf
(
"END %s, duration %02dm %02.3fs."
,
rti
.
getExecutableName
().
c_str
(),
min
.
count
(),
float
(
t
.
count
()
/
1000.0
f
));
}
else
{
LOGI
<<
io
::
xprintf
(
"END %s, duration %02.3fs."
,
rti
.
getExecutableName
().
c_str
(),
float
(
t
.
count
()
/
1000.0
f
));
}
}
else
{
LOGI
<<
io
::
xprintf
(
"END %s"
,
rti
.
getExecutableName
().
c_str
());
...
...
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