cp_file_access_wrapper.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*************************************************************************/
  2. /* cp_file_access_wrapper.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef CP_FILE_ACCESS_WRAPPER_H
  31. #define CP_FILE_ACCESS_WRAPPER_H
  32. #include "cp_config.h"
  33. class CPFileAccessWrapper {
  34. public:
  35. enum ModeFlags {
  36. READ = 1,
  37. WRITE = 2,
  38. READ_WRITE = 3,
  39. };
  40. enum Error {
  41. OK,
  42. ERROR_FILE_NOT_FOUND,
  43. ERROR_FILE_BAD_DRIVE,
  44. ERROR_FILE_BAD_PATH,
  45. ERROR_FILE_NO_PERMISSION,
  46. ERROR_ALREADY_IN_USE,
  47. ERROR_INVALID_PARAMETERS,
  48. ERROR_OPENING_FILE,
  49. ERROR_READING_FILE,
  50. ERROR_WRITING_FILE
  51. };
  52. virtual Error open(const char *p_filename, int p_mode_flags) = 0;
  53. virtual void close() = 0;
  54. virtual void seek(uint32_t p_position) = 0;
  55. virtual void seek_end() = 0;
  56. virtual uint32_t get_pos() = 0;
  57. virtual bool eof_reached() = 0;
  58. virtual uint8_t get_byte() = 0;
  59. virtual void get_byte_array(uint8_t *p_dest, int p_elements) = 0;
  60. virtual void get_word_array(uint16_t *p_dest, int p_elements) = 0;
  61. virtual uint16_t get_word() = 0;
  62. virtual uint32_t get_dword() = 0;
  63. // use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  64. // It's not about the current CPU type but file formats.
  65. // this flags get reset to false (little endian) on each open
  66. virtual void set_endian_conversion(bool p_swap) = 0;
  67. virtual bool is_open() = 0;
  68. virtual Error get_error() = 0;
  69. virtual void store_byte(uint8_t p_dest) = 0;
  70. virtual void store_byte_array(const uint8_t *p_dest, int p_elements) = 0;
  71. virtual void store_word(uint16_t p_dest) = 0;
  72. virtual void store_dword(uint32_t p_dest) = 0;
  73. virtual ~CPFileAccessWrapper() {}
  74. };
  75. #endif