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

📄 octet.cpp

📁 isdn的完整解决方案。非常强大。不过是国际标准而非国标。
💻 CPP
字号:
/*************************************************************************** *   Copyright (C) 2004 by Roman Schmidt                                   * *   roman.schmidt@fh-stralsund.de                                         * *                                                                         * ***************************************************************************/#include "octet.h"#include <qobject.h>using namespace std;Octet::Octet(Octet *newFather, int test){	father = newFather;	mask = 0xFF;		}Octet::~Octet(){	for(int i=0; i<childOctets.size(); i++)	{		delete childOctets[i];	}}std::string Octet::getValue(){	bitset<8> bitmask(mask);		unsigned char tmpByte = byte & mask;	char tmpStr[4];		for(int i=0; i<8; i++)	{		if(bitmask[i])		{			break;		}		else		{			tmpByte>>=1;		}	}		sprintf(tmpStr,"%d",tmpByte);	return tmpStr;}std::string Octet::getBitset(){	std::bitset<8> bits(byte);	std::bitset<8> bitmask(mask);	std::string tmpStr;		for(int i=7; i>=0; i--)	{		if(bitmask[i])		{			bits[i] ? tmpStr += "1" : tmpStr += "0";		}		else		{			tmpStr += "-";		}	}		return tmpStr;}void Octet::setBitmask(unsigned char set){	mask = set;}void Octet::setParam(std::string str){	param = str;}std::string Octet::getParam(){	return param;}/*!    \fn Octet::isSubOctet() */bool Octet::isSubOctet(){		if(father)		return true;	else		return false;}/*!    \fn Octet::setByte() */void Octet::setByte(unsigned char data){    byte = data;}/*!    \fn Octet::getByte() */std::string Octet::getByteAsString(){	char tmpStr[3];		sprintf(tmpStr,"%02x",byte);		    return std::string(tmpStr);}unsigned char Octet::getByte(){    return byte;}/*!    \fn Octet::addChildOctet() */void Octet::addChildOctet(Octet *childOctet){    childOctets.push_back(childOctet);}/*!    \fn Octet::getChildOctet(int i) */Octet* Octet::getChildOctet(int i){    if(i < childOctets.size())	{		return childOctets[i];	}	else	{		return NULL;	}}/*!    \fn Octet::childSize() */int Octet::childSize(){    return childOctets.size();}int Octet::getMaxValue(){	std::bitset<8> bitmask(mask);	int maxValue=1;		for(int i=0; i<8; i++)	{		if(bitmask[i])		{			maxValue *= 2;		}	}		return maxValue-1;}/*!    \fn Octet::setValue(int val) */void Octet::setValue(int val){    std::bitset<8> value(val);	std::bitset<8> bitmask(mask);	std::string tmpStr;	for(int i=0; i<8; i++)	{		if(bitmask[i])		{			break;		}		else		{			value<<=1;		}	}		byte &= 0xFF^mask;	byte |= mask&value.to_ulong();		debug("%02x",byte);		if(father)		father->setByte(byte);	else		this->setByte(byte);}

⌨️ 快捷键说明

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