Создание исследовательского прототипа системы идентификации табличных данных
Рефераты >> Программирование и компьютеры >> Создание исследовательского прототипа системы идентификации табличных данных

if(Next!=NULL)

Next->Prev=Parent;

if(Parent->Next==this)

Parent->Next=Next;

else

if(Parent->Down==this)

Parent->Down=Next;

NewParent->AddChild(this);

if(IsGroup&&tv){

tn=(TTreeNode *)(NewParent->Data);

ToTree(tv,tn);

}

}

void TPositionTree::SaveToFile(FILE *f,TProgressBar *ind){

if(ind) ind->Position=ind->Position+1;

if(Down){

Down->SavePositionTo(f);

Down->SaveToFile(f,ind);

}else{

fputs("!enddown!",f);

fputs("\n",f);

}

if(Next){

Next->SavePositionTo(f);

Next->SaveToFile(f,ind);

}else{

fputs("!endnext!",f);

fputs("\n",f);

}

}

void TPositionTree::SavePositionTo(FILE *f){

TStringList *SL=new TStringList();

for(int i=0;i<FlowNum;i++){

SL->Add(OutPres[i]);

}

SL->Add(Code);

SL->Add(int(IsGroup));

SL->Add(Depth);

fputs(SL->CommaText.c_str(),f);

delete SL;

fputs("\n",f);

IP.SaveTo(f);

}

bool TPositionTree::Save(AnsiString FileName,TProgressBar *ind){

FILE *f;

f=fopen(FileName.c_str(),"w");

if(!f)

return(false);

SaveToFile(f,ind);

fclose(f);

ind->Position=0;

return(true);

}

TPositionTree *TPositionTree::LoadPositionFrom(FILE *f){

char str[600];

fgets(str,600,f);

if(AnsiString(str).Trim().AnsiCompare("!endnext!")==0

||AnsiString(str).Trim().AnsiCompare("!enddown!")==0)

return(NULL);

TPositionTree *Node=new TPositionTree();

TStringList *SL=new TStringList();

SL->CommaText=AnsiString(str);

for(int i=0;i<FlowNum;i++)

Node->OutPres[i]=SL->Strings[i];

Node->Code=SL->Strings[FlowNum].ToInt();

Node->IsGroup=SL->Strings[FlowNum+1].ToInt();

Node->Depth=SL->Strings[FlowNum+2].ToInt();

delete SL;

/* Node->OutPres[0]=AnsiString(str).Trim();

fgets(str,600,f);

Node->Code=AnsiString(str).Trim().ToInt();

fgets(str,600,f);

Node->IsGroup=AnsiString(str).Trim().ToInt();

fgets(str,600,f);

Node->Depth=AnsiString(str).Trim().ToInt(); */

Node->IP.LoadFrom(f);

return(Node);

}

void TPositionTree::LoadFromFile(FILE *f,TProgressBar *ind){

if(ind) ind->Position=ind->Position+1;

TPositionTree *Result=NULL;

if((Result=LoadPositionFrom(f))!=NULL){

AddChild(Result);

Result->LoadFromFile(f,ind);

}

if((Result=LoadPositionFrom(f))!=NULL){

Add(Result);

Result->LoadFromFile(f,ind);

}

}

TPositionTree *Load(AnsiString FileName,TProgressBar *ind){

FILE *f;

f=fopen(FileName.c_str(),"r");

if(!f)

return(NULL);

TPositionTree *Root=new TPositionTree();

Root->OutPres[0]=ChangeFileExt(ExtractFileName(FileName),AnsiString());

Root->IsGroup=true;

Root->Depth=0;

Root->LoadFromFile(f,ind);

fclose(f);

ind->Position=0;

return(Root);

}

TPositionTree *ImportFromFile(AnsiString FileName){

FILE *f;

f=fopen(FileName.c_str(),"r");

if(f==NULL)

return(NULL);

TPositionTree *Drive=new TPositionTree();

TPositionTree *Root;

Drive->Code=0;

Drive->IsGroup=true;

Drive->Depth=0;

Drive->OutPres[0]=ChangeFileExt(ExtractFileName(FileName),AnsiString());

Root=Drive;

char str[100];

AnsiString S;

bool Group; int i=0;

while(fgets(str,100,f)!=NULL){

S=AnsiString(str).Trim();

Group=true-IsQuantity(S);

if(Drive->Depth==0){

Drive=Drive->AddChild(i,S);

i++;

Drive->IsGroup=Group;

continue;

}

if(Group){

Drive=Drive->Add(i,S);

i++;

Drive->IsGroup=Group;

}else

Drive->AddChild(0,S)->IsGroup=Group;

}

fclose(f);

return(Root);

}

TPositionTree *ImportFromFileCT(AnsiString FileName,bool Price,TProgressBar *ind){

if(!FileExists(FileName))

return(NULL);

if(!FileExists(ChangeFileExt(FileName,".hdr")))

return(NULL);

TPositionTree *Drive=new TPositionTree();

TPositionTree *Root;

TPositionTree *New;

Drive->Code=0;

Drive->IsGroup=true;

Drive->Depth=0;

Root=Drive;

int Numerator=0;

TStringList *Y=new TStringList();

TStringList *X=new TStringList();

//Âûÿñíèòü íîìåð ïîòîêà ñ property

int PropertyFlowNum=-1;

Y->LoadFromFile(ChangeFileExt(FileName,".hdr"));

for(int i=1;i<=Y->Count/2;i++){

X->CommaText=Y->Strings[2*i];

if(X->Strings[0].ToInt()){

PropertyFlowNum=i-1;

break;

}

}

Y->Clear();

X->Clear();

Drive->OutPres[0]=ChangeFileExt(ExtractFileName(FileName),AnsiString());

Y->LoadFromFile(FileName);

bool IsGroup;

for(int i=0;i<Y->Count;i++){

X->CommaText=Y->Strings[i];

Numerator++;

IsGroup=false;

if(Price&&PropertyFlowNum!=-1){

if(X->Count>PropertyFlowNum){

if(!IsQuantity(X->Strings[PropertyFlowNum]))

IsGroup=true;

}else

IsGroup=true;

}else{

for(int fl=0;fl<FlowNum&&fl<X->Count;fl++)

if(!IsQuantity(X->Strings[PropertyFlowNum])){

IsGroup=true;

break;

}

}

if(IsGroup)

New=(Drive=Root->AddChild(!Price*Numerator,X->Strings[0]));

else

New=Drive->AddChild(!Price*Numerator,X->Strings[0]);

New->IsGroup=IsGroup;

for(int j=0;j<X->Count&&j<FlowNum;j++){

New->OutPres[j]=X->Strings[j];

New->IP.Init(X->Strings[j]);

}

if(ind) ind->Position=Numerator;

}

delete X,Y;

ind->Position=0;

return(Root);

}

bool TPositionTree::Action(WalkAction ActionIndex,void *Data){

switch(ActionIndex){

case aInit:{IP.Clear();

for(int i=0;i<FlowNum;i++)

IP.Init(OutPres[i]);

return(false);

}

case aToList:{

if(!IsGroup)

((TList *)Data)->Add(this);

return(false);

}

}

return(false);

}

TPositionTree *TPositionTree::TreeWalk(WalkAction ActionIndex,void *Data){

if(Depth==0)

return(Down->TreeWalk(ActionIndex,Data));

if(Action(ActionIndex,Data))

return(this);

TPositionTree *Result;

if(Down)

if((Result=Down->TreeWalk(ActionIndex,Data))!=NULL)

return(Result);

if(Next)

if((Result=Next->TreeWalk(ActionIndex,Data))!=NULL)

return(Result);

return(NULL);

}

AnsiString TPositionTree::OP(){

AnsiString Returned=AnsiString();

for(int i=0;i<IP.FlowCount;i++){

Returned=Returned+OutPres[i];


Страница: