ffactory.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. ** Command & Conquer Renegade(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. class FileClass;
  50. /*
  51. ** FileFactoryClass is a pure virtual class used to
  52. ** create FileClasses.
  53. */
  54. class FileFactoryClass {
  55. public:
  56. virtual ~FileFactoryClass(void){};
  57. virtual FileClass * Get_File( char const *filename ) = 0;
  58. virtual void Return_File( FileClass *file ) = 0;
  59. };
  60. //
  61. // Handy auto pointer class. Prevents you from having to call Return_File manually
  62. //
  63. class file_auto_ptr
  64. {
  65. public:
  66. explicit file_auto_ptr(FileFactoryClass *fac, const char *filename);
  67. ~file_auto_ptr();
  68. operator FileClass*(void) const
  69. {return (get()); }
  70. FileClass& operator*() const
  71. {return (*get()); }
  72. FileClass *operator->() const
  73. {return (get()); }
  74. FileClass *get() const
  75. {return (_Ptr); }
  76. private:
  77. // prevent these from getting auto-generated or used
  78. file_auto_ptr(const file_auto_ptr &other);
  79. file_auto_ptr &operator=(const file_auto_ptr &other);
  80. FileClass *_Ptr;
  81. FileFactoryClass *_Fac;
  82. };
  83. /*
  84. ** RawFileFactoryClass is a derived FileFactoryClass which
  85. ** gives RawFileClass objects
  86. */
  87. class RawFileFactoryClass : public FileFactoryClass {
  88. public:
  89. virtual FileClass * Get_File( char const *filename );
  90. virtual void Return_File( FileClass *file );
  91. };
  92. /*
  93. ** SimpleFileFactoryClass is a slightly more capable derivative of
  94. ** FileFactoryClass which adds some simple extra functionality. It supports a
  95. ** current subdirectory, and also adds some logging capabilities. Note that
  96. ** it currently creates BufferedFileClass objects instead of RawFileClass
  97. ** objects.
  98. */
  99. class SimpleFileFactoryClass : public FileFactoryClass {
  100. public:
  101. SimpleFileFactoryClass( void );
  102. ~SimpleFileFactoryClass( void ) {}
  103. virtual FileClass * Get_File( char const *filename );
  104. virtual void Return_File( FileClass *file );
  105. // sub_directory may be a semicolon seperated search path. New files will always
  106. // go in the last dir in the path.
  107. void Get_Sub_Directory( StringClass& new_dir ) const;
  108. void Set_Sub_Directory( const char * sub_directory );
  109. void Prepend_Sub_Directory( const char * sub_directory );
  110. void Append_Sub_Directory( const char * sub_directory );
  111. bool Get_Strip_Path( void ) const { return IsStripPath; }
  112. void Set_Strip_Path( bool set ) { IsStripPath = set; }
  113. protected:
  114. StringClass SubDirectory;
  115. bool IsStripPath;
  116. // Mutex must be mutable because const functions lock on it.
  117. mutable CriticalSectionClass Mutex;
  118. };
  119. /*
  120. ** TheFileFactory is a static pointer to the single file factory (only one
  121. ** should be inexistence at any one time). TheSimpleFileFactory is a
  122. ** differently typed pointer to the same entity for those cases where the
  123. ** extra interface functions are needed (TheFileFactory is created as an
  124. ** object of type SimpleFileFactoryClass by default. If this changes to some
  125. ** other class which is not a derivative of SimpleFileFactoryClass then
  126. ** TheSimpleFileFactory should be set to NULL).
  127. */
  128. extern FileFactoryClass * _TheFileFactory;
  129. extern FileFactoryClass * _TheWritingFileFactory;
  130. extern SimpleFileFactoryClass * _TheSimpleFileFactory;
  131. #endif