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