Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
ArchiveIO.h
1#ifndef _ARCHIVEIO_H
2#define _ARCHIVEIO_H
3
4extern "C"
5{
6#include <mz.h>
7#include <mz_strm.h>
8#include <mz_zip.h>
9#include <mz_zip_rw.h>
10}
11#include <stdexcept>
12#include <string>
13
14class ArchiveIOGeneralException: public std::runtime_error
15{
16public:
17 explicit ArchiveIOGeneralException(int32_t status,
18 const std::string& action,
19 const std::string& log_location,
20 int32_t expectedStatus = MZ_OK):
21 std::runtime_error(log_location + "Failed to " + action
22 + " invalid status: " + std::to_string(status) + " ("
23 + std::to_string(expectedStatus) + " expected)")
24 {
25 }
26};
27
28class ArchiveIOSpecificException: public std::runtime_error
29{
30public:
31 ArchiveIOSpecificException(int32_t status,
32 const std::string& errMessage,
33 const std::string& log_location,
34 int32_t expectedStatus = MZ_OK):
35 std::runtime_error(log_location + errMessage + "\ninvalid status: " + std::to_string(status)
36 + " (" + std::to_string(expectedStatus) + " expected)")
37 {
38 }
39
40 ArchiveIOSpecificException(const std::string& errMessage, const std::string& log_location):
41 std::runtime_error(log_location + errMessage)
42 {
43 }
44};
45
46#include <filesystem>
47#include <shared_mutex>
48
50{
51private:
52 std::filesystem::path archivePath_;
53
54protected:
55 mutable std::shared_mutex mutex_;
56
57 virtual void Create() = 0;
58
59public:
60 explicit ArchiveIO(const std::filesystem::path& archivePath):
61 archivePath_(archivePath)
62 {
63 }
64
65 ArchiveIO() = default;
66 virtual ~ArchiveIO() = default;
67
68 std::filesystem::path ArchivePath() const
69 {
70 return archivePath_;
71 }
72
73 void SetArchivePath(const std::filesystem::path& archivePath)
74 {
75 archivePath_ = archivePath;
76 }
77
78 virtual int32_t Close() = 0;
79 virtual void Delete() = 0;
80
81 virtual int Open() = 0;
82 virtual void* InternalPointer() const = 0;
83};
84
85#endif // _ARCHIVEIO_H
Definition ArchiveIO.h:15
Definition ArchiveIO.h:29
Definition ArchiveIO.h:50