Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
xstraw.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/Code/Library/XSTRAW.CPP $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 9/28/98 12:06p $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * BufferStraw::Get -- Fetch data from the straw's buffer holding tank. *
36 * FileStraw::Get -- Fetch data from the file. *
37 * FileStraw::~FileStraw -- The destructor for the file straw. *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#include "always.h"
41#include "xstraw.h"
42#include <stddef.h>
43#include <string.h>
44
45//---------------------------------------------------------------------------------------------------------
46// BufferStraw
47//---------------------------------------------------------------------------------------------------------
48
49
50/***********************************************************************************************
51 * BufferStraw::Get -- Fetch data from the straw's buffer holding tank. *
52 * *
53 * This routine will copy the requested number of bytes from the buffer holding tank (as *
54 * set up by the straw's constructor) to the buffer specified. *
55 * *
56 * INPUT: source -- Pointer to the buffer to be filled with data. *
57 * *
58 * length -- The number of bytes requested. *
59 * *
60 * OUTPUT: Returns with the number of bytes copied to the buffer. If this is less than *
61 * requested, then it indicates that the data holding tank buffer is exhausted. *
62 * *
63 * WARNINGS: none *
64 * *
65 * HISTORY: *
66 * 07/03/1996 JLB : Created. *
67 *=============================================================================================*/
68int BufferStraw::Get(void * source, int slen)
69{
70 int total = 0;
71
72 if (Is_Valid() && source != NULL && slen > 0) {
73 int len = slen;
74 if (BufferPtr.Get_Size() != 0) {
75 int theoretical_max = BufferPtr.Get_Size() - Index;
76 len = (slen < theoretical_max) ? slen : theoretical_max;
77 }
78
79 if (len > 0) {
80 memmove(source, ((char*)BufferPtr.Get_Buffer()) + Index, len);
81 }
82
83 Index += len;
84// Length -= len;
85// BufferPtr = ((char *)BufferPtr) + len;
86 total += len;
87 }
88 return(total);
89}
90
91
92//---------------------------------------------------------------------------------------------------------
93// FileStraw
94//---------------------------------------------------------------------------------------------------------
95
96
97/***********************************************************************************************
98 * FileStraw::Get -- Fetch data from the file. *
99 * *
100 * This routine will read data from the file (as specified in the straw's constructor) into *
101 * the buffer indicated. *
102 * *
103 * INPUT: source -- Pointer to the buffer to hold the data. *
104 * *
105 * length -- The number of bytes requested. *
106 * *
107 * OUTPUT: Returns with the number of bytes stored into the buffer. If this number is less *
108 * than the number requested, then this indicates that the file is exhausted. *
109 * *
110 * WARNINGS: none *
111 * *
112 * HISTORY: *
113 * 07/03/1996 JLB : Created. *
114 *=============================================================================================*/
115int FileStraw::Get(void * source, int slen)
116{
117 if (Valid_File() && source != NULL && slen > 0) {
118 if (!File->Is_Open()) {
119 HasOpened = true;
120 if (!File->Is_Available()) return(0);
121 if (!File->Open(FileClass::READ)) return(0);
122 }
123
124 return(File->Read(source, slen));
125 }
126 return(0);
127}
128
129
130/***********************************************************************************************
131 * FileStraw::~FileStraw -- The destructor for the file straw. *
132 * *
133 * This destructor only needs to close the file if it was the one to open it. *
134 * *
135 * INPUT: none *
136 * *
137 * OUTPUT: none *
138 * *
139 * WARNINGS: none *
140 * *
141 * HISTORY: *
142 * 07/03/1996 JLB : Created. *
143 *=============================================================================================*/
145{
146 if (Valid_File() && HasOpened) {
147 File->Close();
148 HasOpened = false;
149 File = NULL;
150 }
151}
#define NULL
Definition BaseType.h:92
virtual int Get(void *source, int slen)
Definition xstraw.cpp:68
virtual ~FileStraw(void)
Definition xstraw.cpp:144
virtual int Get(void *source, int slen)
Definition xstraw.cpp:115