LocalFile.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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: LocalFile.h
  37. //
  38. // Created: 4/23/01
  39. //
  40. //----------------------------------------------------------------------------
  41. #pragma once
  42. #ifndef __LOCALFILE_H
  43. #define __LOCALFILE_H
  44. //----------------------------------------------------------------------------
  45. // Includes
  46. //----------------------------------------------------------------------------
  47. #include "Common/File.h"
  48. // srj sez: this was purely an experiment in optimization.
  49. // at the present time, it doesn't appear to be a good one.
  50. // but I am leaving the code in for now.
  51. // if still present in 2003, please nuke.
  52. #define NO_USE_BUFFERED_IO
  53. #ifdef USE_BUFFERED_IO
  54. #include <stdio.h>
  55. #endif
  56. //----------------------------------------------------------------------------
  57. // Forward References
  58. //----------------------------------------------------------------------------
  59. //----------------------------------------------------------------------------
  60. // Type Defines
  61. //----------------------------------------------------------------------------
  62. //===============================
  63. // LocalFile
  64. //===============================
  65. /**
  66. * File abstraction for standard C file operators: open, close, lseek, read, write
  67. */
  68. //===============================
  69. class LocalFile : public File
  70. {
  71. MEMORY_POOL_GLUE_ABC(LocalFile)
  72. private:
  73. #ifdef USE_BUFFERED_IO
  74. FILE* m_file;
  75. enum { BUF_SIZE = 32768 };
  76. char m_vbuf[BUF_SIZE];
  77. #else
  78. int m_handle; ///< Local C file handle
  79. #endif
  80. public:
  81. LocalFile();
  82. //virtual ~LocalFile();
  83. virtual Bool open( const Char *filename, Int access = 0 ); ///< Open a file for access
  84. virtual void close( void ); ///< Close the file
  85. virtual Int read( void *buffer, Int bytes ); ///< Read the specified number of bytes in to buffer: See File::read
  86. virtual Int write( const void *buffer, Int bytes ); ///< Write the specified number of bytes from the buffer: See File::write
  87. virtual Int seek( Int new_pos, seekMode mode = CURRENT ); ///< Set file position: See File::seek
  88. virtual void nextLine(Char *buf = NULL, Int bufSize = 0); ///< moves file position to after the next new-line
  89. virtual Bool scanInt(Int &newInt); ///< return what gets read in as an integer at the current file position.
  90. virtual Bool scanReal(Real &newReal); ///< return what gets read in as a float at the current file position.
  91. virtual Bool scanString(AsciiString &newString); ///< return what gets read in as a string at the current file position.
  92. /**
  93. Allocate a buffer large enough to hold entire file, read
  94. the entire file into the buffer, then close the file.
  95. the buffer is owned by the caller, who is responsible
  96. for freeing is (via delete[]). This is a Good Thing to
  97. use because it minimizes memory copies for BIG files.
  98. */
  99. virtual char* readEntireAndClose();
  100. virtual File* convertToRAMFile();
  101. };
  102. //----------------------------------------------------------------------------
  103. // Inlining
  104. //----------------------------------------------------------------------------
  105. #endif // __LOCALFILE_H