Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
zipassetmanager.h
Go to the documentation of this file.
1 
18 #ifndef ION_BASE_ZIPASSETMANAGER_H_
19 #define ION_BASE_ZIPASSETMANAGER_H_
20 
21 #include <chrono> // NOLINT
22 #include <map>
23 #include <memory>
24 #include <set>
25 #include <string>
26 #include <vector>
27 
28 #include "base/macros.h"
29 #include "ion/port/mutex.h"
30 
31 namespace ion {
32 namespace base {
33 
42 class ION_API ZipAssetManager {
43  public:
46  ~ZipAssetManager();
47 
56  static bool RegisterAssetData(const void* data, size_t data_size);
57 
59  static bool ContainsFile(const std::string& filename);
60 
64  static bool IsFileCached(const std::string& filename);
65 
67  static std::vector<std::string> GetRegisteredFileNames();
68 
73  static std::shared_ptr<const std::string> GetFileDataPtr(
74  const std::string& filename);
79  static const std::string& GetFileData(const std::string& filename);
83  static bool GetFileDataNoCache(const std::string& filename, std::string* out);
84 
91  static bool UpdateFileIfChanged(
92  const std::string& filename,
93  std::chrono::system_clock::time_point* timestamp);
94 
99  static bool SetFileData(const std::string& filename,
100  const std::string& source);
101 
108  static bool SaveFileData(const std::string& filename);
109 
112  static void Reset();
113 
114  private:
117  struct FileInfo {
120  void* zip_handle;
122  std::chrono::system_clock::time_point timestamp;
125  std::shared_ptr<std::string> data_ptr;
127  std::string original_name;
128  };
129  typedef std::map<std::string, FileInfo> FileCache;
130 
132  ZipAssetManager();
133 
139  const std::string& GetFileDataLocked(const std::string& filename,
140  std::string* out);
141 
144  bool ContainsFileLocked(const std::string& filename);
145 
147  static ZipAssetManager* GetManager();
148 
151  static bool FileIsCached(const FileInfo& info);
152 
154  FileCache file_cache_;
156  std::set<void*> zipfiles_;
157 
160 
161  DISALLOW_COPY_AND_ASSIGN(ZipAssetManager);
162 };
163 
164 } // namespace base
165 } // namespace ion
166 
167 #endif // ION_BASE_ZIPASSETMANAGER_H_
ZipAssetManager manages all zipfile assets in Ion.
port::Mutex mutex_
Protects shared access to the Allocator and FT_Library.
A Mutex is used to ensure that only one thread or process can access a block of code at one time...
Definition: mutex.h:34