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

📄 mydata.cpp

📁 使用VC6开发 通过并口操作IIC 使用winio驱动操作并口
💻 CPP
字号:
// MyData.cpp: implementation of the CMyData class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "iic.h"
#include "MyData.h"
#include <vector>
using namespace std;

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Row::Row()
{
	Name = "NewReg";
	Note = "";
	nReg = 1;
	for(int i =0;i<260;i++){
		Value[i] = 0;
	}
}
Row::~Row()
{
}

CMyData::CMyData()
{
}

CMyData::~CMyData()
{
}

BYTE CMyData::GetValue(int Row,int Column)
{
	if(Row>(List.size()))
		AfxMessageBox("vector List err,GetValue()");
	return List[Row].Value[Column];
}

void CMyData::SetValue(int Row, int Column,BYTE value)
{
	if(Row>(List.size()))
		AfxMessageBox("vector List err,GetValue()");
	if(List[Row].nReg < Column){
		AfxMessageBox("数据中间不能有空值。");
		return;
	}
	if(List[Row].nReg == Column) List[Row].nReg++;
	List[Row].Value[Column] = value;
}

int CMyData::AddRow(CString str)
{
	CString str2;
	Row newRow;
	int sum = 0,index = 0;
	char* pStopString;
	BYTE Number;
	str += " ";
	str.TrimLeft();
	index = str.Find(" ");
	while (index != -1){
		str2 = str.Left(index);
		str = str.Right(str.GetLength() - index);
		str.TrimLeft();
		if(str2.GetLength() <= 2){
			Number = strtoul (str2, &pStopString, 16);
			newRow.Value[sum] = Number;
			sum++;
			if(sum>255){
				newRow.nReg = sum;
				newRow.Name = "Error";
				newRow.Note = "This line is too long to receive.\r\nThe data line's length shuld be less than 255.";
				return AddRow(newRow);
			}
		}else{
			if(sum==0) return 0;
			str2.Replace("##"," ");
			str2.TrimLeft();
			newRow.Name = str2;
			str.TrimRight();
			newRow.Note = str;
			newRow.Note.Replace("\t","\r\n");
			break;
		}
		index = str.Find(" ");
	}
	if(sum>0){
		newRow.nReg = sum;
		return AddRow(newRow);
	}
	return 0;
}

int CMyData::AddRow(Row newRow)
{
	List.push_back(newRow);
	return 1;
}

CString CMyData::GetName(int row)
{
	if(row>List.size())
		AfxMessageBox("List size error!GetNmae()");
	return List[row].Name;
}

CString CMyData::GetNote(int row)
{
	if(row>List.size())
		AfxMessageBox("List size error!GetNmae()");
	return List[row].Note;	
}

void CMyData::SetName(int row,CString name)
{
	if(row>List.size())
		AfxMessageBox("List size error!SetName()");
	List[row].Name = name;
	return;
}

void CMyData::SetNote(int row,CString note)
{
	if(row>List.size())
		AfxMessageBox("List size error!SetNote()");
	List[row].Note = note;	
	return;
}

CString CMyData::GetRow(int row)
{
	if(row>List.size())
		AfxMessageBox("List size error!GetName()");
	CString str(""),str2("");
	if(row>List.size())
		AfxMessageBox("List size error!GetRow()");	
	for(int i=0;i<List[row].nReg;i++){
		str2.Format("%02X",List[row].Value[i]);
		str += str2;
		str += " ";
	}
	str += "##";
	CString tmp = List[row].Name;
	tmp.Replace(" ","##");
	str += tmp;
	str += " ";
	str += List[row].Note;
	str.Replace("\t","    ");
	str.Replace("\r\n","\t");
	str += "\n";
	return str;
}

int CMyData::GetSize()
{
	return List.size();
}

int CMyData::AddRow()
{
	Row newRow;
	return AddRow(newRow);
}

BYTE CMyData::GetValue(int row)
{
	if(row>List.size())
		AfxMessageBox("List size error!GetName()");
	int index = List[row].nReg -1;
	return GetValue(row,index);
}

void CMyData::ClearAll()
{
	List.clear();
}

int CMyData::GetRowLength(int row)
{
	return List[row].nReg;
}

void CMyData::DeleteRow(int row)
{
	List.erase(List.begin()+row);
}

⌨️ 快捷键说明

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