RAMFile.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. //----------------------------------------------------------------------------=
  24. //
  25. // Westwood Studios Pacific.
  26. //
  27. // Confidential Information
  28. // Copyright(C) 2001 - All Rights Reserved
  29. //
  30. //----------------------------------------------------------------------------
  31. //
  32. // Project: WSYS Library
  33. //
  34. // Module: IO
  35. //
  36. // File name: wsys/RAMFile.h
  37. //
  38. // Created: 11/08/01
  39. //
  40. //----------------------------------------------------------------------------
  41. #pragma once
  42. #ifndef __RAMFILE_H
  43. #define __RAMFILE_H
  44. //----------------------------------------------------------------------------
  45. // Includes
  46. //----------------------------------------------------------------------------
  47. #include "Common/File.h"
  48. //----------------------------------------------------------------------------
  49. // Forward References
  50. //----------------------------------------------------------------------------
  51. //----------------------------------------------------------------------------
  52. // Type Defines
  53. //----------------------------------------------------------------------------
  54. //===============================
  55. // RAMFile
  56. //===============================
  57. /**
  58. * File abstraction for standard C file operators: open, close, lseek, read, write
  59. */
  60. //===============================
  61. class RAMFile : public File
  62. {
  63. MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(RAMFile, "RAMFile")
  64. protected:
  65. Char *m_data; ///< File data in memory
  66. Int m_pos; ///< current read position
  67. Int m_size; ///< size of file in memory
  68. public:
  69. RAMFile();
  70. //virtual ~RAMFile();
  71. virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access
  72. virtual void close( void ); ///< Close the file
  73. virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read
  74. virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write
  75. virtual Int seek( Int new_pos, seekMode mode = CURRENT ); ///< Set file position: See File::seek
  76. virtual void nextLine(Char *buf = NULL, Int bufSize = 0); ///< moves current position to after the next new-line
  77. virtual Bool scanInt(Int &newInt); ///< return what gets read as an integer from the current memory position.
  78. virtual Bool scanReal(Real &newReal); ///< return what gets read as a float from the current memory position.
  79. virtual Bool scanString(AsciiString &newString); ///< return what gets read as a string from the current memory position.
  80. virtual Bool open( File *file ); ///< Open file for fast RAM access
  81. virtual Bool openFromArchive(File *archiveFile, const AsciiString& filename, Int offset, Int size); ///< copy file data from the given file at the given offset for the given size.
  82. virtual Bool copyDataToFile(File *localFile); ///< write the contents of the RAM file to the given local file. This could be REALLY slow.
  83. /**
  84. Allocate a buffer large enough to hold entire file, read
  85. the entire file into the buffer, then close the file.
  86. the buffer is owned by the caller, who is responsible
  87. for freeing is (via delete[]). This is a Good Thing to
  88. use because it minimizes memory copies for BIG files.
  89. */
  90. virtual char* readEntireAndClose();
  91. virtual File* convertToRAMFile();
  92. };
  93. //----------------------------------------------------------------------------
  94. // Inlining
  95. //----------------------------------------------------------------------------
  96. #endif // __WSYS_RAMFILE_H