message.cpp

来自「本代码是基于LINUX系统下的」· C++ 代码 · 共 72 行

CPP
72
字号
#include "Message.h"CMessage::CMessage(char *buff, int buf_length)
{
	assert(buff != NULL);
	total_length = buf_length;
	total_Str = new char[total_length];
	if(total_Str != NULL)
	cout<< "make success!"<< endl;
	int i=0;
	while(i < total_length)
	{
		total_Str[i] = buff[i];
		i++;
	}
	Type = buff[1];
	Sid = 0;
}

void CMessage::SetSingleStr(char *str, int startc,int length)
{		assert((startc+length) <= total_length);
		int i = 0,j = startc;
		while(i < length)
		{
			total_Str[j] = str[i];
			i++;
			j++;
		}
}

void CMessage::GetsingleStr(char *str,  int startc, int length)
{
	assert(total_Str != NULL);
	int i = 0,j = startc;
	while(i < length)
	{
		str[i] = total_Str[j];
		i++;
		j++;
	}
	str[length] = '\0';
}

int CMessage::GetTotalStrLen()
{
		return total_length;
}

int CMessage::GetType()
{	
	if(total_Str == NULL)
	cout<< "null"<< endl;
	else 
	cout<< "not null"<< endl;
	assert(total_Str != NULL);
	int i = total_Str[1];
	return i;
}

int CMessage::GetSID()
{
	return Sid;
}

CMessage::~CMessage()
{	
	//cout<< "the CMessage is running:";
	if(total_Str != NULL)delete[]total_Str;

}

⌨️ 快捷键说明

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