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

📄 icecustomarray.h

📁 使用stl技术,(还没看,是听说的)
💻 H
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 *	Contains a custom array class.
 *	\file		IceCustomArray.h
 *	\author		Pierre Terdiman
 *	\date		January, 15, 1999
 */
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Include Guard
#ifndef __ICECUSTOMARRAY_H__
#define __ICECUSTOMARRAY_H__

	//! Default size of a memory block
	#define CUSTOMARRAY_BLOCKSIZE	(4*1024)		// 4 Kb => heap size

	//! A memory block
	class ICECORE_API CustomBlock
	{
		public:
							CustomBlock();
							~CustomBlock();

		void*				Addy;					//!< Stored data
		udword				Size;					//!< Length of stored data
		udword				Max;					//!< Heap size
	};

	//! A linked list of blocks
	class ICECORE_API CustomCell
	{
		public:
							CustomCell();
							~CustomCell();

		CustomCell*			NextCustomCell;
		CustomBlock			Item;
	};

	class ICECORE_API CustomArray
	{
		public:
		// Constructor / Destructor
								CustomArray(udword start_size=CUSTOMARRAY_BLOCKSIZE, void* input_buffer=null);
								CustomArray(CustomArray& array);
								CustomArray(const char* filename);
								~CustomArray();

				CustomArray&	Clean();

		// Store methods

			// Store a BOOL
				CustomArray&	Store(BOOL bo);
			// Store a bool
				CustomArray&	Store(bool bo);

			// Store a char (different from "signed char" AND "unsigned char")
				CustomArray&	Store(char b);
			// Store a ubyte
		inline_	CustomArray&	Store(ubyte b)
								{
									ASSERT(sizeof(ubyte)==sizeof(char));
									return Store(char(b));
								}
			// Store a sbyte
		inline_	CustomArray&	Store(sbyte b)
								{
									ASSERT(sizeof(sbyte)==sizeof(char));
									return Store(char(b));
								}

			// Store a short / sword
				CustomArray&	Store(short w);
			// Store a uword
		inline_	CustomArray&	Store(uword w)
								{
									ASSERT(sizeof(uword)==sizeof(short));
									return Store(short(w));
								}

			// Store a unsigned int / udword. "int / sdword" is handled as a BOOL.
				CustomArray&	Store(udword d);
			// Store a long
		inline_	CustomArray&	Store(long d)
								{
									ASSERT(sizeof(long)==sizeof(udword));
									return Store(udword(d));
								}
			// Store a unsigned long
		inline_	CustomArray&	Store(unsigned long d)
								{
									ASSERT(sizeof(unsigned long)==sizeof(udword));
									return Store(udword(d));
								}

			// Store a float
				CustomArray&	Store(float f);
			// Store a double
				CustomArray&	Store(double f);

			// Store a string
				CustomArray&	Store(const char* string);
			// Store a buffer
				CustomArray&	Store(void* buffer, udword size);
			// Store a CustomArray
				CustomArray&	Store(CustomArray* array);

		// ASCII store methods

			// Store a BOOL in ASCII
				CustomArray&	StoreASCII(BOOL bo);
			// Store a bool in ASCII
				CustomArray&	StoreASCII(bool bo);

			// Store a char in ASCII
				CustomArray&	StoreASCII(char b);
			// Store a sbyte in ASCII
		inline_	CustomArray&	StoreASCII(sbyte b)		{ return StoreASCII(char(b));	}
			// Store a ubyte in ASCII
				CustomArray&	StoreASCII(ubyte b);

			// Store a short in ASCII
				CustomArray&	StoreASCII(short w);
			// Store a uword in ASCII
				CustomArray&	StoreASCII(uword w);

			// Store a long in ASCII
				CustomArray&	StoreASCII(long d);
			// Store a unsigned long in ASCII
				CustomArray&	StoreASCII(unsigned long d);

			// Store a int in ASCII
			//	CustomArray&	StoreASCII(int d);
			// Store a unsigned int in ASCII
				CustomArray&	StoreASCII(unsigned int d);

			// Store a float in ASCII
				CustomArray&	StoreASCII(float f);
			// Store a double in ASCII
				CustomArray&	StoreASCII(double f);

			// Store a string in ASCII
				CustomArray&	StoreASCII(const char* string);
			// Store a formated string in ASCII
				CustomArray&	StoreASCII(LPSTR fmt, ...);

		// Bit storage - inlined since mostly used in data compression where speed is welcome

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Stores a bit.
		 *	\param		bit		[in] the bit to store
		 *	\return		Self-Reference
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	CustomArray&	StoreBit(bool bit)
								{
									mBitMask<<=1;				// Shift current bitmask
//									if(bit)	mBitMask |= 1;		// Set the LSB if needed
									mBitMask |= (ubyte)bit;		// Set the LSB if needed - no conditional branch here
									mBitCount++;				// Count number of active bits in bitmask
									if(mBitCount==8)			// If bitmask is full...
									{
										mBitCount = 0;			// ...then reset counter...
										Store(mBitMask);		// ...and store bitmask.
									}
									return *this;
								}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Store bits.
		 *	\param		bits	[in] the bit pattern to store
		 *	\param		nb_bits	[in] the number of bits to store
		 *	\return		Self-Reference
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	CustomArray&	StoreBits(udword bits, udword nb_bits)
								{
									udword Mask=1<<(nb_bits-1);
									while(Mask)
									{
										StoreBit((bits&Mask)!=0);

⌨️ 快捷键说明

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