www.gusucode.com > 一些VC++加密算法+实例源码源码程序 > 一些VC++加密算法+实例源码/优化后的加密注册模块/优化后的加密注册模块/inventory(optimized)/MapLink.cpp
// MapLink.cpp: implementation of the MapLink class. #include "stdafx.h" #include "INV_struct.h" #include "MapLink.h" //**************************************************************************** MapLink::MapLink() { //initialize the member variable header = NULL; tail = NULL; MaxID=10000; number=0; } MapLink::~MapLink() { //delete all nodes, release the map link MAPNode *cur,*curnext; cur=header; while (cur!=NULL) { curnext=cur->Next; delete cur; cur=curnext; } } //******************************************************************************** MAPdb*MapLink::SearchNode(long id) { MAPNode *cur=header; while (cur!=NULL) { if (cur->body->ID==id) return cur->body; cur=cur->Next; } return NULL; } //******************************************************************************** void MapLink::AddNode(MAPdb *newMAP) { if (newMAP->ID>MaxID) MaxID=newMAP->ID; MAPNode *newhead = new MAPNode; MAPdb *tmpMAP=new MAPdb; newhead->body = tmpMAP; newhead->Next = NULL; tmpMAP->ID=newMAP->ID; lstrcpy(tmpMAP->IPAddress,newMAP->IPAddress); tmpMAP->AvailableTag = newMAP->AvailableTag; lstrcpy(tmpMAP->HostName,newMAP->HostName); if(header == NULL) { header = newhead; tail = newhead; } else { tail->Next = newhead; tail = newhead; } number++; } //****************************************************************************** void MapLink::deleteNode(long id) { MAPNode *curf=header; MAPNode *cur; if(curf->body->ID==id) { header=header->Next; delete curf; } else { cur=header->Next; while (cur!=NULL) { if (cur->body->ID==id) { if(cur->Next==NULL) tail=curf; curf->Next=cur->Next; delete cur; break; } else { curf=cur; cur=cur->Next; } } } number--; } //****************************************************************************** void Transform_IP(char *IP) { char newIP[16]; int i,j=15,k=0; i=strlen(IP); while(i>=0) { if(IP[i]=='.') { while(k<4) { newIP[j]='0'; j--; k++; } k=0; } newIP[j]=IP[i]; k++; i--; j--; } if(j>=0) { while(k<4) { newIP[j]='0'; j--; k++; } } strcpy(IP,newIP); } //******************************************************************************* void Tranvers_IP(char *IP) { char newIP[16]; int i,j=0,head=0; for(i=0;i<(int)strlen(IP);i++) { if(IP[i]=='.') { if(head==0) { newIP[j]='0'; j++; } else head=0; newIP[j]='.'; j++; } else if(head!=0 || IP[i]!='0') { newIP[j]=IP[i]; j++; head=1; } } if(head==0) { newIP[j]='0'; j++; } newIP[j]=0; strcpy(IP,newIP); }