BUFFER.CPP 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /***************************************************************************
  15. ** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
  16. ***************************************************************************
  17. * *
  18. * Project Name : Westwood 32 Bit Library *
  19. * *
  20. * File Name : BUFFER.CPP *
  21. * *
  22. * Programmer : Phil W. Gorrow *
  23. * *
  24. * Start Date : May 18, 1994 *
  25. * *
  26. * Last Update : June 1, 1994 [PWG] *
  27. * *
  28. *-------------------------------------------------------------------------*
  29. * Functions: *
  30. * BC::BufferClass -- The default (void) constructor for a buffer class *
  31. * BC::~BufferClass -- The destructor for the buffer class *
  32. * BC::BufferClass -- The standard constructor for a buffer class *
  33. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  34. #ifndef BUFFER_H
  35. #include "buffer.h"
  36. #endif
  37. /*=========================================================================*/
  38. /* The following PRIVATE functions are in this file: */
  39. /*=========================================================================*/
  40. /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
  41. /***************************************************************************
  42. * BC::BufferClass -- The standard constructor for a buffer class *
  43. * *
  44. * INPUT: VOID * buffer to which should be included in buffer class *
  45. * LONG size of the buffer which we included *
  46. * *
  47. * OUTPUT: NONE *
  48. * *
  49. * WARNINGS: If the buffer passed to this function is equal to NULL, *
  50. * the buffer will be allocated using new. *
  51. * *
  52. * HISTORY: *
  53. * 06/01/1994 PWG : Created. *
  54. *=========================================================================*/
  55. BufferClass::BufferClass(VOID *buffer, LONG size)
  56. {
  57. Size = size; // find size of physical buffer
  58. if (buffer) { // if buffer is specified
  59. Buffer = (BYTE *)buffer; // point to it and mark
  60. Allocated = FALSE; // it as user allocated
  61. } else {
  62. Buffer = new BYTE[Size]; // otherwise allocate it and
  63. Allocated = TRUE; // mark it system alloced
  64. }
  65. }
  66. /***************************************************************************
  67. * BC::BufferClass -- constructor for BufferClass with size only *
  68. * *
  69. * INPUT: LONG the size of the buffer that needs to be allocated *
  70. * *
  71. * OUTPUT: none *
  72. * *
  73. * HISTORY: *
  74. * 06/01/1994 PWG : Created. *
  75. *=========================================================================*/
  76. BufferClass::BufferClass(LONG size)
  77. {
  78. Size = size;
  79. Buffer = new BYTE[Size]; // otherwise allocate it and
  80. Allocated = TRUE; // mark it system alloced
  81. }
  82. /***************************************************************************
  83. * BC::BufferClass -- The default (void) constructor for a buffer class *
  84. * *
  85. * INPUT: none *
  86. * *
  87. * OUTPUT: none *
  88. * *
  89. * NOTES: The primary function of this class is to be called by a *
  90. * derived class which will fill in the values after the *
  91. * fact. *
  92. * *
  93. * HISTORY: *
  94. * 06/01/1994 PWG : Created. *
  95. *=========================================================================*/
  96. BufferClass::BufferClass(VOID)
  97. {
  98. Buffer = NULL;
  99. Size = 0;
  100. Allocated = FALSE;
  101. }
  102. /***************************************************************************
  103. * BC::~BUFFERCLASS -- The destructor for the buffer class *
  104. * *
  105. * INPUT: none *
  106. * *
  107. * OUTPUT: none *
  108. * *
  109. * HISTORY: *
  110. * 06/01/1994 PWG : Created. *
  111. *=========================================================================*/
  112. BufferClass::~BufferClass(VOID)
  113. {
  114. if (Allocated) {
  115. delete[] Buffer;
  116. }
  117. }