Oxygine  1
2g game engine
file.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include <vector>
4 #include "Object.h"
5 #include "FileSystem.h"
6 #include <string>
7 
8 namespace oxygine
9 {
10  namespace file
11  {
12  class STDFileSystem;
13 
14 
15  typedef file::fileHandle* handle;
16 
18  class buffer
19  {
20  public:
21  typedef unsigned char uchar;
22 
23  uchar& front() { return data.front(); }
24  const uchar& front() const { return data.front(); }
25 
26  uchar& back() { return data.back(); }
27  const uchar& back() const { return data.back(); }
28 
29  uchar& operator[](size_t i) { return data[i]; }
30  const uchar& operator[](size_t i) const { return data[i]; }
31 
32  uchar& at(size_t i) { return data.at(i); }
33  const uchar& at(size_t i) const { return data.at(i); }
34 
35  void push_back(uchar v) { return data.push_back(v); }
36  uchar pop_back() { uchar v = data.back(); data.pop_back(); return v; }
37  void reserve(size_t v) { data.reserve(v); }
38  void resize(size_t v) { data.resize(v); }
39 
40  size_t size() const { return data.size(); }
41  bool empty() const { return data.empty(); }
42 
43  const void* getData() const {if (data.empty()) return 0; return &data[0];}
44  void* getData() { if (data.empty()) return 0; return &data[0]; }
45  unsigned int getSize() const {return (unsigned int)data.size();}
46 
47  std::string getString() const {return std::string((char*)&data[0], size());}
48 
49  typedef std::vector<uchar> buff;
50  buff data;
51  };
52 
54  handle open(const std::string& file, const char* mode, error_policy ep = ep_show_error);
55 
57  void close(handle);
58 
60  int seek(handle, unsigned int offset, int whence);
61 
63  unsigned int tell(handle);
64 
66  unsigned int read(handle, void* dest, unsigned int size);
67 
69  bool read(const std::string& file, buffer& dest, error_policy ep = ep_show_error);
70 
72  unsigned int read(handle, buffer& dest);
73 
75  unsigned int write(handle, const void* data, unsigned int size);
76 
78  unsigned int write(const std::string& file, const buffer& data, error_policy ep = ep_show_error);
79  unsigned int write(const std::string& file, const void* data, unsigned int size, error_policy ep = ep_show_error);
80 
82  bool exists(const std::string& file);
83 
85  unsigned int size(handle);
86 
88  bool deleteFile(const std::string& path, error_policy ep = ep_show_warning);
89 
91  bool rename(const std::string& src, const std::string& dest, error_policy ep = ep_show_warning);
92 
94  bool makeDirectory(const std::string& path);
95  void makeDirectories(const std::string& path);
96 
98  void deleteDirectory(const std::string& path);
99 
101  file::STDFileSystem& fs();
102 
104  file::STDFileSystem& wfs();
105 
107  void mount(FileSystem* fs);
108 
110  void unmount(FileSystem* fs);
111 
112  class autoClose
113  {
114  public:
115  autoClose(handle h): _handle(h) {}
116  ~autoClose() {if (_handle) close(_handle);}
117 
118  handle getHandle() const {return _handle;}
119 
120  private:
121  //non copyable
122  autoClose(const autoClose&);
123  const autoClose& operator=(const autoClose&);
124 
125  handle _handle;
126  };
127 
128 
129 
131  void init(const char* company, const char* app);
132 
134  void free();
135  }
136 }
Definition: FileSystem.h:12
Definition: file.h:112
–oxgl-end–!
Definition: Actor.h:14
Definition: file.h:18
Definition: STDFileSystem.h:8
Definition: FileSystem.h:27