Consts and references

This commit is contained in:
2022-09-09 20:10:38 +02:00
parent b050c23577
commit 699e2a4784
16 changed files with 156 additions and 179 deletions
+8 -3
View File
@@ -4,6 +4,7 @@
#include <cstdint>
#include <fstream>
#include <string>
#include <utility>
#include <vector>
#include "constants.h"
@@ -24,15 +25,19 @@ namespace germanairlinesva_logbook
class Logbook
{
private:
std::vector<std::uint8_t> file;
std::vector<LogbookEntry> entries;
void fromFile(const std::string &file);
void readVersion1(std::ifstream &in);
public:
Logbook();
void addEntry(LogbookEntry entry);
void toFile();
template <class... Args> inline void addEntry(Args &&...args)
{
this->entries.emplace_back(std::forward<Args>(args)...);
}
void toFile() const;
};
} // namespace germanairlinesva_logbook
+8 -21
View File
@@ -71,14 +71,14 @@ namespace germanairlinesva_logbook
* STRLEN | STRING
* Postamble (5)
* FLOAT32 | BITFIELD
* --------------+---
* POINTS | FLAGS
* FLOAT | BITFIELD
* -------+---------
* POINTS | FLAGS
* Flags Bitfield
* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* ---+---+---+---+---+---+---+-----
* NIL|NIL|NIL|NIL|NIL|NIL|NIL|FILED
* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
* ----+-----+-----+-----+-----+-----+-----+------
* NIL | NIL | NIL | NIL | NIL | NIL | NIL | FILED
*/
class LogbookEntry
{
@@ -145,21 +145,8 @@ namespace germanairlinesva_logbook
float points,
std::uint8_t flags);
inline std::uint8_t *getBinaryData() { return file.data(); }
inline std::size_t getBinaryLength() { return file.size(); }
std::string to_string() const
{
std::ostringstream str;
// TO STR
return str.str();
}
friend inline std::ostream &operator<<(std::ostream &os,
const LogbookEntry &gate)
{
return os << gate.to_string();
}
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
};
} // namespace germanairlinesva_logbook
+3 -3
View File
@@ -28,10 +28,10 @@ namespace germanairlinesva_recording
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
public:
void addSegment(PathSegment segment);
void addSegment(const PathSegment &segment);
inline std::uint8_t *getBinaryData() { return file.data(); }
inline std::size_t getBinaryLength() { return file.size(); }
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
};
} // namespace germanairlinesva_recording
+2 -2
View File
@@ -31,8 +31,8 @@ namespace germanairlinesva_recording
std::uint16_t groundSpeed,
struct germanairlinesva_geodata::point coordinates);
inline std::uint8_t *getBinaryData() { return file.data(); }
inline std::size_t getBinaryLength() { return file.size(); }
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
friend inline bool operator==(const PathSegment &lhs,
const PathSegment &rhs)
+10 -27
View File
@@ -4,13 +4,8 @@ namespace germanairlinesva_logbook
{
Logbook::Logbook()
{
if (germanairlinesva_util::fileExists(
XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
if (germanairlinesva_util::fileExists(XPLANE_PLUGIN_DIRECTORY LOGBOOK)) {
this->fromFile(XPLANE_PLUGIN_DIRECTORY LOGBOOK);
} else {
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
this->file.resize(6);
std::memcpy(file.data(), &header, 6);
}
}
@@ -32,30 +27,18 @@ namespace germanairlinesva_logbook
}
}
void Logbook::readVersion1(std::ifstream &in)
{
in.seekg(0, std::fstream::end);
std::streampos fileSize = in.tellg();
in.seekg(0, std::ios::beg);
void Logbook::readVersion1(std::ifstream &in) {}
this->file.resize(fileSize);
in.read(reinterpret_cast<char *>(this->file.data()), fileSize);
in.close();
}
void Logbook::addEntry(LogbookEntry entry)
void Logbook::toFile() const
{
std::size_t size = file.size();
file.resize(file.size() + entry.getBinaryLength());
std::uint8_t *bufPtr = file.data() + size;
std::memcpy(bufPtr, entry.getBinaryData(), entry.getBinaryLength());
}
void Logbook::toFile()
{
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK,
std::fstream::binary);
out.write(reinterpret_cast<char *>(this->file.data()), this->file.size());
std::ofstream out(XPLANE_PLUGIN_DIRECTORY LOGBOOK, std::fstream::binary);
char header[] = {'V', 'G', 'A', 'L', '\0', 1};
out.write(header, 6);
for (const LogbookEntry &entry : this->entries) {
out.write(reinterpret_cast<const char *>(entry.getBinaryData()),
entry.getBinaryLength());
}
out.close();
}
} // namespace germanairlinesva_logbook
+1 -1
View File
@@ -2,7 +2,7 @@
namespace germanairlinesva_recording
{
void PathRecording::addSegment(PathSegment segment)
void PathRecording::addSegment(const PathSegment &segment)
{
file.resize(file.size() + segment.getBinaryLength());
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();