⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bitarray.h

📁 hl2 source code. Do not use it illegal.
💻 H
字号:
/**********************************************************************
 *<
	FILE: bitarray.h

	DESCRIPTION:

	CREATED BY: Dan Silva

	HISTORY:

 *>	Copyright (c) 1994, All Rights Reserved.
 **********************************************************************/

#ifndef BITARRAY__H
#define BITARRAY__H

#include <windef.h>
#include <ioapi.h>

class BitArrayCallback {
	public:
	virtual void proc(int n)=0;
	};

// Direction indicators for BitArray::Rotate and BitArray::Shift
#define LEFT_BITSHIFT 0
#define RIGHT_BITSHIFT 1

class BitArray {
	DWORD* bits;
	long numBits;
	public:
		DllExport void SetSize(int n, int save=0);  // save=1:preserve old bit values
		int	GetSize() const { return numBits; }
		DllExport void ClearAll();
		DllExport void SetAll();
	    DllExport void Set(int i);       	// set ith bit to 1
	    DllExport void Clear(int i);     	// set ith bit to 0 
		DllExport void Set(int i, int b);  // set ith bit to b
		DllExport int operator[](int i) const;  // get ith bit
		DllExport int NumberSet();      // how many bits are 1's.
		DllExport BOOL IsEmpty();      // are NO bits set?.  much faster than NumberSet
		DllExport void Compress();    
		DllExport void Expand();
		DllExport void Reverse(BOOL keepZero = FALSE);	// keepZero=TRUE keeps zero bit where it is
		DllExport void Rotate(int direction, int count);				// With wraparound
		DllExport void Shift(int direction, int count, int where=0);	// Without wraparound
		DllExport void EnumSet(BitArrayCallback &cb);  // enumerates elements that are 1's
		DllExport void DeleteSet (BitArray & dset, int mult=1);
		DllExport IOResult Save(ISave* isave);
		DllExport IOResult Load(ILoad* iload);

		BitArray() { bits = NULL; 	numBits = 0; }
		DllExport BitArray(int n);
		DllExport BitArray(const BitArray& b);
		DllExport ~BitArray();

		// Comparison operator
		DllExport BOOL operator==(const BitArray& b);
		
		// Assignment operators
		DllExport BitArray& operator=(const BitArray& b);

		// Assignment operators: These require arrays of the same size!
		DllExport BitArray& operator&=(const BitArray& b);  // AND=
		DllExport BitArray& operator|=(const BitArray& b);  // OR=
		DllExport BitArray& operator^=(const BitArray& b);  // XOR=

		// Binary operators: These require arrays of the same size!
		DllExport BitArray operator&(const BitArray&) const; // AND
		DllExport BitArray operator|(const BitArray&) const; // OR
		DllExport BitArray operator^(const BitArray&) const; // XOR

		// Unary operators
		DllExport BitArray operator~(); // unary NOT function

	};






#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -