CnC_Remastered_Collection

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

BUFFERX.H (4280B)


      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/BUFFERX.H 1     3/03/97 10:24a 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 : BUFFER.H                                                     *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 05/04/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : May 4, 1996 [JLB]                                            *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     34 
     35 
     36 #ifndef BUFFERx_H
     37 #define BUFFERx_H
     38 
     39 #include	"wwfile.h"
     40 
     41 /*
     42 **	This is a transmuter interface designed to aid implementation of compression, encryption, or
     43 **	data analysis classes. The Transmuter should be derived into a class that performs the necessary
     44 **	processing.
     45 */
     46 class Transmuter {
     47 	public:
     48 		Transmuter(void) : Output(0) {}
     49 		virtual ~Transmuter(void) {}
     50 
     51 		/*
     52 		**	These are the interface function that are used to pass data to the transmuter. The
     53 		**	default implementation of these functions do nothing other than pass the data onto
     54 		**	the subsequent transmuter. For practical use, these functions should be overloaded to
     55 		**	do something more useful.
     56 		*/
     57 		virtual void Attach(Transmuter * transmuter) {Output = transmuter;}
     58 		virtual void Flush(void) {if (Output) Output->Flush();}
     59 		virtual void Put(const void * input, unsigned length) {if (Output) Output->Put(input, length);}
     60 
     61 	protected:
     62 
     63 		/*
     64 		**	Pointer to the output transmuter.
     65 		*/
     66 		Transmuter * Output;
     67 };
     68 
     69 
     70 class FileTransmuter {
     71 	public:
     72 		FileTransmuter(FileClass * file = NULL) : OutputFile(file) {}
     73 
     74 		virtual void Attach(FileClass * file) {OutputFile = file;}
     75 		virtual void Flush(void) {}
     76 		virtual void Put(const void * input, unsigned length) {if (OutputFile) OutputFile->Write(input, length);}
     77 
     78 	protected:
     79 		FileClass * OutputFile;
     80 };
     81 
     82 
     83 class BufferTransmuter {
     84 	public:
     85 		BufferTransmuter(void * buffer = NULL) : BufferPtr(buffer) {}
     86 
     87 		virtual void Attach(void * buffer) {BufferPtr = buffer;}
     88 		virtual void Flush(void) {}
     89 		virtual void Put(const void * input, unsigned length) {if (BufferPtr) {memcpy(BufferPtr, input, length);((char *&)BufferPtr) += length;}}
     90 
     91 	protected:
     92 		void * BufferPtr;
     93 };
     94 
     95 
     96 #endif
     97 
     98