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

📄 icecustomarray.h

📁 使用stl技术,(还没看,是听说的)
💻 H
📖 第 1 页 / 共 2 页
字号:
										Mask>>=1;
									}
									return *this;
								}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Reads a bit.
		 *	\return		the bit
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	bool			GetBit()	const
								{
									if(!mBitCount)
									{
										mBitMask = GetByte();
										mBitCount = 0x80;
									}
									bool Bit = (mBitMask&mBitCount)!=0;
									mBitCount>>=1;
									return Bit;
								}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Reads bits.
		 *	\param		nb_bits		[in] the number of bits to read
		 *	\return		the bits
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	udword			GetBits(udword nb_bits)	const
								{
									udword Bits = 0;
									while(nb_bits--)
									{
										Bits<<=1;
										bool Bit = GetBit();
										Bits|=udword(Bit);
									}
									return Bits;
								}

		// Padds extra bits to reach a byte
				CustomArray&	EndBits();

		// Management methods
				bool			ExportToDisk(const char* filename, const char* access=null);
				bool			ExportToDisk(FILE* fp);

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets current number of bytes stored.
		 *	\return		number of bytes stored
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				udword			GetOffset()	const;
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Padds offset on a 8 bytes boundary.
		 *	\return		Self-Reference
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				CustomArray&	Padd();
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Collapses a CustomArray into a single continuous buffer. This invalidates all pushed addies.
		 *	If you provide your destination buffer original bytes are copied into it, then it's safe using them.
		 *	If you don't, returned address is valid until the array's destructor is called. Beware of memory corruption...
		 *	\param		user_buffer		[out] destination buffer (provided or not)
		 *	\return		destination buffer
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				void*			Collapse(void* user_buffer=null);

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets the current address within the current block.
		 *	\return		destination buffer
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	void*			GetAddress()	const
								{
									char* CurrentAddy = (char*)mCurrentCell->Item.Addy;
									CurrentAddy+=mCurrentCell->Item.Size;
									return CurrentAddy;
								}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets used size within current block.
		 *	\return		used size / offset
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	udword			GetCellUsedSize()	const
								{
									return mCurrentCell->Item.Size;
								}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets max size within current block.
		 *	\return		max size / limit
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	udword			GetCellMaxSize()	const
								{
									return mCurrentCell->Item.Max;
								}

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Gets remaining size within current block.
		 *	\return		remaining size / limit - offset
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		inline_	udword			GetCellRemainingSize()	const
								{
									return mCurrentCell->Item.Max - mCurrentCell->Item.Size;
								}

		// Address methods
				bool			PushAddress();
				CustomArray&	PopAddressAndStore(BOOL Bo);
				CustomArray&	PopAddressAndStore(bool Bo);
				CustomArray&	PopAddressAndStore(char b);
				CustomArray&	PopAddressAndStore(ubyte b);
				CustomArray&	PopAddressAndStore(short w);
				CustomArray&	PopAddressAndStore(uword w);
				CustomArray&	PopAddressAndStore(long d);
				CustomArray&	PopAddressAndStore(unsigned long d);
			//	CustomArray&	PopAddressAndStore(int d);
				CustomArray&	PopAddressAndStore(unsigned int d);
				CustomArray&	PopAddressAndStore(float f);
				CustomArray&	PopAddressAndStore(double f);

		// Read methods
				ubyte			GetByte()	const;			//!< Read a byte from the array
				uword			GetWord()	const;			//!< Read a word from the array
				udword			GetDword()	const;			//!< Read a dword from the array
				float			GetFloat()	const;			//!< Read a float from the array
				ubyte*			GetString()	const;			//!< Read a string from the array

		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Sets the current address within current block. Input offset can't be greater than current block's length.
		 *	\param		offset	[in] the wanted offset within the block.
		 *	\return		Self-Reference.
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				CustomArray&	Reset(udword offset=0);
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 *	Finds a given chunk (a sequence of bytes) in current buffer.
		 *	\param		chunk	[in] chunk you're looking for (must end with a null byte).
		 *	\return		address where the chunk has been found, or null if not found.
		 *	\warning	chunk length limited to 1024 bytes...
		 */
		///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
				void*			GetChunk(const char* chunk);

				CustomArray&	operator=(CustomArray& array);
		private:
				CustomCell*		mCurrentCell;				//!< Current block cell
				CustomCell*		mInitCell;					//!< First block cell

				void*			mCollapsed;					//!< Possible collapsed buffer
				void**			mAddresses;					//!< Stack to store addresses
				void*			mLastAddress;				//!< Last address used in current block cell
				uword			mNbPushedAddies;			//!< Number of saved addies
				uword			mNbAllocatedAddies;			//!< Number of allocated addies
		// Bit storage
		mutable	ubyte			mBitCount;					//!< Current number of valid bits in the bitmask
		mutable	ubyte			mBitMask;					//!< Current bitmask
		// Management methods
				void			Init(udword start_size, void* input_buffer, FILE* fp, udword used_size);
				CustomArray&	Empty();
				CustomArray&	CheckArray(udword bytes_needed);
				bool			NewBlock(CustomCell* previous_cell, udword size=0);
				bool			SaveCell(CustomCell* p, FILE* fp);
				CustomArray&	StoreASCIICode(char code);
				void*			PrepareAccess(udword size);
	};

#endif // __ICECUSTOMARRAY_H__

⌨️ 快捷键说明

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