//--------------------------------------------------------------------------- #include #pragma hdrstop #include "FileList.h" #include "BinaryFile.h" //--------------------------------------------------------------------------- #pragma package(smart_init) // list operations template void FileList::Open(AnsiString FileName) // open if existing file, create otherwise { ListInfo H; BF.Assign(FileName); if (FileExists(FileName)) { BF.Open(); BF.ReadHeader(H); Current = H.Head; Previous = -1; } else { ListInfo H; BF.Create(); H.Head = -1; H.DeleteList = -1; Current = -1; Previous = -1; BF.WriteHeader(H); } } template void FileList::Close() // open if existing file, create otherwise { BF.Close();} template void FileList::Insert(LRecord Item) // insert record in order { /*int NewRecNo, CurNo, PrevNo; ListNode NewRec, Cur, Prev; ListInfo H; // find file address of new record BF.ReadHeader(H); if (H.DeleteList != -1) { NewRecNo = H.DeleteList; BF.Read(Cur, H.DeleteList); H.DeleteList = Cur.Next; BF.WriteHeader(H); } // if else NewRecNo = BF.Size(); // determine location in list of new record and insert if (H.Head == -1) {H.Head = NewRecNo; NewRec.Next = -1; StrLCopy((char*)NewRec.item,(char*)Item, sizeof(LRecord)); BF.Write(NewRec, NewRecNo); } // if else {PrevNo = -1; CurNo = H.Head; BF.Read(Cur, CurNo); while (Cur.item < Item) { PrevNo = Current; if (Cur.Next == -1) break; else { Current = Cur.Next; Prev = Cur; BF.Read(Cur, CurNo); { // else } // while } // else if (PrevNo == -1) // insert into head of list { NewRec.Next = H.Head; StrLCopy((char*)NewRec.item,(char*)Item, sizeof(LRecord)); H.Head = NewRecNo; BF.WriteHeader(H); BF.Write(NewRec, NewRecNo); } // if else // insert into body of list { NewRec.Next = CurNo; StrLCopy((char*)NewRec.item,(char*)Item, sizeof(LRecord)); Prev.Next = NewRecNo; BF.Write(Prev, PrevNo); BF.Write(NewRec, NewRecNo); } // else */ } // insert template void FileList::Search(LRecord &SearchItem) // find first record that is at or after SearchItem {} template void FileList::GetCurrent(LRecord &Item) // read current record { ListNode LItem; BF.Read(LItem, Current); Item = LItem.item;} template void FileList::GetNext(LRecord &Item) // read next record { if (!this.AtEnd()) { ListNode temp; BF.Read(temp, Current); Previous = Current; Current = temp.Next; BF.Read(temp, Current); Item = temp.item; } } template void FileList::GetFirst(LRecord &Item) // read first record { ListNode temp; Current = Head; Previous = -1; BF.Read(temp, Current) Item = temp.item; } template void FileList::Delete() // delete current record {} template void FileList::ModifyCurrent(LRecord &Item) //rewrite current record { ListNode temp; BF.Read(temp, Current); if (temp.item == Item) { temp.item = Item; BF.Write(temp, Current); } else { this.Delete(); this.Insert(Item); } } template bool FileList::AtEnd() // true if current is last record in list. { ListNode temp; BF.Read(temp, Current); return (temp.next == -1);} template void FileList::Pack() // rewrites list with list order in order. {}