Archive.hpp
Go to the documentation of this file.
1 
6 #ifdef ETK_BUILD_MINIZIP
7 
8 #include <etk/types.hpp>
9 
10 #pragma once
11 
12 #include <map>
13 #include <mutex>
14 #include <ememory/memory.hpp>
15 
16 namespace etk {
21  private:
22  int32_t m_link;
23  public:
27  void increaseRef() {
28  m_link++;
29  }
33  void decreaseRef() {
34  m_link--;
35  }
40  int32_t getNumberOfRef() const {
41  return m_link;
42  }
43  private:
44  int32_t m_theoricSize;
45  public:
50  int32_t getTheoricSize() const {
51  return m_theoricSize;
52  }
53  private:
54  std::vector<char> m_data;
55  public:
60  ArchiveContent(int32_t _basicSize=0) :
61  m_link(-1),
62  m_theoricSize(_basicSize) {
63 
64  }
69  int32_t size() const {
70  return m_data.size();
71  }
76  void* data() const {
77  return (void*)&m_data[0];
78  }
83  std::vector<char>& getDataVector() {
84  return m_data;
85  }
86  };
90  class Archive {
91  private:
92  mutable std::mutex m_mutex;
93  public:
98  Archive(const std::string& _fileName) :
99  m_fileName(_fileName) {
100 
101  };
105  virtual ~Archive() = default;
106  protected:
107  std::string m_fileName;
108  public:
113  const std::string& getFileName() {
114  return m_fileName;
115  };
116  protected:
117  std::map<std::string, ArchiveContent> m_content;
118  public:
123  int32_t size() const {
124  return m_content.size();
125  };
131  const std::string& getName(size_t _id) const;
137  const ArchiveContent& getContent(size_t _id) const;
143  const ArchiveContent& getContent(const std::string& _key) const;
149  bool exist(const std::string& _key) const;
154  void open(const std::string& _key);
159  void close(const std::string& _key);
163  void display();
164  protected:
169  virtual void loadFile(const std::map<std::string, ArchiveContent>::iterator& _it) { };
170  public:
176  static Archive* load(const std::string& _fileName);
182  static Archive* loadPackage(const std::string& _fileName);
183  };
184 }
185 #endif
void increaseRef()
Increment the number of user of this resource (permit to keep data alive)
Definition: Archive.hpp:27
Element of the archive (with associated data)
Definition: Archive.hpp:20
ArchiveContent(int32_t _basicSize=0)
Basic constructor of an element.
Definition: Archive.hpp:60
virtual void loadFile(const std::map< std::string, ArchiveContent >::iterator &_it)
Request the load in memory of the concerned file.
Definition: Archive.hpp:169
std::vector< char > & getDataVector()
Get the Data Vector on the file.
Definition: Archive.hpp:83
int32_t getTheoricSize() const
Get the size of the element (size set by Zip file (not read))
Definition: Archive.hpp:50
basic namespace of the etk library. (it might contain all the etk fuctions/class/structures without m...
Definition: Archive.hpp:16
Archive(const std::string &_fileName)
Contructor of the archive element.
Definition: Archive.hpp:98
int32_t size() const
Get the number of elements.
Definition: Archive.hpp:123
std::map< std::string, ArchiveContent > m_content
list of element of the zip file
Definition: Archive.hpp:115
Access on a zip data file.
Definition: Archive.hpp:90
const std::string & getFileName()
Get the current file name.
Definition: Archive.hpp:113
void decreaseRef()
Release reference on this data.
Definition: Archive.hpp:33
int32_t size() const
Get the size of the Data loaded.
Definition: Archive.hpp:69
int32_t getNumberOfRef() const
Get the number of user link with this reference.
Definition: Archive.hpp:40
std::string m_fileName
File name when it came from an file.
Definition: Archive.hpp:107
void * data() const
Get the pointer on the data read from the zip file.
Definition: Archive.hpp:76