straw.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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:: /G/wwlib/STRAW.CPP $*
  25. * *
  26. * $Author:: Eric_c $*
  27. * *
  28. * $Modtime:: 4/15/99 10:16a $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * Straw::Get_From -- Connect one straw segment to another. *
  35. * Straw::Get -- Fetch some data from the straw chain. *
  36. * Straw::~Straw -- Destructor for a straw segment. *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "always.h"
  39. #include "straw.h"
  40. #include <stddef.h>
  41. //#include <string.h>
  42. /***********************************************************************************************
  43. * Straw::~Straw -- Destructor for a straw segment. *
  44. * *
  45. * This destructor will remove this segment from the straw chain. If there were any *
  46. * connected segments to either side, they will be joined so that the straw chain will *
  47. * still remain linked. *
  48. * *
  49. * INPUT: none *
  50. * *
  51. * OUTPUT: none *
  52. * *
  53. * WARNINGS: none *
  54. * *
  55. * HISTORY: *
  56. * 07/03/1996 JLB : Created. *
  57. *=============================================================================================*/
  58. Straw::~Straw(void)
  59. {
  60. if (ChainTo != NULL) {
  61. ChainTo->ChainFrom = ChainFrom;
  62. }
  63. if (ChainFrom != NULL) {
  64. ChainFrom->Get_From(ChainTo);
  65. }
  66. ChainFrom = NULL;
  67. ChainTo = NULL;
  68. }
  69. /***********************************************************************************************
  70. * Straw::Get_From -- Connect one straw segment to another. *
  71. * *
  72. * Use this routine to connect straw segments together. The straw segment specified as the *
  73. * parameter will be linked to the chain such that when data is requested, it will be *
  74. * fetched from the specified link before being processed by this link. *
  75. * *
  76. * INPUT: straw -- Pointer to the straw segment that data will be fetched from. *
  77. * *
  78. * OUTPUT: none *
  79. * *
  80. * WARNINGS: none *
  81. * *
  82. * HISTORY: *
  83. * 07/03/1996 JLB : Created. *
  84. *=============================================================================================*/
  85. void Straw::Get_From(Straw * straw)
  86. {
  87. if (ChainTo != straw) {
  88. if (straw != NULL && straw->ChainFrom != NULL) {
  89. straw->ChainFrom->Get_From(NULL);
  90. straw->ChainFrom = NULL;
  91. }
  92. if (ChainTo != NULL) {
  93. ChainTo->ChainFrom = NULL;
  94. }
  95. ChainTo = straw;
  96. if (ChainTo != NULL) {
  97. ChainTo->ChainFrom = this;
  98. }
  99. }
  100. }
  101. /***********************************************************************************************
  102. * Straw::Get -- Fetch some data from the straw chain. *
  103. * *
  104. * Use this routine to fetch some data from the straw. It is presumed that this routine *
  105. * will be overridden to provide some useful functionality. At this level, the straw chain *
  106. * merely passes the request on to the next straw in the chain. *
  107. * *
  108. * INPUT: source -- Pointer to the buffer to hold the requested data. *
  109. * *
  110. * length -- The number of bytes requested. *
  111. * *
  112. * OUTPUT: Returns with the number of bytes stored into the buffer. If the number returned *
  113. * is less than the number requested, then this indicates that the straw data has *
  114. * been exhausted. *
  115. * *
  116. * WARNINGS: none *
  117. * *
  118. * HISTORY: *
  119. * 07/03/1996 JLB : Created. *
  120. *=============================================================================================*/
  121. int Straw::Get(void * source, int slen)
  122. {
  123. if (ChainTo != NULL) {
  124. return(ChainTo->Get(source, slen));
  125. }
  126. return(0);
  127. }