template<class T>
Database<T>::~Database()
{
// Copy nonnull records to new file
// Delete old data file
// rename new file old filename
fstream dbout;
T tmp;
database.open(fName,ios::in|ios::out|ios::binary);
dbout.open("tmpfile",ios::out|ios::binary);
database.clear();
while (true)
{
tmp.readFromFile(database);
if (database.eof())
break;
if (!tmp.isNull())
{
dbout.clear();
dbout.seekp(0,ios::end);
tmp.writeToFile(dbout);
}
}
dbout.close();
database.close();
std::remove(fName);
std::rename("tmpfile",fName);