mirror of
https://gitcode.com/gh_mirrors/ope/OpenFace.git
synced 2026-08-05 09:47:46 +00:00
Updating dlib and linking to it differently, increasing compilation speed and reducing dependency issues with it.
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
// Copyright (C) 2009 Davis E. King (davis@dlib.net)
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
#ifndef DLIB_DIR_NAV_EXTENSIONs_CPP_
|
||||
#define DLIB_DIR_NAV_EXTENSIONs_CPP_
|
||||
|
||||
#include "dir_nav_extensions.h"
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
namespace implementation_details
|
||||
{
|
||||
void get_all_sub_dirs (
|
||||
const directory& top_of_tree,
|
||||
unsigned long max_depth,
|
||||
std::vector<directory>& result,
|
||||
std::vector<directory>& temp
|
||||
)
|
||||
{
|
||||
if (max_depth > 0)
|
||||
{
|
||||
top_of_tree.get_dirs(temp);
|
||||
const unsigned long start = result.size();
|
||||
result.insert(result.end(), temp.begin(), temp.end());
|
||||
const unsigned long end = start + temp.size();
|
||||
|
||||
for (unsigned long i = start; i < end; ++i)
|
||||
{
|
||||
get_all_sub_dirs(result[i], max_depth-1, result, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool file_exists (
|
||||
const std::string& filename
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
dlib::file temp(filename);
|
||||
return true;
|
||||
}
|
||||
catch (file::file_not_found&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
directory get_parent_directory (
|
||||
const directory& dir
|
||||
)
|
||||
{
|
||||
return dir.get_parent();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
directory get_parent_directory (
|
||||
const file& f
|
||||
)
|
||||
{
|
||||
if (f.full_name().size() == 0)
|
||||
return directory();
|
||||
|
||||
std::string::size_type pos = f.full_name().find_last_of("\\/");
|
||||
|
||||
if (pos == std::string::npos)
|
||||
return directory();
|
||||
|
||||
return directory(f.full_name().substr(0,pos));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
#endif // DLIB_DIR_NAV_EXTENSIONs_CPP_
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
!*/
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
@@ -1,252 +0,0 @@
|
||||
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
#ifndef DLIB_DIR_NAV_KERNEL_1_CPp_
|
||||
#define DLIB_DIR_NAV_KERNEL_1_CPp_
|
||||
#include "../platform.h"
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "dir_nav_kernel_1.h"
|
||||
#include "../string.h"
|
||||
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
// Apparently the borland compiler doesn't define this.
|
||||
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
||||
#endif
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// file object implementation
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
void file::
|
||||
init (
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
char buf[3000];
|
||||
char* str;
|
||||
if (GetFullPathNameA(name.c_str(),sizeof(buf),buf,&str) == 0)
|
||||
{
|
||||
// the file was not found
|
||||
throw file_not_found("Unable to find file " + name);
|
||||
}
|
||||
state.full_name = buf;
|
||||
|
||||
|
||||
string::size_type pos = state.full_name.find_last_of(directory::get_separator());
|
||||
if (pos == string::npos)
|
||||
{
|
||||
// no valid full path has no separator characters.
|
||||
throw file_not_found("Unable to find file " + name);
|
||||
}
|
||||
state.name = state.full_name.substr(pos+1);
|
||||
|
||||
|
||||
// now find the size of this file
|
||||
WIN32_FIND_DATAA data;
|
||||
HANDLE ffind = FindFirstFileA(state.full_name.c_str(), &data);
|
||||
if (ffind == INVALID_HANDLE_VALUE ||
|
||||
(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||
{
|
||||
throw file_not_found("Unable to find file " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64 temp = data.nFileSizeHigh;
|
||||
temp <<= 32;
|
||||
temp |= data.nFileSizeLow;
|
||||
state.file_size = temp;
|
||||
FindClose(ffind);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool file::
|
||||
operator == (
|
||||
const file& rhs
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if (state.full_name.size() != rhs.state.full_name.size())
|
||||
return false;
|
||||
|
||||
// compare the strings but ignore the case because file names
|
||||
// are not case sensitive on windows
|
||||
return tolower(state.full_name) == tolower(rhs.state.full_name);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// directory object implementation
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
void directory::
|
||||
init (
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
char buf[3000];
|
||||
char* str;
|
||||
if (GetFullPathNameA(name.c_str(),sizeof(buf),buf,&str) == 0)
|
||||
{
|
||||
// the directory was not found
|
||||
throw dir_not_found("Unable to find directory " + name);
|
||||
}
|
||||
state.full_name = buf;
|
||||
|
||||
|
||||
const char sep = get_separator();
|
||||
if (is_root_path(state.full_name) == false)
|
||||
{
|
||||
// ensure that thre is not a trialing separator
|
||||
if (state.full_name[state.full_name.size()-1] == sep)
|
||||
state.full_name.erase(state.full_name.size()-1);
|
||||
|
||||
// pick out the directory name
|
||||
string::size_type pos = state.full_name.find_last_of(sep);
|
||||
state.name = state.full_name.substr(pos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ensure that there is a trailing separator
|
||||
if (state.full_name[state.full_name.size()-1] != sep)
|
||||
state.full_name += sep;
|
||||
}
|
||||
|
||||
|
||||
// now check that this is actually a valid directory
|
||||
DWORD attribs = GetFileAttributesA(state.full_name.c_str());
|
||||
if (attribs == INVALID_FILE_ATTRIBUTES ||
|
||||
(attribs&FILE_ATTRIBUTE_DIRECTORY) == 0)
|
||||
{
|
||||
// the directory was not found
|
||||
throw dir_not_found("Unable to find directory " + name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
char directory::
|
||||
get_separator (
|
||||
)
|
||||
{
|
||||
return '\\';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool directory::
|
||||
operator == (
|
||||
const directory& rhs
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
if (state.full_name.size() != rhs.state.full_name.size())
|
||||
return false;
|
||||
|
||||
// compare the strings but ignore the case because file names
|
||||
// are not case sensitive on windows
|
||||
return tolower(state.full_name) == tolower(rhs.state.full_name);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
const directory directory::
|
||||
get_parent (
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
// if *this is the root then just return *this
|
||||
if (is_root())
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
directory temp;
|
||||
|
||||
const char sep = get_separator();
|
||||
|
||||
string::size_type pos = state.full_name.find_last_of(sep);
|
||||
temp.state.full_name = state.full_name.substr(0,pos);
|
||||
|
||||
if ( is_root_path(temp.state.full_name))
|
||||
{
|
||||
temp.state.full_name += sep;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = temp.state.full_name.find_last_of(sep);
|
||||
if (pos != string::npos)
|
||||
{
|
||||
temp.state.name = temp.state.full_name.substr(pos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.state.full_name += sep;
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool directory::
|
||||
is_root_path (
|
||||
const std::string& path
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
const char sep = get_separator();
|
||||
bool root_path = false;
|
||||
if (path.size() > 2 && path[0] == sep && path[1] == sep)
|
||||
{
|
||||
// in this case this is a windows share path
|
||||
string::size_type pos = path.find_first_of(sep,2);
|
||||
if (pos != string::npos)
|
||||
{
|
||||
pos = path.find_first_of(sep,pos+1);
|
||||
|
||||
if (pos == string::npos && path[path.size()-1] != sep)
|
||||
root_path = true;
|
||||
else if (pos == path.size()-1)
|
||||
root_path = true;
|
||||
}
|
||||
|
||||
}
|
||||
else if ( (path.size() == 2 || path.size() == 3) && path[1] == ':')
|
||||
{
|
||||
// if this is a valid windows path then it must be a root path
|
||||
root_path = true;
|
||||
}
|
||||
|
||||
return root_path;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
#endif // DLIB_DIR_NAV_KERNEL_1_CPp_
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../stl_checked.h"
|
||||
#include "../enable_if.h"
|
||||
#include "../queue.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
@@ -39,11 +40,13 @@ namespace dlib
|
||||
state.name == name()
|
||||
state.full_name == full_name()
|
||||
state.file_size == size()
|
||||
state.last_modified == last_modified()
|
||||
|
||||
CONVENTION
|
||||
state.name == name()
|
||||
state.full_name == full_name()
|
||||
state.file_size == size()
|
||||
state.last_modified == last_modified()
|
||||
|
||||
!*/
|
||||
|
||||
@@ -54,6 +57,7 @@ namespace dlib
|
||||
uint64 file_size;
|
||||
std::string name;
|
||||
std::string full_name;
|
||||
std::chrono::time_point<std::chrono::system_clock> last_modified;
|
||||
};
|
||||
|
||||
|
||||
@@ -66,12 +70,14 @@ namespace dlib
|
||||
const std::string& name,
|
||||
const std::string& full_name,
|
||||
const uint64 file_size,
|
||||
const std::chrono::time_point<std::chrono::system_clock>& last_modified,
|
||||
private_constructor
|
||||
)
|
||||
{
|
||||
state.file_size = file_size;
|
||||
state.name = name;
|
||||
state.full_name = full_name;
|
||||
state.last_modified = last_modified;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +113,9 @@ namespace dlib
|
||||
inline uint64 size (
|
||||
) const { return state.file_size; }
|
||||
|
||||
inline std::chrono::time_point<std::chrono::system_clock> last_modified (
|
||||
) const { return state.last_modified; }
|
||||
|
||||
bool operator == (
|
||||
const file& rhs
|
||||
) const;
|
||||
@@ -413,8 +422,15 @@ namespace dlib
|
||||
uint64 file_size = data.nFileSizeHigh;
|
||||
file_size <<= 32;
|
||||
file_size |= data.nFileSizeLow;
|
||||
|
||||
ULARGE_INTEGER ull;
|
||||
ull.LowPart = data.ftLastWriteTime.dwLowDateTime;
|
||||
ull.HighPart = data.ftLastWriteTime.dwHighDateTime;
|
||||
std::chrono::nanoseconds epoch(100 * (ull.QuadPart - 116444736000000000));
|
||||
auto last_modified = std::chrono::time_point<std::chrono::system_clock>(std::chrono::duration_cast<std::chrono::system_clock::duration>(epoch));
|
||||
|
||||
// this is a file so add it to the queue
|
||||
file temp(data.cFileName,path+data.cFileName,file_size, private_constructor());
|
||||
file temp(data.cFileName,path+data.cFileName,file_size, last_modified, private_constructor());
|
||||
files.enqueue(temp);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
// Copyright (C) 2003 Davis E. King (davis@dlib.net)
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
#ifndef DLIB_DIR_NAV_KERNEL_2_CPp_
|
||||
#define DLIB_DIR_NAV_KERNEL_2_CPp_
|
||||
|
||||
#include "../platform.h"
|
||||
|
||||
#ifdef POSIX
|
||||
|
||||
|
||||
#include "dir_nav_kernel_2.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// file object implementation
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
void file::
|
||||
init (
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
char buf[PATH_MAX];
|
||||
if (realpath(name.c_str(),buf) == 0)
|
||||
{
|
||||
// the file was not found
|
||||
throw file_not_found("Unable to find file " + name);
|
||||
}
|
||||
state.full_name = buf;
|
||||
|
||||
|
||||
string::size_type pos = state.full_name.find_last_of(directory::get_separator());
|
||||
if (pos == string::npos)
|
||||
{
|
||||
// no valid full path has no separtor characters.
|
||||
throw file_not_found("Unable to find file " + name);
|
||||
}
|
||||
state.name = state.full_name.substr(pos+1);
|
||||
|
||||
|
||||
// now find the size of this file
|
||||
struct stat64 buffer;
|
||||
if (::stat64(state.full_name.c_str(), &buffer) ||
|
||||
S_ISDIR(buffer.st_mode))
|
||||
{
|
||||
// there was an error during the call to stat64 or
|
||||
// name is actually a directory
|
||||
throw file_not_found("Unable to find file " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.file_size = static_cast<uint64>(buffer.st_size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool file::
|
||||
operator == (
|
||||
const file& rhs
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
if (state.full_name.size() == 0 && rhs.state.full_name.size() == 0)
|
||||
return true;
|
||||
|
||||
// These files might have different names but actually represent the same
|
||||
// file due to the presence of symbolic links.
|
||||
char buf[PATH_MAX];
|
||||
string left, right;
|
||||
if (realpath(state.full_name.c_str(),buf) == 0)
|
||||
return false;
|
||||
left = buf;
|
||||
|
||||
if (realpath(rhs.state.full_name.c_str(),buf) == 0)
|
||||
return false;
|
||||
right = buf;
|
||||
|
||||
return (left == right);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// directory object implementation
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
void directory::
|
||||
init (
|
||||
const std::string& name
|
||||
)
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
char buf[PATH_MAX];
|
||||
if (realpath(name.c_str(),buf) == 0)
|
||||
{
|
||||
// the directory was not found
|
||||
throw dir_not_found("Unable to find directory " + name);
|
||||
}
|
||||
state.full_name = buf;
|
||||
|
||||
|
||||
const char sep = get_separator();
|
||||
if (is_root_path(state.full_name) == false)
|
||||
{
|
||||
// ensure that thre is not a trialing separator
|
||||
if (state.full_name[state.full_name.size()-1] == sep)
|
||||
state.full_name.erase(state.full_name.size()-1);
|
||||
|
||||
// pick out the directory name
|
||||
string::size_type pos = state.full_name.find_last_of(sep);
|
||||
state.name = state.full_name.substr(pos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ensure that there is a trailing separator
|
||||
if (state.full_name[state.full_name.size()-1] != sep)
|
||||
state.full_name += sep;
|
||||
}
|
||||
|
||||
|
||||
struct stat64 buffer;
|
||||
// now check that this is actually a valid directory
|
||||
if (::stat64(state.full_name.c_str(),&buffer))
|
||||
{
|
||||
// the directory was not found
|
||||
throw dir_not_found("Unable to find directory " + name);
|
||||
}
|
||||
else if (S_ISDIR(buffer.st_mode) == 0)
|
||||
{
|
||||
// It is not a directory
|
||||
throw dir_not_found("Unable to find directory " + name);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
char directory::
|
||||
get_separator (
|
||||
)
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool directory::
|
||||
operator == (
|
||||
const directory& rhs
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
if (state.full_name.size() == 0 && rhs.state.full_name.size() == 0)
|
||||
return true;
|
||||
|
||||
// These directories might have different names but actually represent the same
|
||||
// directory due to the presence of symbolic links.
|
||||
char buf[PATH_MAX];
|
||||
string left, right;
|
||||
if (realpath(state.full_name.c_str(),buf) == 0)
|
||||
return false;
|
||||
left = buf;
|
||||
|
||||
if (realpath(rhs.state.full_name.c_str(),buf) == 0)
|
||||
return false;
|
||||
right = buf;
|
||||
|
||||
return (left == right);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
const directory directory::
|
||||
get_parent (
|
||||
) const
|
||||
{
|
||||
using namespace std;
|
||||
// if *this is the root then just return *this
|
||||
if (is_root())
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
directory temp;
|
||||
|
||||
const char sep = get_separator();
|
||||
|
||||
string::size_type pos = state.full_name.find_last_of(sep);
|
||||
temp.state.full_name = state.full_name.substr(0,pos);
|
||||
|
||||
if ( is_root_path(temp.state.full_name))
|
||||
{
|
||||
temp.state.full_name += sep;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos = temp.state.full_name.find_last_of(sep);
|
||||
if (pos != string::npos)
|
||||
{
|
||||
temp.state.name = temp.state.full_name.substr(pos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
temp.state.full_name += sep;
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
bool directory::
|
||||
is_root_path (
|
||||
const std::string& path
|
||||
) const
|
||||
{
|
||||
const char sep = get_separator();
|
||||
if (path.size() == 1 && path[0] == sep)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
#endif // POSIX
|
||||
|
||||
#endif // DLIB_DIR_NAV_KERNEL_2_CPp_
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <chrono>
|
||||
|
||||
#if !defined(__USE_LARGEFILE64 ) && !defined(_LARGEFILE64_SOURCE)
|
||||
#define stat64 stat
|
||||
@@ -48,11 +49,13 @@ namespace dlib
|
||||
state.name == name()
|
||||
state.full_name == full_name()
|
||||
state.file_size == size()
|
||||
state.last_modified == last_modified()
|
||||
|
||||
CONVENTION
|
||||
state.name == name()
|
||||
state.full_name == full_name()
|
||||
state.file_size == size()
|
||||
state.last_modified == last_modified()
|
||||
|
||||
!*/
|
||||
|
||||
@@ -63,6 +66,7 @@ namespace dlib
|
||||
uint64 file_size;
|
||||
std::string name;
|
||||
std::string full_name;
|
||||
std::chrono::time_point<std::chrono::system_clock> last_modified;
|
||||
};
|
||||
|
||||
void init(const std::string& name);
|
||||
@@ -74,12 +78,14 @@ namespace dlib
|
||||
const std::string& name,
|
||||
const std::string& full_name,
|
||||
const uint64 file_size,
|
||||
const std::chrono::time_point<std::chrono::system_clock>& last_modified,
|
||||
private_constructor
|
||||
)
|
||||
{
|
||||
state.file_size = file_size;
|
||||
state.name = name;
|
||||
state.full_name = full_name;
|
||||
state.last_modified = last_modified;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +116,9 @@ namespace dlib
|
||||
inline uint64 size (
|
||||
) const { return state.file_size; }
|
||||
|
||||
inline std::chrono::time_point<std::chrono::system_clock> last_modified (
|
||||
) const { return state.last_modified; }
|
||||
|
||||
operator std::string (
|
||||
) const { return full_name(); }
|
||||
|
||||
@@ -383,6 +392,10 @@ namespace dlib
|
||||
{
|
||||
file_size = static_cast<uint64>(buffer.st_size);
|
||||
}
|
||||
auto last_modified = std::chrono::system_clock::from_time_t(buffer.st_mtime);
|
||||
#ifdef _BSD_SOURCE
|
||||
last_modified += std::chrono::duration_cast<std::chrono::system_clock::duration>(std::chrono::nanoseconds(buffer.st_atim.tv_nsec));
|
||||
#endif
|
||||
|
||||
if (S_ISDIR(buffer.st_mode) == 0)
|
||||
{
|
||||
@@ -391,6 +404,7 @@ namespace dlib
|
||||
data->d_name,
|
||||
path+data->d_name,
|
||||
file_size,
|
||||
last_modified,
|
||||
file::private_constructor()
|
||||
);
|
||||
files.enqueue(temp);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
#include "../uintn.h"
|
||||
#include "../algs.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
@@ -139,6 +140,13 @@ namespace dlib
|
||||
- returns the size of this file in bytes.
|
||||
!*/
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock> last_modified (
|
||||
) const;
|
||||
/*!
|
||||
ensures
|
||||
- returns the time the file was last modified.
|
||||
!*/
|
||||
|
||||
operator std::string (
|
||||
) const;
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user