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

📄 octets.h

📁 一个实现可以在进程间或者线程间通信的高效环形队列类
💻 H
字号:
#ifndef _OCTETS_H_
#define _OCTETS_H_

#include "ace/Log_Msg.h"
typedef unsigned char BYTE;
typedef unsigned int UINT;

struct _OCTETS
{
	BYTE * stream;
	UINT   datalen;
	UINT   buflen;
	int   dynamic;
};
typedef struct _OCTETS OCTETS;

class COctets : public _OCTETS
{
	friend int operator == (const COctets& octet1, const COctets& octet2);
	friend int operator != (const COctets& octet1, const COctets& octet2);
	friend int operator >  (const COctets& octet1, const COctets& octet2);
	friend int operator <  (const COctets& octet1, const COctets& octet2);
	friend int operator >= (const COctets& octet1, const COctets& octet2);
	friend int operator <= (const COctets& octet1, const COctets& octet2);
	
	friend int operator == (const COctets& octet1, const char * octet2);
	friend int operator != (const COctets& octet1, const char * octet2);
	friend int operator >  (const COctets& octet1, const char * octet2);
	friend int operator <  (const COctets& octet1, const char * octet2);
	friend int operator >= (const COctets& octet1, const char * octet2);
	friend int operator <= (const COctets& octet1, const char * octet2);
	
public:
	COctets();
	COctets(UINT nLen);
	COctets(const COctets& octet);
	COctets(const BYTE * pDatas, UINT nLenOfDatas, int fAllocByDll = true);
	COctets(const char * pDatas, UINT nLenOfDatas, int fAllocByDll = true);
	COctets(const char * pDatas);
	
	virtual ~COctets();
	
public:
	void Free();
	
	void SetData(const BYTE* string, UINT nLength, int fAllocByDll = true);
	void SetDataSize(UINT nLength);
	void SetBufferSize(UINT nLength);
	void ExtendBuffer(UINT nExtendLen, int bDataCopy = true);
	COctets* Clone() const;
	
	COctets& operator = (const COctets& octet);
	COctets& operator = (const char* s);
	COctets& operator += (const COctets& octet);
	COctets& operator += (const char* octet);
	COctets& operator += (const char ch);
	void Append(const COctets& octet)	{*this += octet;}
	void Append(const char* octet)		{*this += octet;}
	void Append(const char ch)			{*this += ch;}
	void Append(const BYTE* pDatas, UINT nLenOfDatas);
	
	BYTE& operator[](const UINT index);
	BYTE operator[](const UINT index) const;

	int IsEmpty() const {return datalen == 0;}
	void Empty() {datalen = 0;}
	void Reset() {datalen = 0;}
	void Compress();
	void SetGrowBy(int nGrowBy);
	
	// 比较
	int NCompare(const COctets& octet, UINT nChars) const;
	int NCompare(const char* octet, UINT nChars) const;
	
	int Compare(const COctets& octet) const;
	int Compare(const char* octet) const;
	
	
	BYTE* GetData() const {return stream;}
	UINT GetDataLength() const {return datalen;}
	UINT GetBufLength() const {return buflen;}
	

	
private:
	int	 m_nGrowBy;

private:
	inline BYTE * MyMemAlloc(UINT nLen)
	{
		return new BYTE[nLen];
	}

	inline void MyMemFree(BYTE * pData)
	{
			delete []pData;
	}
		
};

inline void COctets::SetGrowBy(int nGrowBy)
{
	ACE_ASSERT(nGrowBy > 0); 
	m_nGrowBy = nGrowBy;
}

#endif // _OCTETS_H_


⌨️ 快捷键说明

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