libadblockplus
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
IFileSystem.h
1 /*
2  * This file is part of Adblock Plus <https://adblockplus.org/>,
3  * Copyright (C) 2006-present eyeo GmbH
4  *
5  * Adblock Plus is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 3 as
7  * published by the Free Software Foundation.
8  *
9  * Adblock Plus is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef ADBLOCK_PLUS_IFILE_SYSTEM_H
19 #define ADBLOCK_PLUS_IFILE_SYSTEM_H
20 
21 #include <istream>
22 #include <cstdint>
23 #include <string>
24 #include <memory>
25 #include <vector>
26 #include <functional>
27 
28 namespace AdblockPlus
29 {
34  {
35  public:
39  struct StatResult
40  {
41  StatResult()
42  {
43  exists = false;
44  lastModified = 0;
45  }
46 
50  bool exists;
51 
55  int64_t lastModified;
56  };
57 
58  virtual ~IFileSystem() {}
59 
61  typedef std::vector<uint8_t> IOBuffer;
62 
67  typedef std::function<void(const std::string&)> Callback;
68 
73  typedef std::function<void(IOBuffer&&)> ReadCallback;
74 
83  virtual void Read(const std::string& fileName,
84  const ReadCallback& doneCallback,
85  const Callback& errorCallback) const = 0;
86 
93  virtual void Write(const std::string& fileName,
94  const IOBuffer& data,
95  const Callback& callback) = 0;
96 
103  virtual void Move(const std::string& fromFileName, const std::string& toFileName,
104  const Callback& callback) = 0;
105 
111  virtual void Remove(const std::string& fileName, const Callback& callback) = 0;
112 
118  typedef std::function<void(const StatResult&, const std::string&)> StatCallback;
119 
125  virtual void Stat(const std::string& fileName,
126  const StatCallback& callback) const = 0;
127  };
128 
132  typedef std::unique_ptr<IFileSystem> FileSystemPtr;
133 }
134 
135 #endif
bool exists
File exists.
Definition: IFileSystem.h:50
std::function< void(const std::string &)> Callback
Default callback type for asynchronous filesystem calls.
Definition: IFileSystem.h:67
std::function< void(const StatResult &, const std::string &)> StatCallback
Callback type for the asynchronous Stat call.
Definition: IFileSystem.h:118
virtual void Move(const std::string &fromFileName, const std::string &toFileName, const Callback &callback)=0
Moves a file (i.e. renames it).
int64_t lastModified
POSIX time of the last modification.
Definition: IFileSystem.h:55
File system interface.
Definition: IFileSystem.h:33
Main namespace of libadblockplus.
Definition: ActiveObject.h:23
virtual void Remove(const std::string &fileName, const Callback &callback)=0
Removes a file.
virtual void Stat(const std::string &fileName, const StatCallback &callback) const =0
Retrieves information about a file.
Result of a stat operation, i.e. information about a file.
Definition: IFileSystem.h:39
std::unique_ptr< IFileSystem > FileSystemPtr
Unique smart pointer to to a IFileSystem instance.
Definition: IFileSystem.h:132
virtual void Read(const std::string &fileName, const ReadCallback &doneCallback, const Callback &errorCallback) const =0
Reads from a file.
std::vector< uint8_t > IOBuffer
Type for the buffer used for IO.
Definition: IFileSystem.h:61
std::function< void(IOBuffer &&)> ReadCallback
Callback type for the asynchronous Read call.
Definition: IFileSystem.h:73
virtual void Write(const std::string &fileName, const IOBuffer &data, const Callback &callback)=0
Writes to a file.