STRAW.CPP 8.4 KB

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