@@ -33,41 +33,64 @@ class IFileArchive : public core::IReferenceCounted
33
33
EAT_MALLOC // decompress to RAM
34
34
};
35
35
// ! An entry in a list of items, can be a folder or a file.
36
- struct SListEntry
36
+ struct SFileList
37
37
{
38
- // ! The name of the file including the path relative to archive root
39
- system::path pathRelativeToArchive;
40
-
41
- // ! The size of the file in bytes
42
- size_t size;
43
-
44
- // ! FileOffset inside an archive
45
- size_t offset;
46
-
47
- // ! The ID of the file in an archive, it maps it to a memory pool entry for CFileView
48
- uint32_t ID;
49
-
50
- // `EAT_NONE` for directories
51
- E_ALLOCATOR_TYPE allocatorType;
52
-
53
- // ! The == operator is provided so that CFileList can slowly search the list!
54
- inline bool operator ==(const struct SListEntry & other) const
55
- {
56
- return pathRelativeToArchive.string ()==other.pathRelativeToArchive .string ();
57
- }
58
-
59
- // ! The < operator is provided so that CFileList can sort and quickly search the list.
60
- inline bool operator <(const struct SListEntry & other) const
38
+ struct SEntry
61
39
{
62
- return pathRelativeToArchive<other.pathRelativeToArchive ;
63
- }
40
+ // same stuff as `SListEntry` right now
41
+ // ! The name of the file including the path relative to archive root
42
+ system::path pathRelativeToArchive;
43
+
44
+ // ! The size of the file in bytes
45
+ size_t size;
46
+
47
+ // ! FileOffset inside an archive
48
+ size_t offset;
49
+
50
+ // ! The ID of the file in an archive, it maps it to a memory pool entry for CFileView
51
+ uint32_t ID;
52
+
53
+ // `EAT_NONE` for directories
54
+ IFileArchive::E_ALLOCATOR_TYPE allocatorType;
55
+
56
+ // ! The == operator is provided so that CFileList can slowly search the list!
57
+ inline bool operator ==(const struct SEntry & other) const
58
+ {
59
+ return pathRelativeToArchive.string () == other.pathRelativeToArchive .string ();
60
+ }
61
+
62
+ // ! The < operator is provided so that CFileList can sort and quickly search the list.
63
+ inline bool operator <(const struct SEntry & other) const
64
+ {
65
+ return pathRelativeToArchive < other.pathRelativeToArchive ;
66
+ }
67
+ };
68
+ using refctd_storage_t = std::shared_ptr<const std::vector<SEntry>>;
69
+ using range_t = core::SRange<const SEntry>;
70
+
71
+ inline operator range_t () const { return m_range; }
72
+
73
+ SFileList (const SFileList&) = default ;
74
+ SFileList (SFileList&&) = default ;
75
+ SFileList& operator =(const SFileList&) = default ;
76
+ SFileList& operator =(SFileList&&) = default ;
77
+
78
+ private:
79
+ // default ctor full range
80
+ SFileList (refctd_storage_t _data) : m_data(_data), m_range({ _data->data (),_data->data () + _data->size () }) {}
81
+
82
+ friend class IFileArchive ;
83
+ refctd_storage_t m_data;
84
+ range_t m_range;
64
85
};
65
86
66
87
//
67
- virtual core::SRange<const SListEntry> listAssets () const {return {m_items.data (),m_items.data ()+m_items.size ()};}
88
+ virtual inline SFileList listAssets () const {
89
+ return { m_items.load () };
90
+ }
68
91
69
92
// List all files and directories in a specific dir of the archive
70
- virtual core::SRange< const SListEntry> listAssets (const path& asset_path ) const ;
93
+ virtual SFileList listAssets (const path& pathRelativeToArchive ) const ;
71
94
72
95
//
73
96
virtual core::smart_refctd_ptr<IFile> getFile (const path& pathRelativeToArchive, const std::string_view& password) = 0;
@@ -79,19 +102,20 @@ class IFileArchive : public core::IReferenceCounted
79
102
IFileArchive (path&& _defaultAbsolutePath, system::logger_opt_smart_ptr&& logger) :
80
103
m_defaultAbsolutePath (std::move(_defaultAbsolutePath)), m_logger(std::move(logger)) {}
81
104
82
- inline const SListEntry * getItemFromPath (const system::path& pathRelativeToArchive) const
105
+ inline const SFileList::SEntry * getItemFromPath (const system::path& pathRelativeToArchive) const
83
106
{
84
- const IFileArchive::SListEntry itemToFind = { pathRelativeToArchive };
85
- const auto found = std::lower_bound (m_items.begin (),m_items.end (),itemToFind);
86
- if (found==m_items.end () || found->pathRelativeToArchive !=pathRelativeToArchive)
107
+ const SFileList::SEntry itemToFind = { pathRelativeToArchive };
108
+ auto items = m_items.load ();
109
+ const auto found = std::lower_bound (items->begin (), items->end (),itemToFind);
110
+ if (found== items->end () || found->pathRelativeToArchive != pathRelativeToArchive)
87
111
return nullptr ;
88
112
return &(*found);
89
113
}
90
114
91
115
mutable std::mutex itemMutex; // TODO: update to readers writer lock
92
116
path m_defaultAbsolutePath;
93
117
// files and directories
94
- mutable core::vector<SListEntry > m_items;
118
+ mutable std::atomic<SFileList:: refctd_storage_t > m_items;
95
119
//
96
120
system::logger_opt_smart_ptr m_logger;
97
121
};
0 commit comments