TuttleOFX
1
|
An helper to cache any kind of files on your HDD. It allows to: More...
#include <DiskCacheTranslator.hpp>
Public Types | |
typedef std::size_t | KeyType |
Public Member Functions | |
void | setRootDir (const boost::filesystem::path &rootDir) |
Set the base directory for all cached files. | |
boost::filesystem::path | keyToAbsolutePath (const KeyType key) const |
Convert a key into a filepath. | |
boost::filesystem::path | keyToRelativePath (const KeyType key) const |
Convert a key into a filepath. | |
boost::filesystem::path | absolutePathToRelativePath (const boost::filesystem::path &absoluteKeypath) const |
Convert an absolute keypath into a relative keypath. | |
boost::filesystem::path | relativePathToAbsolutePath (const boost::filesystem::path &relativeKeypath) const |
Convert a relative keypath into an absolute keypath. | |
KeyType | relativePathToKey (const boost::filesystem::path &filepath) const |
Convert a filepath relative to basedir into a key. | |
KeyType | absolutePathToKey (const boost::filesystem::path &filepath) const |
Convert an absolute filepath into a key. | |
bool | contains (const KeyType key) const |
Check if the key exists. | |
bool | contains (const KeyType key, std::time_t &lastWriteTime) const |
Check if the key exists. | |
bool | contains (const boost::filesystem::path &keypath) const |
Check if the keypath exists. | |
bool | contains (const boost::filesystem::path &keypath, std::time_t &lastWriteTime) const |
Check if the keypath exists (absolute or relative path). | |
boost::filesystem::path | get (const KeyType key) const |
Retrieve an existing key. Throw an error if the key doesn't exist. | |
boost::filesystem::path | create (const KeyType key) |
Retrieve a absolute filepath from a key and create needed directories. Throw an error if you can't create directories or if basedir is not setted. | |
Private Attributes | |
boost::filesystem::path | _rootDir |
Static Private Attributes | |
static const std::size_t | s_digits = std::numeric_limits<KeyType>::digits |
static const std::size_t | s_nbCharSplit = 8 |
An helper to cache any kind of files on your HDD. It allows to:
Paths used here are only paths inside the cache.
Definition at line 21 of file DiskCacheTranslator.hpp.
typedef std::size_t tuttle::host::DiskCacheTranslator::KeyType |
Definition at line 24 of file DiskCacheTranslator.hpp.
DiskCacheTranslator::KeyType tuttle::host::DiskCacheTranslator::absolutePathToKey | ( | const boost::filesystem::path & | filepath | ) | const |
Convert an absolute filepath
into a key.
Definition at line 59 of file DiskCacheTranslator.cpp.
References absolutePathToRelativePath(), and relativePathToKey().
boost::filesystem::path tuttle::host::DiskCacheTranslator::absolutePathToRelativePath | ( | const boost::filesystem::path & | absoluteKeypath | ) | const |
Convert an absolute keypath into a relative keypath.
Definition at line 45 of file DiskCacheTranslator.cpp.
References _rootDir.
Referenced by absolutePathToKey().
bool tuttle::host::DiskCacheTranslator::contains | ( | const KeyType | key | ) | const |
Check if the key
exists.
Definition at line 64 of file DiskCacheTranslator.cpp.
References keyToAbsolutePath().
Referenced by tuttle::host::ThumbnailDiskCache::contains(), tuttle::host::ThumbnailDiskCache::containsUpToDate(), and get().
bool tuttle::host::DiskCacheTranslator::contains | ( | const KeyType | key, |
std::time_t & | lastWriteTime | ||
) | const |
Check if the key
exists.
Definition at line 70 of file DiskCacheTranslator.cpp.
References keyToAbsolutePath().
bool tuttle::host::DiskCacheTranslator::contains | ( | const boost::filesystem::path & | keypath | ) | const |
Check if the keypath
exists.
[in] | keypath | path inside the cache (absolute or relative path) |
Definition at line 81 of file DiskCacheTranslator.cpp.
References relativePathToAbsolutePath().
bool tuttle::host::DiskCacheTranslator::contains | ( | const boost::filesystem::path & | keypath, |
std::time_t & | lastWriteTime | ||
) | const |
Check if the keypath
exists (absolute or relative path).
[in] | keypath | path inside the cache (absolute or relative path) |
[out] | lastWriteTime | last write time of the cached file |
Definition at line 89 of file DiskCacheTranslator.cpp.
References relativePathToAbsolutePath().
boost::filesystem::path tuttle::host::DiskCacheTranslator::create | ( | const KeyType | key | ) |
Retrieve a absolute filepath from a key
and create needed directories. Throw an error if you can't create directories or if basedir is not setted.
Definition at line 109 of file DiskCacheTranslator.cpp.
References _rootDir, and keyToAbsolutePath().
Referenced by tuttle::host::ThumbnailDiskCache::create().
boost::filesystem::path tuttle::host::DiskCacheTranslator::get | ( | const KeyType | key | ) | const |
Retrieve an existing key. Throw an error if the key doesn't exist.
Definition at line 101 of file DiskCacheTranslator.cpp.
References contains(), and keyToAbsolutePath().
boost::filesystem::path tuttle::host::DiskCacheTranslator::keyToAbsolutePath | ( | const KeyType | key | ) | const |
Convert a key
into a filepath.
Definition at line 14 of file DiskCacheTranslator.cpp.
References keyToRelativePath(), and relativePathToAbsolutePath().
Referenced by contains(), tuttle::host::ThumbnailDiskCache::containsUpToDate(), create(), get(), tuttle::host::ThumbnailDiskCache::getThumbnail(), and tuttle::host::ThumbnailDiskCache::retrieveThumbnail().
boost::filesystem::path tuttle::host::DiskCacheTranslator::keyToRelativePath | ( | const KeyType | key | ) | const |
Convert a key
into a filepath.
Definition at line 19 of file DiskCacheTranslator.cpp.
References s_digits, and s_nbCharSplit.
Referenced by keyToAbsolutePath().
boost::filesystem::path tuttle::host::DiskCacheTranslator::relativePathToAbsolutePath | ( | const boost::filesystem::path & | relativeKeypath | ) | const [inline] |
Convert a relative keypath into an absolute keypath.
Definition at line 53 of file DiskCacheTranslator.hpp.
References _rootDir.
Referenced by contains(), and keyToAbsolutePath().
DiskCacheTranslator::KeyType tuttle::host::DiskCacheTranslator::relativePathToKey | ( | const boost::filesystem::path & | filepath | ) | const |
Convert a filepath
relative to basedir into a key.
Definition at line 35 of file DiskCacheTranslator.cpp.
Referenced by absolutePathToKey().
void tuttle::host::DiskCacheTranslator::setRootDir | ( | const boost::filesystem::path & | rootDir | ) | [inline] |
Set the base directory for all cached files.
Definition at line 34 of file DiskCacheTranslator.hpp.
References _rootDir.
Referenced by tuttle::host::ThumbnailDiskCache::setRootDir().
boost::filesystem::path tuttle::host::DiskCacheTranslator::_rootDir [private] |
Definition at line 105 of file DiskCacheTranslator.hpp.
Referenced by absolutePathToRelativePath(), create(), relativePathToAbsolutePath(), and setRootDir().
const std::size_t tuttle::host::DiskCacheTranslator::s_digits = std::numeric_limits<KeyType>::digits [static, private] |
Definition at line 27 of file DiskCacheTranslator.hpp.
Referenced by keyToRelativePath().
const std::size_t tuttle::host::DiskCacheTranslator::s_nbCharSplit = 8 [static, private] |
Definition at line 28 of file DiskCacheTranslator.hpp.
Referenced by keyToRelativePath().