filesystem.h (2302B)
1 // 2 // filesystem.h 3 // Smalltalk-80 4 // 5 // Created by Dan Banay on 5/3/20. 6 // Copyright © 2020 Dan Banay. All rights reserved. 7 // 8 // MIT License 9 // Permission is hereby granted, free of charge, to any person obtaining a copy 10 // of this software and associated documentation files (the "Software"), to deal 11 // in the Software without restriction, including without limitation the rights 12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 // copies of the Software, and to permit persons to whom the Software is 14 // furnished to do so, subject to the following conditions: 15 // 16 // The above copyright notice and this permission notice shall be included in all 17 // copies or substantial portions of the Software. 18 // 19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 // SOFTWARE. 26 // 27 28 29 #pragma once 30 #include <functional> 31 #include <cstdint> 32 33 class IFileSystem 34 { 35 public: 36 // File oriented operations 37 virtual int create_file(const char *name) = 0; 38 virtual int open_file(const char *name) = 0; 39 virtual int close_file(int file_handle) = 0; 40 41 virtual int seek_to(int file_handle, int position) = 0; 42 virtual int tell(int file_handle) = 0; 43 virtual int read(int file_handle, char *buffer, int bytes) = 0; 44 virtual int write(int file_handle, const char *buffer, int bytes) = 0; 45 46 47 virtual bool truncate_to(int file_handle, int length) = 0; 48 virtual int file_size(int file_handle) = 0; 49 virtual bool file_flush(int file_handle) = 0; 50 51 // Directory orientated operations 52 virtual void enumerate_files(const std::function <void (const char *) >& each) = 0; 53 54 virtual bool rename_file(const char *old_name, const char *new_name) = 0; 55 virtual bool delete_file(const char* file_name) = 0; 56 57 // Error handling 58 virtual const int last_error() = 0; 59 virtual const char *error_text(int code) = 0; 60 }; 61 62