ffactory.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/ffactory.h $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 9/07/01 5:30p $*
  29. * *
  30. * $Revision:: 14 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef FFACTORY_H
  39. #define FFACTORY_H
  40. #ifndef ALWAYS_H
  41. #include "always.h"
  42. #endif
  43. #include "mutex.h"
  44. #include "vector.h"
  45. #include "wwstring.h"
  46. /*
  47. **
  48. */
  49. #include "rawfile.h"
  50. class FileClass;
  51. /*
  52. ** FileFactoryClass is a pure virtual class used to
  53. ** create FileClasses.
  54. */
  55. class FileFactoryClass {
  56. public:
  57. virtual ~FileFactoryClass(void){};
  58. virtual FileClass * Get_File( char const *filename ) = 0;
  59. virtual void Return_File( FileClass *file ) = 0;
  60. };
  61. //
  62. // Handy auto pointer class. Prevents you from having to call Return_File manually
  63. //
  64. class file_auto_ptr
  65. {
  66. public:
  67. explicit file_auto_ptr(FileFactoryClass *fac, const char *filename);
  68. ~file_auto_ptr();
  69. operator FileClass*(void) const
  70. {return (get()); }
  71. FileClass& operator*() const
  72. {return (*get()); }
  73. FileClass *operator->() const
  74. {return (get()); }
  75. FileClass *get() const
  76. {return (_Ptr); }
  77. private:
  78. // prevent these from getting auto-generated or used
  79. file_auto_ptr(const file_auto_ptr &other);
  80. file_auto_ptr &operator=(const file_auto_ptr &other);
  81. FileClass *_Ptr;
  82. FileFactoryClass *_Fac;
  83. };
  84. /*
  85. ** RawFileFactoryClass is a derived FileFactoryClass which
  86. ** gives RawFileClass objects
  87. */
  88. class RawFileFactoryClass {
  89. public:
  90. RawFileClass * Get_File( char const *filename );
  91. void Return_File( FileClass *file );
  92. };
  93. #define no_SIMPLE_FILE
  94. /*
  95. ** SimpleFileFactoryClass is a slightly more capable derivative of
  96. ** FileFactoryClass which adds some simple extra functionality. It supports a
  97. ** current subdirectory, and also adds some logging capabilities. Note that
  98. ** it currently creates BufferedFileClass objects instead of RawFileClass
  99. ** objects.
  100. */
  101. class SimpleFileFactoryClass : public FileFactoryClass {
  102. public:
  103. SimpleFileFactoryClass( void );
  104. ~SimpleFileFactoryClass( void ) {}
  105. virtual FileClass * Get_File( char const *filename );
  106. virtual void Return_File( FileClass *file );
  107. // sub_directory may be a semicolon seperated search path. New files will always
  108. // go in the last dir in the path.
  109. void Get_Sub_Directory( StringClass& new_dir ) const;
  110. void Set_Sub_Directory( const char * sub_directory );
  111. void Prepend_Sub_Directory( const char * sub_directory );
  112. void Append_Sub_Directory( const char * sub_directory );
  113. bool Get_Strip_Path( void ) const { return IsStripPath; }
  114. void Set_Strip_Path( bool set ) { IsStripPath = set; }
  115. void Reset_Sub_Directory( void ) { SubDirectory = ""; }
  116. protected:
  117. StringClass SubDirectory;
  118. bool IsStripPath;
  119. // Mutex must be mutable because const functions lock on it.
  120. mutable CriticalSectionClass Mutex;
  121. };
  122. extern FileFactoryClass * _TheFileFactory;
  123. extern RawFileFactoryClass * _TheWritingFileFactory;
  124. // No simple file factory. jba.
  125. // (gth) re-enabling this because w3d view uses it
  126. extern SimpleFileFactoryClass * _TheSimpleFileFactory;
  127. #endif