GCC Code Coverage Report


./
File: libs/io/zip/archive.hpp
Date: 2025-01-21 16:21:04
Lines:
7/19
36.8%
Functions:
1/7
14.3%
Branches:
10/26
38.5%

Line Branch Exec Source
1 /************************************************************************
2 *
3 * Copyright (C) 2009-2024 IRCAD France
4 * Copyright (C) 2012-2021 IHU Strasbourg
5 *
6 * This file is part of Sight.
7 *
8 * Sight is free software: you can redistribute it and/or modify it under
9 * the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Sight is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
20 *
21 ***********************************************************************/
22
23 #pragma once
24
25 #include <sight/io/zip/config.hpp>
26
27 #include <core/macros.hpp>
28
29 #include <filesystem>
30
31 namespace sight::io::zip
32 {
33
34 /// Class that allow reading and writing an archive.
35 class SIGHT_IO_ZIP_CLASS_API archive
36 {
37 public:
38
39 SIGHT_DECLARE_CLASS(archive);
40
41 /// Delete default constructors and assignment operators, as we don't want to allow resources duplication
42 archive() = delete;
43 archive(const archive&) = delete;
44 archive(archive&&) = delete;
45 archive& operator=(const archive&) = delete;
46 archive& operator=(archive&&) = delete;
47
48 /// Destructor
49 SIGHT_IO_ZIP_API virtual ~archive();
50
51 /// Enum to define
52 enum class archive_format : uint8_t
53 {
54 filesystem = 0, /// Use the filesystem to store files.
55 compatible = 2, /// Store files in a ZIP archive, with old deflate algorithm
56 optimized = 3, /// Store files in a ZIP archive, with zstd algorithm
57 DEFAULT = optimized, /// Default behavior if nothing is set
58 invalid = 255 /// Used for error management
59 };
60
61 /// Convenience function to convert from archiveFormat enum value to string
62 constexpr static std::string_view archive_format_to_string(archive_format _archive_format) noexcept
63 {
64 switch(_archive_format)
65 {
66 case archive_format::filesystem:
67 return "filesystem";
68
69 case archive_format::compatible:
70 return "compatible";
71
72 case archive_format::optimized:
73 return "optimized";
74
75 default:
76 return "default";
77 }
78 }
79
80 /// Convenience function to convert from string to archiveFormat enum value
81 124 constexpr static archive_format string_to_archive_format(std::string_view _archive_format) noexcept
82 {
83
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 115 times.
124 if(_archive_format == archive_format_to_string(archive_format::filesystem))
84 {
85 return archive_format::filesystem;
86 }
87
88
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if(_archive_format == archive_format_to_string(archive_format::compatible))
89 {
90 return archive_format::compatible;
91 }
92
93
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
8 if(_archive_format == archive_format_to_string(archive_format::optimized))
94 {
95 return archive_format::optimized;
96 }
97
98
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 if(_archive_format.empty() || _archive_format == "default")
99 {
100 return archive_format::DEFAULT;
101 }
102
103 // Error case
104 return archive_format::invalid;
105 }
106
107 /// Returns the path of the archive
108 inline const std::filesystem::path& get_archive_path() const;
109
110 protected:
111
112 /// Constructor
113 SIGHT_IO_ZIP_API archive(const std::filesystem::path& _archive_path);
114
115 private:
116
117 const std::filesystem::path m_archive_path;
118 };
119
120 //------------------------------------------------------------------------------
121
122 2 inline const std::filesystem::path& archive::get_archive_path() const
123 {
124
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
2 return m_archive_path;
125 }
126
127 } // namespace sight::io::zip
128