CSTRAW.CPP 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/CSTRAW.CPP 1 3/03/97 10:24a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** 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 ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : CSTRAW.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 11/10/96 *
  30. * *
  31. * Last Update : November 10, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * CacheStraw::Get -- Fetch data from the data source. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "cstraw.h"
  38. #include <string.h>
  39. /***********************************************************************************************
  40. * CacheStraw::Get -- Fetch data from the data source. *
  41. * *
  42. * This will supply the data quantity requested. It performs a regulating influence on the *
  43. * data requests passed through it. The data is requested from the next straw in the *
  44. * chain such that the data stream is requested in chunks. This serves to lessen the *
  45. * impact of multiple small data requests. *
  46. * *
  47. * INPUT: source -- Pointer to the buffer to hold the data. *
  48. * *
  49. * slen -- The number of data bytes requested. *
  50. * *
  51. * OUTPUT: Returns with the number of data bytes stored into the buffer specified. If this *
  52. * number is less than that requested, it indicates that the data source has been *
  53. * exhausted. *
  54. * *
  55. * WARNINGS: none *
  56. * *
  57. * HISTORY: *
  58. * 11/10/1996 JLB : Created. *
  59. *=============================================================================================*/
  60. int CacheStraw::Get(void * source, int slen)
  61. {
  62. int total = 0;
  63. if (Is_Valid() && source != NULL && slen > 0) {
  64. /*
  65. ** Keep processing the data request until there is no more data to supply or the request
  66. ** has been fulfilled.
  67. */
  68. while (slen > 0) {
  69. /*
  70. ** First try to fetch the data from data previously loaded into the buffer.
  71. */
  72. if (Length > 0) {
  73. int tocopy = (Length < slen) ? Length : slen;
  74. memmove(source, ((char *)BufferPtr.Get_Buffer()) + Index, tocopy);
  75. slen -= tocopy;
  76. Index += tocopy;
  77. total += tocopy;
  78. Length -= tocopy;
  79. source = (char*)source + tocopy;
  80. }
  81. if (slen == 0) break;
  82. /*
  83. ** Since there is more to be fulfilled yet the holding buffer is empty,
  84. ** refill the buffer with a fresh block of data from the source.
  85. */
  86. Length = Straw::Get(BufferPtr, BufferPtr.Get_Size());
  87. Index = 0;
  88. if (Length == 0) break;
  89. }
  90. }
  91. return(total);
  92. }