FsBase.h
Go to the documentation of this file.
1 
21 #pragma once
22 
23 #include "FileSystem.h"
24 
25 namespace IFS
26 {
27 #define GET_FS(failure) \
28  auto fs = getFileSystem(); \
29  if(fs == nullptr) { \
30  return failure; \
31  }
32 
33 class FsBase
34 {
35 public:
36  FsBase(IFileSystem* filesys) : fileSystem(FileSystem::cast(filesys))
37  {
38  }
39 
40  bool isValid() const
41  {
42  return fileSystem != nullptr;
43  }
44 
49  {
50  return lastError;
51  }
52 
53  String getErrorString(int err) const
54  {
55  return fileSystem == nullptr ? Error::toString(err) : fileSystem->getErrorString(err);
56  }
57 
59  {
60  return getErrorString(lastError);
61  }
62 
64  {
65  if(fileSystem == nullptr) {
66  lastError = Error::NoFileSystem;
67  }
68  return fileSystem;
69  }
70 
71 protected:
76  bool check(int res)
77  {
78  if(res >= 0) {
79  return true;
80  }
81 
82  lastError = res;
83  return false;
84  }
85 
86 protected:
87  mutable int lastError{FS_OK};
88 
89 private:
90  FileSystem* fileSystem;
91 };
92 
93 } // namespace IFS
FsBase(IFileSystem *filesys)
Definition: FsBase.h:36
String getLastErrorString() const
Definition: FsBase.h:58
Installable File System base class.
Definition: IFileSystem.h:95
bool check(int res)
Check file operation result and note error code.
Definition: FsBase.h:76
The String class.
Definition: WString.h:136
Installable File System base class.
Definition: Components/IFS/src/include/IFS/FileSystem.h:39
String getErrorString(int err) const
Definition: FsBase.h:53
bool isValid() const
Definition: FsBase.h:40
String toString(int err)
get text for an error code
Definition: DirectoryTemplate.h:36
int getLastError()
determine if an error occurred during operation
Definition: FsBase.h:48
Definition: FsBase.h:33
FileSystem * getFileSystem() const
Definition: FsBase.h:63
constexpr ErrorCode FS_OK
Definition: Error.h:128
int lastError
Definition: FsBase.h:87
virtual String getErrorString(int err)
get the text for a returned error code
Definition: IFileSystem.h:208