65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
#include <aladin/logbook.hpp>
|
|
#include <common/qsort.hpp>
|
|
#include <common/file.hpp>
|
|
|
|
LogBook::LogBook()
|
|
{
|
|
}
|
|
|
|
LogBook::~LogBook()
|
|
{
|
|
}
|
|
|
|
bool LogBook::readFrom(RawData &array,CurrentStatus &status)
|
|
{
|
|
QuickSort<DiveLog> quickSort;
|
|
int index=StartAddress;
|
|
|
|
for(int logIndex=0;logIndex<MaxLogs;logIndex++)
|
|
{
|
|
DiveLog diveLog;
|
|
if(diveLog.readFrom(array,index)&&!haveDive(diveLog))insert(&diveLog);
|
|
}
|
|
quickSort.sortItems(*this,SortOptions::Descending);
|
|
return true;
|
|
}
|
|
|
|
bool LogBook::readFrom(File &inFile)
|
|
{
|
|
int count;
|
|
|
|
if(!inFile.isOkay())return false;
|
|
if(!inFile.read(&count,sizeof(count)))return false;
|
|
for(int index=0;index<count;index++)
|
|
{
|
|
insert(&DiveLog());
|
|
DiveLog &diveLog=operator[](size()-1);
|
|
if(!diveLog.readFrom(inFile))return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool LogBook::writeTo(File &outFile)
|
|
{
|
|
int count;
|
|
|
|
if(!outFile.isOkay())return false;
|
|
count=size();
|
|
if(!outFile.write(&count,sizeof(count)))return false;
|
|
for(int index=0;index<count;index++)
|
|
{
|
|
if(!operator[](index).writeTo(outFile))return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool LogBook::haveDive(DiveLog &diveLog)
|
|
{
|
|
for(int index=0;index<size();index++)
|
|
{
|
|
if(operator[](index)==diveLog)return true;
|
|
}
|
|
return false;
|
|
}
|
|
|