Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
375f1172
Unverified
Commit
375f1172
authored
Nov 15, 2020
by
Adrià Arrufat
Committed by
GitHub
Nov 15, 2020
Browse files
Add custom ostream to console progress indicator (#2234)
parent
2ef8e3ac
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
+19
-17
dlib/console_progress_indicator.h
dlib/console_progress_indicator.h
+19
-17
No files found.
dlib/console_progress_indicator.h
View file @
375f1172
...
@@ -66,15 +66,16 @@ namespace dlib
...
@@ -66,15 +66,16 @@ namespace dlib
inline
bool
print_status
(
inline
bool
print_status
(
double
cur
,
double
cur
,
bool
always_print
=
false
bool
always_print
=
false
,
std
::
ostream
&
out
=
std
::
cout
);
);
/*!
/*!
ensures
ensures
- print_status() assumes it is called with values which are linearly
- print_status() assumes it is called with values which are linearly
approaching target(). It will attempt to predict how much time is
approaching target(). It will attempt to predict how much time is
remaining until cur becomes equal to target().
remaining until cur becomes equal to target().
- prints a status message to
the screen
which indicates how much
- prints a status message to
out
which indicates how much
more time is
more time is
left until cur is equal to target()
left until cur is equal to target()
- if (always_print) then
- if (always_print) then
- This function prints to the screen each time it is called.
- This function prints to the screen each time it is called.
- else
- else
...
@@ -120,7 +121,8 @@ namespace dlib
...
@@ -120,7 +121,8 @@ namespace dlib
bool
console_progress_indicator
::
bool
console_progress_indicator
::
print_status
(
print_status
(
double
cur
,
double
cur
,
bool
always_print
bool
always_print
,
std
::
ostream
&
out
)
)
{
{
const
time_t
cur_time
=
std
::
time
(
0
);
const
time_t
cur_time
=
std
::
time
(
0
);
...
@@ -149,30 +151,30 @@ namespace dlib
...
@@ -149,30 +151,30 @@ namespace dlib
double
seconds
=
delta_t
/
delta_val
*
std
::
abs
(
target_val
-
cur
);
double
seconds
=
delta_t
/
delta_val
*
std
::
abs
(
target_val
-
cur
);
std
::
ios
::
fmtflags
oldflags
=
std
::
c
out
.
flags
();
std
::
ios
::
fmtflags
oldflags
=
out
.
flags
();
std
::
c
out
.
setf
(
std
::
ios
::
fixed
,
std
::
ios
::
floatfield
);
out
.
setf
(
std
::
ios
::
fixed
,
std
::
ios
::
floatfield
);
std
::
streamsize
ss
;
std
::
streamsize
ss
;
if
(
seconds
<
60
)
if
(
seconds
<
60
)
{
{
ss
=
std
::
c
out
.
precision
(
0
);
ss
=
out
.
precision
(
0
);
std
::
c
out
<<
"Time remaining: "
<<
seconds
<<
" seconds.
\r
"
<<
std
::
flush
;
out
<<
"Time remaining: "
<<
seconds
<<
" seconds.
\r
"
<<
std
::
flush
;
}
}
else
if
(
seconds
<
60
*
60
)
else
if
(
seconds
<
60
*
60
)
{
{
ss
=
std
::
c
out
.
precision
(
2
);
ss
=
out
.
precision
(
2
);
std
::
c
out
<<
"Time remaining: "
<<
seconds
/
60
<<
" minutes.
\r
"
<<
std
::
flush
;
out
<<
"Time remaining: "
<<
seconds
/
60
<<
" minutes.
\r
"
<<
std
::
flush
;
}
}
else
else
{
{
ss
=
std
::
c
out
.
precision
(
2
);
ss
=
out
.
precision
(
2
);
std
::
c
out
<<
"Time remaining: "
<<
seconds
/
60
/
60
<<
" hours.
\r
"
<<
std
::
flush
;
out
<<
"Time remaining: "
<<
seconds
/
60
/
60
<<
" hours.
\r
"
<<
std
::
flush
;
}
}
// restore previous output flags and precision settings
// restore previous output flags and precision settings
std
::
c
out
.
flags
(
oldflags
);
out
.
flags
(
oldflags
);
std
::
c
out
.
precision
(
ss
);
out
.
precision
(
ss
);
return
true
;
return
true
;
}
}
...
...
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