FsBase.h
Go to the documentation of this file.
1 
21 #pragma once
22 
23 #include "FileSystem.h"
24 
25 namespace IFS
26 {
27 class FsBase
28 {
29 public:
30  FsBase(IFileSystem* filesys) : fileSystem(filesys)
31  {
32  }
33 
38  {
39  return lastError;
40  }
41 
42  String getErrorString(int err) const
43  {
44  return fileSystem == nullptr ? Error::toString(err) : fileSystem->getErrorString(err);
45  }
46 
48  {
49  return getErrorString(lastError);
50  }
51 
53  {
54  if(fileSystem == nullptr) {
55  lastError = Error::NoFileSystem;
56  }
57  return static_cast<FileSystem*>(fileSystem);
58  }
59 
60 protected:
65  bool check(int res)
66  {
67  if(res >= 0) {
68  return true;
69  }
70 
71  lastError = res;
72  return false;
73  }
74 
75 protected:
76  mutable int lastError{FS_OK};
77 
78 private:
79  IFileSystem* fileSystem;
80 };
81 
82 } // namespace IFS
FsBase(IFileSystem *filesys)
Definition: FsBase.h:30
String getLastErrorString() const
Definition: FsBase.h:47
Installable File System base class.
Definition: IFileSystem.h:100
bool check(int res)
Check file operation result and note error code.
Definition: FsBase.h:65
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:42
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:37
Definition: FsBase.h:27
FileSystem * getFileSystem() const
Definition: FsBase.h:52
constexpr ErrorCode FS_OK
Definition: Error.h:130
int lastError
Definition: FsBase.h:76
virtual String getErrorString(int err)
get the text for a returned error code
Definition: IFileSystem.h:184