C++ Utilities 5.26.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
53 explicit ArchiveFile(
54 std::string &&name, std::string &&content, ArchiveFileType type, CppUtilities::DateTime creationTime, CppUtilities::DateTime modificationTime)
55 : name(name)
56 , content(content)
57 , creationTime(creationTime)
58 , modificationTime(modificationTime)
59 , type(type)
60 {
61 }
62 std::string name;
63 std::string content;
67};
68
70using FileMap = std::map<std::string, std::vector<ArchiveFile>>;
72using FilePredicate = std::function<bool(const char *, const char *, mode_t)>;
74using DirectoryHandler = std::function<bool(std::string_view path)>;
76using FileHandler = std::function<bool(std::string_view path, ArchiveFile &&file)>;
77
78CPP_UTILITIES_EXPORT FileMap extractFiles(std::string_view archivePath, const FilePredicate &isFileRelevant = FilePredicate());
79CPP_UTILITIES_EXPORT void walkThroughArchive(std::string_view archivePath, const FilePredicate &isFileRelevant = FilePredicate(),
80 FileHandler &&fileHandler = FileHandler(), DirectoryHandler &&directoryHandler = DirectoryHandler());
82 std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant = FilePredicate());
83CPP_UTILITIES_EXPORT void walkThroughArchiveFromBuffer(std::string_view archiveData, std::string_view archiveName,
84 const FilePredicate &isFileRelevant = FilePredicate(), FileHandler &&fileHandler = FileHandler(),
85 DirectoryHandler &&directoryHandler = DirectoryHandler());
86
87} // namespace CppUtilities
88
89#endif // CPP_UTILITIES_ARCHIVE_H
The ArchiveException class is thrown by the various archiving-related functions of this library when ...
Definition archive.h:21
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 provides 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:192
CPP_UTILITIES_EXPORT FileMap extractFilesFromBuffer(std::string_view archiveData, std::string_view archiveName, const FilePredicate &isFileRelevant=FilePredicate())
Extracts the specified archive.
Definition archive.cpp:217
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:227
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:72
CPP_UTILITIES_EXPORT FileMap extractFiles(std::string_view archivePath, const FilePredicate &isFileRelevant=FilePredicate())
Extracts the specified archive.
Definition archive.cpp:259
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:74
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:70
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:76
STL namespace.
The ArchiveFile class holds data about a file within an archive.
Definition archive.h:52
CppUtilities::DateTime modificationTime
Definition archive.h:65
ArchiveFileType type
Definition archive.h:66
CppUtilities::DateTime creationTime
Definition archive.h:64
ArchiveFile(std::string &&name, std::string &&content, ArchiveFileType type, CppUtilities::DateTime creationTime, CppUtilities::DateTime modificationTime)
Definition archive.h:53