TuttleOFX  1
tuttle::host::DiskCacheTranslator Class Reference

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

Detailed Description

An helper to cache any kind of files on your HDD. It allows to:

  • translate a key into a disk path
  • check if the files exists
  • create the sub-directories when needed

Paths used here are only paths inside the cache.

Definition at line 21 of file DiskCacheTranslator.hpp.


Member Typedef Documentation

Definition at line 24 of file DiskCacheTranslator.hpp.


Member Function Documentation

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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

bool tuttle::host::DiskCacheTranslator::contains ( const boost::filesystem::path &  keypath) const

Check if the keypath exists.

Parameters:
[in]keypathpath inside the cache (absolute or relative path)

Definition at line 81 of file DiskCacheTranslator.cpp.

References relativePathToAbsolutePath().

Here is the call graph for this function:

bool tuttle::host::DiskCacheTranslator::contains ( const boost::filesystem::path &  keypath,
std::time_t &  lastWriteTime 
) const

Check if the keypath exists (absolute or relative path).

Parameters:
[in]keypathpath inside the cache (absolute or relative path)
[out]lastWriteTimelast write time of the cached file

Definition at line 89 of file DiskCacheTranslator.cpp.

References relativePathToAbsolutePath().

Here is the call graph for this function:

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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

boost::filesystem::path tuttle::host::DiskCacheTranslator::keyToAbsolutePath ( const KeyType  key) const
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().


Field Documentation

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().


The documentation for this class was generated from the following files: