Guest User

Untitled

a guest
Aug 7th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. enum class Mode : int{
  2.     NO=0, //Nothing
  3.     NOB, //Nothing, binary
  4.     RO, //Read-only
  5.     ROB, //Read-only binary
  6.     WO, //Write-only
  7.     WOB, //Write-only binary
  8.     RW, //Read-write
  9.     RWB, //Read-write binary
  10.     EXE  //load program
  11. };
  12. enum /*throwable*/ class FError : int {
  13.     SUCCESS=0,
  14.     NO_SUCH_FILE,
  15.     NO_PERMISSIONS,
  16.     STILL_OPEN,
  17.     WRITE_PROTECTED,
  18.     READ_PROTECTED,
  19.     NOT_EXECUTABLE,
  20.     NO_SUCH_DEVICE,
  21.     UNKNOWN,
  22.     WRONG_ARCH,
  23.     BUG_REPORT_PLS,
  24.     MOD_UNLOADED,
  25.     NO_COLOR
  26. };
  27. class File;
  28. class Directory;
  29. class FS {
  30.     friend class File;
  31.     friend class Directory;
  32.     protected:
  33.         Block dev;
  34.         vector<File> openFiles;
  35.     public:
  36.         auto open(String &fname, Mode mode) -> File &;
  37.         //Files are closed when deconstructed
  38.         auto enter(String &dname) -> Directory &;
  39.         auto create(String &fname) -> File &; //Created files are already opened RW
  40.         auto delete(String &fname) -> bool;
  41.         auto deleteDir(String &dname) -> bool;
  42. };
  43. class File {
  44.     private:
  45.         String fname;
  46.         fsize_t size;
  47.         fsize_t woff;
  48.         fsize_t roff;
  49.         friend class FS;
  50.         Mode mode;
  51.         File() {}
  52.         File(String &name, Mode mode);
  53.     public:
  54.         auto read(fsize_t len, void *buf) -> fsize_t;
  55.         auto write(fsize_t len, void *buf) -> fsize_t;
  56.         template<typename T>
  57.         auto operator>>(T& obj) -> File & {
  58.             read(sizeof(T), (void*)&obj);
  59.             return *this;
  60.         }
  61.         template<typename T>
  62.         auto operator<<(T& obj) -> File & {
  63.             write(sizeof(T), (void*)&obj);
  64.             return *this;
  65.         }
  66.         auto getSize() -> fsize_t;
  67.         auto seek(fsize_t sval) -> File &; //From beginning
  68.         auto seek(foff_t off) -> File&; //Relative
  69.         //And more?
  70.         ~File();
  71. };
  72. class Directory:public Vector<File> {
  73.     //Todo
  74. };
Advertisement
Add Comment
Please, Sign In to add comment