Header only File Lib

This commit is contained in:
2022-09-24 13:39:26 +02:00
parent 9deae93fdd
commit 46214e9dc3
20 changed files with 396 additions and 590 deletions
@@ -1,12 +1,12 @@
#ifndef GERMANAIRLINESVA_FILE_RECORDING_H
#define GERMANAIRLINESVA_FILE_RECORDING_H
#ifndef GERMANAIRLINESVA_FILE_RECORDING_RECORDING_H
#define GERMANAIRLINESVA_FILE_RECORDING_RECORDING_H
#include <cstdint>
#include <fstream>
#include <vector>
#include "constants.h"
#include "recordingEntry.h"
#include "recordingEntry.hpp"
namespace germanairlinesva
{
@@ -36,7 +36,18 @@ namespace file
{
this->entries.emplace_back(std::forward<Args>(args)...);
}
void toFile(std::string fileName) const;
inline void toFile(std::string fileName) const
{
std::ofstream out(BASE_DIRECTORY RECORDING_DIRECTORY + fileName,
std::fstream::binary);
char header[] = {'V', 'G', 'A', 'R', '\0', 1};
out.write(header, 6);
for (const RecordingEntry &entry : this->entries) {
entry.toFile(out);
}
out.close();
}
};
} // namespace recording
} // namespace file
@@ -24,20 +24,28 @@ namespace file
{
private:
std::uint32_t time;
std::uint16_t altitude = 0;
std::uint16_t groundSpeed = 0;
struct geodata::point coordinates {
NAN, NAN
};
std::uint16_t altitude;
std::uint16_t groundSpeed;
struct geodata::point coordinates;
public:
RecordingEntry() = default;
RecordingEntry(std::uint32_t time,
std::uint16_t altitude,
std::uint16_t groundSpeed,
struct geodata::point coordinates);
inline RecordingEntry() = default;
inline RecordingEntry(std::uint32_t time,
std::uint16_t altitude,
std::uint16_t groundSpeed,
struct geodata::point coordinates)
: time(time), altitude(altitude), groundSpeed(groundSpeed),
coordinates(coordinates)
{
}
void toFile(std::ofstream &out) const;
inline void toFile(std::ofstream &out) const
{
write<decltype(this->time)>(out, this->time);
write<decltype(this->altitude)>(out, this->altitude);
write<decltype(this->groundSpeed)>(out, this->groundSpeed);
write<decltype(this->coordinates)>(out, this->coordinates);
}
friend inline bool operator==(const RecordingEntry &lhs,
const RecordingEntry &rhs)