×


FileCache
- Found In File: FileHelper.h





This class aids in caching the current log file, including its absolute path, directory, file name, and file extension.

Click here for a file snippet:

This struct is found under the namespace serenity::target::helpers in file FileHelper.h

class FileCache { public: FileCache(std::string_view path); FileCache(FileCache&) = delete; FileCache& operator=(FileCache&) = delete; ~FileCache() = default; void CacheFile(std::string_view path, bool ignoreExtInFileName = false); std::filesystem::path FilePath() const; std::filesystem::path DirPath() const; std::string DirName() const; std::string FileName() const; std::string Extenstion() const; // Helper Functions void SetFilePath(const std::filesystem::path& newPath); void SetFileDir(const std::string& newDir); void SetFileName(const std::string& newName); void SetExtension(const std::string& newExt); protected: std::filesystem::path filePath; std::string fileDir; std::string fileName; std::string extension; std::filesystem::path dirPath; };


Public Functions
FileCache(std::string_view path);
This is the only constructor available for this class.
void CacheFile(std::string_view path, bool ignoreExtInFileName=false);
This function is called in the FileCache constructor and is used to break the path up into parts to store.
std::filesystem::path FilePath() const
This function returns the file path that was cached as a std::filesystem::path object.
std::filesystem::path DirPath() const;
This function returns the log directory path that was cached as a std::filesystem::path object.
std::string DirName() const;
This function returns the log directory name that was cached as a std::string object.
std::string FileName() const;
This function returns the file name that was cached as a std::string object.
std::string Extenstion() const;
This function returns the extension format that was cached as a std::string object.
void SetFilePath(const std::filesystem::path& newPath);
This is a helper function that simply sets the member variable `filePath` to what `newPath` is without changing anything else.
void SetFileDir(const std::string& newDir);
This is a helper function that simply sets the member variable `fileDir` to what `newDir` is without changing anything else..
void SetFileName(const std::string& newName);
This is a helper function that simply sets the member variable `fileName` to what `newName` is without changing anything else.
void SetExtension(const std::string& newExt);
This is a helper function that simply sets the member variable `extension` to what `newExt` is without changing anything else.

More Information About Class FileCache


FileCache(std::string_view path);
This is the only constructor available for this class.
  • Parameter `path` is the path to the file, whether absolute or relative to the currently running process's directory.

  • It passes the `path` parameter into CacheFile() for caching with the default value of `ignoreExtInFileName`.

    Essentially calling: CacheFile(path, false);



    void CacheFile(std::string_view path, bool ignoreExtInFileName = false);
    This function is called in the FileCache constructor.
  • Parameter `path` is the path to the file, whether absolute or relative to the currently running process's directory.
  • Parameter `ignoreExtInFileName` controls whether or not we care about the extension of the file

  • This function does the following:
    • If `ignoreExtInFileName` is set to true
      • Then the member variable `extension` will be an empty string
      • Otherwise, it will set the member variable `extension` as described below

    • If the `path` variable provided is not an absolute path
      • Sets the `dirPath` member variable as the currently process's path + "Logs"
      • Sets the `fileDir` to "Logs"
      • Sets the `filePath` member variable to `dirPath` + `path`
      • Sets the `fileName` member variable to `filePath`'s stem data
      • Sets the extension to `fileNames' extension - if none is present, sets it to an empty string

    • Otherwise, if the `path` variable provided is an absolute path
      • Sets the `filePath` member variable to `path`
      • Sets the `dirPath` member variable to `path' minus the file name
      • Sets the `fileDir` to "dirPath"'s stem data
      • Sets the `fileName` member variable to `path`'s file name
      • Sets the extension to `fileNames' extension - if none is present, sets it to an empty string


    std::filesystem::path FilePath() const;
    This function returns the file path that was cached as a std::filesystem::path object.


    std::filesystem::path DirPath() const;
    This function returns the directory path that was cached as a std::filesystem::path object.


    std::string DirName() const;
    This function returns the log directory folder name that was cached as a std::string.


    std::string FileName() const;
    This function returns the log file's name that was cached as a std::string.


    std::string Extenstion() const;
    This function returns the log file's extension that was cached as a std::string.


    void SetFilePath(const std::filesystem::path& newPath);
    This is a helper function that simply sets the member variable `filePath` to what `newPath` is without changing anything else.


    void SetFileDir(const std::string& newDir);
    This is a helper function that simply sets the member variable `fileDir` to what `newDir` is without changing anything else.


    void SetFileName(const std::string& newName);
    This is a helper function that simply sets the member variable `fileName` to what `newName` is without changing anything else.


    void SetExtension(const std::string& newExt);
    This is a helper function that simply sets the member variable `extension` to what `newExt` is without changing anything else.