96 lines
2.6 KiB
C++
96 lines
2.6 KiB
C++
#include <aladin/diveprofile.hpp>
|
|
#include <common/file.hpp>
|
|
|
|
DiveProfile::DiveProfile(void)
|
|
{
|
|
}
|
|
|
|
DiveProfile::DiveProfile(const DiveProfile &diveProfile)
|
|
{
|
|
*this=diveProfile;
|
|
}
|
|
|
|
DiveProfile::~DiveProfile()
|
|
{
|
|
}
|
|
|
|
DiveProfile &DiveProfile::operator=(const DiveProfile &diveProfile)
|
|
{
|
|
remove();
|
|
for(int index=0;index<diveProfile.size();index++)
|
|
{
|
|
ProfileData &profileData=((Block<ProfileData>&)diveProfile)[index];
|
|
insert(&ProfileData(profileData.getDepth(),profileData.getStageTime(),profileData.getWarning()));
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool DiveProfile::operator==(const DiveProfile &diveProfile)const
|
|
{
|
|
if(size()!=diveProfile.size())return false;
|
|
for(int index=0;index<diveProfile.size();index++)
|
|
{
|
|
ProfileData &profileDataSrc=((Block<ProfileData>&)diveProfile)[index];
|
|
ProfileData &profileDataDst=((Block<ProfileData>&)*this)[index];
|
|
if(!(profileDataSrc==profileDataDst))return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool DiveProfile::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(&ProfileData());
|
|
ProfileData &profileData=operator[](size()-1);
|
|
if(!profileData.readFrom(inFile))return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool DiveProfile::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;
|
|
}
|
|
|
|
String ProfileData::getWarningString(void)const
|
|
{
|
|
String strWarning;
|
|
if(mWarning&TransmitErrorAirPressure)strWarning+="transmit error air pressure.";
|
|
if(mWarning&WorkTooHard){if(!strWarning.isNull())strWarning+=",";strWarning+="work too hard.";}
|
|
if(mWarning&CeilingViolationOfDeco){if(!strWarning.isNull())strWarning+=",";strWarning+="ceiling violation of deco.";}
|
|
if(mWarning&AscentTooFast){if(!strWarning.isNull())strWarning+=",";strWarning+="ascent too fast.";}
|
|
if(mWarning&RemainingBottomTimeTooShort){if(!strWarning.isNull())strWarning+=",";strWarning+="remaining bottom time too short.";}
|
|
if(mWarning&DecoStop){if(!strWarning.isNull())strWarning+=",";strWarning+="decompression stop.";}
|
|
if(!mWarning)strWarning+="no warnings";
|
|
return strWarning;
|
|
}
|
|
|
|
int DiveProfile::getMaxDepth(void)const
|
|
{
|
|
int maxDepth=0;
|
|
int count=size();
|
|
for(int index=0;index<count;index++)
|
|
{
|
|
if(((Block<ProfileData>&)*this).operator[](index).getDepth()>maxDepth)maxDepth=((Block<ProfileData>&)*this).operator[](index).getDepth();
|
|
}
|
|
return maxDepth;
|
|
}
|
|
|
|
int DiveProfile::getBottomTime(void)const
|
|
{
|
|
return ((Block<ProfileData>&)*this).operator[](size()-1).getStageTime()/60;
|
|
}
|