C++ Utilities 5.32.1
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
archive.h
Go to the documentation of this file.
1#ifndef CPP_UTILITIES_ARCHIVE_H
2#define CPP_UTILITIES_ARCHIVE_H
3
5#include "../global.h"
6
7#include <functional>
8#include <map>
9#include <stdexcept>
10#include <string>
11#include <string_view>
12#include <vector>
13
14namespace CppUtilities {
15
21class CPP_UTILITIES_EXPORT ArchiveException : public std::runtime_error {
22public:
23 explicit ArchiveException() noexcept;
24 explicit ArchiveException(std::string_view what) noexcept;
25 ~ArchiveException() override;
26};
27
32 : std::runtime_error("unable to convert")
33{
34}
35
39inline ArchiveException::ArchiveException(std::string_view what) noexcept
40 : std::runtime_error(what.data())
41{
42}
43
48
76
78using FileMap = std::map<std::string, std::vector<ArchiveFile>>;
80using FilePredicate = std::function<bool(const char *, const char *, mode_t)>;
82using DirectoryHandler = std::function<bool(std::string_view path)>;
84using FileHandler = std::function<bool(std::string_view path, ArchiveFile &&file)>;
85
86CPP_UTILITIES_EXPORT FileMap extractFiles(std::string_view archivePath, const FilePredicate &isFileRelevant = FilePredicate());
87CPP_UTILITIES_EXPORT void walkThroughArchive(std::string_view archivePath, const FilePredicate &isFileRelevant = FilePredicate(),
88 FileHandler &&fileHandler = FileHandler(), DirectoryHandler &&directoryHandler = DirectoryHandler());
90 std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant = FilePredicate());
91CPP_UTILITIES_EXPORT void walkThroughArchiveFromBuffer(std::string_view archiveData, std::string_view archiveName,
92 const FilePredicate &isFileRelevant = FilePredicate(), FileHandler &&fileHandler = FileHandler(),
93 DirectoryHandler &&directoryHandler = DirectoryHandler());
94
95} // namespace CppUtilities
96
97#endif // CPP_UTILITIES_ARCHIVE_H
ArchiveException() noexcept
Constructs a new ArchiveException.
Definition archive.h:31
Represents an instant in time, typically expressed as a date and time of day.
Definition datetime.h:55
#define CPP_UTILITIES_EXPORT
Marks the symbol to be exported by the c++utilities library.
Definition global.h:14
Contains all utilities provided by the c++utilities library.
CPP_UTILITIES_EXPORT void walkThroughArchiveFromBuffer(std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant=FilePredicate(), FileHandler &&fileHandler=FileHandler(), DirectoryHandler &&directoryHandler=DirectoryHandler())
Invokes callbacks for files and directories in the specified archive.
Definition archive.cpp:191
CPP_UTILITIES_EXPORT FileMap extractFilesFromBuffer(std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant=FilePredicate())
Extracts the specified archive.
Definition archive.cpp:216
CPP_UTILITIES_EXPORT void walkThroughArchive(std::string_view archivePath, const FilePredicate &isFileRelevant=FilePredicate(), FileHandler &&fileHandler=FileHandler(), DirectoryHandler &&directoryHandler=DirectoryHandler())
Invokes callbacks for files and directories in the specified archive.
Definition archive.cpp:226
ArchiveFileType
The ArchiveFileType enum specifies the type of a file within an archive.
Definition archive.h:47
std::function< bool(const char *, const char *, mode_t)> FilePredicate
A function that is invoked for each file within an archive. If it returns true, the file is considere...
Definition archive.h:80
CPP_UTILITIES_EXPORT FileMap extractFiles(std::string_view archivePath, const FilePredicate &isFileRelevant=FilePredicate())
Extracts the specified archive.
Definition archive.cpp:258
std::function< bool(std::string_view path)> DirectoryHandler
A function that is invoked by the walk-through-functions to return a directory.
Definition archive.h:82
std::map< std::string, std::vector< ArchiveFile > > FileMap
A map of files extracted from an archive. Keys represent directories and values files within those di...
Definition archive.h:78
std::function< bool(std::string_view path, ArchiveFile &&file)> FileHandler
A function that is invoked by the walk-through-functions to return a file.
Definition archive.h:84
STL namespace.
The ArchiveFile class holds data about a file within an archive.
Definition archive.h:60
CppUtilities::DateTime modificationTime
Definition archive.h:73
ArchiveFileType type
Definition archive.h:74
CppUtilities::DateTime creationTime
Definition archive.h:72
ArchiveFile(std::string &&name, std::string &&content, ArchiveFileType type, CppUtilities::DateTime creationTime, CppUtilities::DateTime modificationTime)
Definition archive.h:61