Future proofed file read/write
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_LOGBOOK_H
|
||||
#define GERMANAIRLINESVA_FILE_LOGBOOK_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "constants.h"
|
||||
#include "helpers.hpp"
|
||||
#include "logbookEntry.h"
|
||||
#include "util.hpp"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace logbook
|
||||
{
|
||||
/*
|
||||
* Logbook Header (6)
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAL | VERSION
|
||||
*
|
||||
* Logbook Entries (n)
|
||||
* LOGBOOKENTRY[]
|
||||
*/
|
||||
class Logbook
|
||||
{
|
||||
private:
|
||||
std::vector<LogbookEntry> entries;
|
||||
|
||||
void fromFile(const std::string &file);
|
||||
void readVersion1(std::ifstream &in);
|
||||
|
||||
public:
|
||||
Logbook();
|
||||
|
||||
template <class... Args> inline void addEntry(Args &&...args)
|
||||
{
|
||||
this->entries.emplace_back(std::forward<Args>(args)...);
|
||||
}
|
||||
void toFile() const;
|
||||
};
|
||||
} // namespace logbook
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
#endif
|
||||
@@ -0,0 +1,158 @@
|
||||
#ifndef GERMANAIRLINESVA_FILE_LOGBOOKENTRY_H
|
||||
#define GERMANAIRLINESVA_FILE_LOGBOOKENTRY_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace germanairlinesva
|
||||
{
|
||||
namespace file
|
||||
{
|
||||
namespace logbook
|
||||
{
|
||||
/*
|
||||
* Preamble (24)
|
||||
* CHAR[10] | CHAR[4] | CHAR[4] | CHAR[6]
|
||||
* ---------+---------------+----------+-------------
|
||||
* DATE | FLIGHT NUMBER | AIRCRAFT | REGISTRATION
|
||||
|
||||
* Departure Airport Name (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Departure Gate Name (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Departure Runway Name (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Arrival Airport Name (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Arrival Gate Name (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Arrival Runway Name (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Times (24)
|
||||
* CHAR[5] | CHAR[5] | CHAR[5] | CHAR[4] | FLOAT
|
||||
* ----------+---------------+--------------+---------------+------
|
||||
* OFF BLOCK | TAKEOFF (OUT) | LANDING (ON) | ON BLOCK (IN) | TOTAL
|
||||
|
||||
* Fuels (16)
|
||||
* FLOAT | FLOAT | FLOAT | FLOAT
|
||||
* ---------+-----------+---------+------
|
||||
* TAXI OUT | IN FLIGHT | TAXI IN | TOTAL
|
||||
|
||||
* Distances (16)
|
||||
* FLOAT | FLOAT | FLOAT |FLOAT
|
||||
* ---------+-----------+---------+-----
|
||||
* TAXI OUT | IN FLIGHT | TAXI IN |TOTAL
|
||||
|
||||
* Landing (9)
|
||||
* FLOAT | CHAR | FLOAT
|
||||
* ---------+---------- +------------
|
||||
* MAX RATE | TOUCHDOWNS | MAX G-FORCE
|
||||
|
||||
* Recording Filename (2...256)
|
||||
* UINT8 | CHAR[]
|
||||
* -------+-------
|
||||
* STRLEN | STRING
|
||||
|
||||
* Postamble (5)
|
||||
* FLOAT | BITFIELD
|
||||
* -------+---------
|
||||
* POINTS | FLAGS
|
||||
|
||||
* Flags Bitfield
|
||||
* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
|
||||
* ----+-----+-----+-----+-----+-----+-----+------
|
||||
* NIL | NIL | NIL | NIL | NIL | NIL | NIL | FILED
|
||||
*/
|
||||
class LogbookEntry
|
||||
{
|
||||
private:
|
||||
std::string date;
|
||||
std::string flightNumber;
|
||||
std::string aircraftType;
|
||||
std::string aircraftRegistration;
|
||||
std::string departureAirport;
|
||||
std::string departureGate;
|
||||
std::string departureRunway;
|
||||
std::string arrivalAirport;
|
||||
std::string arrivalGate;
|
||||
std::string arrivalRunway;
|
||||
std::string offBlockTime;
|
||||
std::string outTime;
|
||||
std::string onTime;
|
||||
std::string onBlockTime;
|
||||
float totalFlightTime;
|
||||
float taxiOutFuel;
|
||||
float inFlightFuel;
|
||||
float taxiInFuel;
|
||||
float totalFuel;
|
||||
float taxiOutDistance;
|
||||
float inFlightDistance;
|
||||
float taxiInDistance;
|
||||
float totalDistance;
|
||||
float maxLandingRate;
|
||||
std::uint8_t touchdowns;
|
||||
float maxLandingGees;
|
||||
std::string recordingFilename;
|
||||
float points;
|
||||
std::uint8_t flags;
|
||||
|
||||
public:
|
||||
LogbookEntry(std::string date,
|
||||
std::string flightNumber,
|
||||
std::string aircraftType,
|
||||
std::string aircraftRegistration,
|
||||
std::string departureAirport,
|
||||
std::string departureGate,
|
||||
std::string departureRunway,
|
||||
std::string arrivalAirport,
|
||||
std::string arrivalGate,
|
||||
std::string arrivalRunway,
|
||||
std::string offBlockTime,
|
||||
std::string outTime,
|
||||
std::string onTime,
|
||||
std::string onBlockTime,
|
||||
float totalFlightTime,
|
||||
float taxiOutFuel,
|
||||
float inFlightFuel,
|
||||
float taxiInFuel,
|
||||
float totalFuel,
|
||||
float taxiOutDistance,
|
||||
float inFlightDistance,
|
||||
float taxiInDistance,
|
||||
float totalDistance,
|
||||
float maxLandingRate,
|
||||
std::uint8_t touchdowns,
|
||||
float maxLandingGees,
|
||||
std::string recordingFilename,
|
||||
float points,
|
||||
std::uint8_t flags);
|
||||
|
||||
void toFile(std::ofstream &out) const;
|
||||
};
|
||||
} // namespace logbook
|
||||
} // namespace file
|
||||
} // namespace germanairlinesva
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user