CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

BUFFER.CPP (7046B)


      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 /***************************************************************************
     17  **   C O N F I D E N T I A L --- W E S T W O O D   A S S O C I A T E S   **
     18  ***************************************************************************
     19  *                                                                         *
     20  *                 Project Name : Westwood 32 Bit Library                  *
     21  *                                                                         *
     22  *                    File Name : BUFFER.CPP                               *
     23  *                                                                         *
     24  *                   Programmer : Phil W. Gorrow                           *
     25  *                                                                         *
     26  *                   Start Date : May 18, 1994                             *
     27  *                                                                         *
     28  *                  Last Update : June 1, 1994   [PWG]                     *
     29  *                                                                         *
     30  *-------------------------------------------------------------------------*
     31  * Functions:                                                              *
     32  *   BC::BufferClass -- The default (void) constructor for a buffer class  *
     33  *   BC::~BufferClass -- The destructor for the buffer class               *
     34  *   BC::BufferClass -- The standard constructor for a buffer class        *
     35  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     36 
     37 #ifndef BUFFER_H
     38 #include "buffer.h"
     39 #endif
     40 
     41 /*=========================================================================*/
     42 /* The following PRIVATE functions are in this file:                       */
     43 /*=========================================================================*/
     44 
     45 
     46 /*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/
     47 
     48 /***************************************************************************
     49  * BC::BufferClass -- The standard constructor for a buffer class          *
     50  *                                                                         *
     51  * INPUT:		VOID *	buffer to which should be included in buffer class *
     52  *					LONG		size of the buffer which we included					*
     53  *                                                                         *
     54  * OUTPUT:     NONE                                                        *
     55  *                                                                         *
     56  * WARNINGS:   If the buffer passed to this function is equal to NULL,     *
     57  *					the buffer will be allocated using new.							*
     58  *                                                                         *
     59  * HISTORY:                                                                *
     60  *   06/01/1994 PWG : Created.                                             *
     61  *=========================================================================*/
     62 BufferClass::BufferClass(VOID *buffer, LONG size)
     63 {
     64 	Size			= size;								// find size of physical buffer
     65 
     66 	if (buffer) {										// if buffer is specified
     67 		Buffer			= (BYTE *)buffer;			//		point to it and mark
     68 		Allocated		= FALSE;						//		it as user allocated
     69 	} else {
     70 		Buffer			= new BYTE[Size];			// otherwise allocate it and
     71 		Allocated		= TRUE;						//		mark it system alloced
     72 	}
     73 }
     74 
     75 /***************************************************************************
     76  * BC::BufferClass -- constructor for BufferClass with size only    			*
     77  *                                                                         *
     78  * INPUT:		LONG the size of the buffer that needs to be allocated		*
     79  *                                                                         *
     80  * OUTPUT:     none                                                        *
     81  *                                                                         *
     82  * HISTORY:                                                                *
     83  *   06/01/1994 PWG : Created.                                             *
     84  *=========================================================================*/
     85 BufferClass::BufferClass(LONG size)
     86 {
     87 	Size				= size;
     88 	Buffer			= new BYTE[Size];			// otherwise allocate it and
     89 	Allocated		= TRUE;						//		mark it system alloced
     90 }
     91 
     92 /***************************************************************************
     93  * BC::BufferClass -- The default (void) constructor for a buffer class    *
     94  *                                                                         *
     95  * INPUT:		none                                                        *
     96  *                                                                         *
     97  * OUTPUT:     none                                                        *
     98  *                                                                         *
     99  * NOTES:   	The primary function of this class is to be called by a     *
    100  *					derived class which will fill in the values after the			*
    101  *					fact.																			*
    102  *                                                                         *
    103  * HISTORY:                                                                *
    104  *   06/01/1994 PWG : Created.                                             *
    105  *=========================================================================*/
    106 BufferClass::BufferClass(VOID)
    107 {
    108 	Buffer		= NULL;
    109 	Size			= 0;
    110 	Allocated	= FALSE;
    111 }
    112 
    113 /***************************************************************************
    114  * BC::~BUFFERCLASS -- The destructor for the buffer class                 *
    115  *                                                                         *
    116  * INPUT:		none                                                        *
    117  *                                                                         *
    118  * OUTPUT:     none                                                        *
    119  *                                                                         *
    120  * HISTORY:                                                                *
    121  *   06/01/1994 PWG : Created.                                             *
    122  *=========================================================================*/
    123 BufferClass::~BufferClass(VOID)
    124 {
    125 	if (Allocated) {
    126 		delete[] Buffer;
    127 	}
    128 }