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
a06b5292
Commit
a06b5292
authored
Jul 01, 2017
by
Davis King
Browse files
Added select_oldest_file() and select_newest_file()
parent
0796ce79
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
0 deletions
+77
-0
dlib/dir_nav/dir_nav_extensions.cpp
dlib/dir_nav/dir_nav_extensions.cpp
+34
-0
dlib/dir_nav/dir_nav_extensions.h
dlib/dir_nav/dir_nav_extensions.h
+14
-0
dlib/dir_nav/dir_nav_extensions_abstract.h
dlib/dir_nav/dir_nav_extensions_abstract.h
+29
-0
No files found.
dlib/dir_nav/dir_nav_extensions.cpp
View file @
a06b5292
...
...
@@ -77,6 +77,40 @@ namespace dlib
return
directory
(
f
.
full_name
().
substr
(
0
,
pos
));
}
// ----------------------------------------------------------------------------------------
std
::
string
select_oldest_file
(
const
std
::
string
&
filename1
,
const
std
::
string
&
filename2
)
{
file
f1
,
f2
;
try
{
f1
=
file
(
filename1
);}
catch
(
file
::
file_not_found
&
)
{
return
filename1
;
}
try
{
f2
=
file
(
filename2
);}
catch
(
file
::
file_not_found
&
)
{
return
filename2
;
}
if
(
f1
.
last_modified
()
<
f2
.
last_modified
())
return
filename1
;
else
return
filename2
;
}
// ----------------------------------------------------------------------------------------
std
::
string
select_newest_file
(
const
std
::
string
&
filename1
,
const
std
::
string
&
filename2
)
{
file
f1
,
f2
;
try
{
f1
=
file
(
filename1
);}
catch
(
file
::
file_not_found
&
)
{
return
filename2
;
}
try
{
f2
=
file
(
filename2
);}
catch
(
file
::
file_not_found
&
)
{
return
filename1
;
}
if
(
f1
.
last_modified
()
>
f2
.
last_modified
())
return
filename1
;
else
return
filename2
;
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/dir_nav/dir_nav_extensions.h
View file @
a06b5292
...
...
@@ -146,6 +146,20 @@ namespace dlib
const
file
&
f
);
// ----------------------------------------------------------------------------------------
std
::
string
select_oldest_file
(
const
std
::
string
&
filename1
,
const
std
::
string
&
filename2
);
// ----------------------------------------------------------------------------------------
std
::
string
select_newest_file
(
const
std
::
string
&
filename1
,
const
std
::
string
&
filename2
);
// ----------------------------------------------------------------------------------------
}
...
...
dlib/dir_nav/dir_nav_extensions_abstract.h
View file @
a06b5292
...
...
@@ -165,6 +165,35 @@ namespace dlib
- returns a default initialized directory (i.e. directory())
!*/
// ----------------------------------------------------------------------------------------
std
::
string
select_oldest_file
(
const
std
::
string
&
filename1
,
const
std
::
string
&
filename2
);
/*!
ensures
- Checks the last modification times of the two given files and returns the
filename of the oldest file, i.e., the file that has gone longest since being
modified. Ties are broken arbitrarily.
- For the purpose of comparison, a file that doesn't exist is presumed to have
a last modification time of -infinity (i.e. very far in the past).
!*/
// ----------------------------------------------------------------------------------------
std
::
string
select_newest_file
(
const
std
::
string
&
filename1
,
const
std
::
string
&
filename2
);
/*!
ensures
- Checks the last modification times of the two given files and returns the
filename that was most recently modified. Ties are broken arbitrarily.
- For the purpose of comparison, a file that doesn't exist is presumed to have
a last modification time of -infinity (i.e. very far in the past).
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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