Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
cstraw.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(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/***********************************************************************************************
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 * $Archive:: /Commando/Library/CSTRAW.CPP $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 7/22/97 11:37a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * CacheStraw::Get -- Fetch data from the data source. *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38#include "always.h"
39#include "cstraw.h"
40#include <string.h>
41
42
43/***********************************************************************************************
44 * CacheStraw::Get -- Fetch data from the data source. *
45 * *
46 * This will supply the data quantity requested. It performs a regulating influence on the *
47 * data requests passed through it. The data is requested from the next straw in the *
48 * chain such that the data stream is requested in chunks. This serves to lessen the *
49 * impact of multiple small data requests. *
50 * *
51 * INPUT: source -- Pointer to the buffer to hold the data. *
52 * *
53 * slen -- The number of data bytes requested. *
54 * *
55 * OUTPUT: Returns with the number of data bytes stored into the buffer specified. If this *
56 * number is less than that requested, it indicates that the data source has been *
57 * exhausted. *
58 * *
59 * WARNINGS: none *
60 * *
61 * HISTORY: *
62 * 11/10/1996 JLB : Created. *
63 *=============================================================================================*/
64int CacheStraw::Get(void * source, int slen)
65{
66 int total = 0;
67
68 if (Is_Valid() && source != NULL && slen > 0) {
69
70 /*
71 ** Keep processing the data request until there is no more data to supply or the request
72 ** has been fulfilled.
73 */
74 while (slen > 0) {
75
76 /*
77 ** First try to fetch the data from data previously loaded into the buffer.
78 */
79 if (Length > 0) {
80 int tocopy = (Length < slen) ? Length : slen;
81 memmove(source, ((char *)BufferPtr.Get_Buffer()) + Index, tocopy);
82 slen -= tocopy;
83 Index += tocopy;
84 total += tocopy;
85 Length -= tocopy;
86 source = (char*)source + tocopy;
87 }
88 if (slen == 0) break;
89
90 /*
91 ** Since there is more to be fulfilled yet the holding buffer is empty,
92 ** refill the buffer with a fresh block of data from the source.
93 */
94 Length = Straw::Get(BufferPtr, BufferPtr.Get_Size());
95 Index = 0;
96 if (Length == 0) break;
97 }
98 }
99 return(total);
100}
#define NULL
Definition BaseType.h:92
virtual int Get(void *source, int slen)
Definition cstraw.cpp:64
virtual int Get(void *buffer, int slen)
Definition straw.cpp:132