Namespacing and Lib for files
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_CONFIG_H
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace germanairlinesva_config
|
||||
{
|
||||
static inline std::map<std::string, std::string>
|
||||
readConfig(const std::string &file)
|
||||
{
|
||||
std::ifstream config(file);
|
||||
std::map<std::string, std::string> settings;
|
||||
|
||||
std::string line;
|
||||
while (std::getline(config, line)) {
|
||||
std::vector<std::string> fields = germanairlinesva_util::split(line, '=');
|
||||
if (fields.size() >= 2) {
|
||||
germanairlinesva_util::trim(fields[0]);
|
||||
germanairlinesva_util::trim(fields[1]);
|
||||
settings[fields[0]] = fields[1];
|
||||
}
|
||||
}
|
||||
|
||||
config.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
static inline void
|
||||
writeConfig(const std::map<std::string, std::string> &config,
|
||||
const std::string &file)
|
||||
{
|
||||
std::ofstream cfg(file);
|
||||
for (const std::pair<const std::string, std::string> &entry : config) {
|
||||
cfg << entry.first << '=' << entry.second << '\n';
|
||||
}
|
||||
cfg.close();
|
||||
}
|
||||
} // namespace germanairlinesva_config
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDING_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_RECORDING_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "pathSegment.h"
|
||||
|
||||
#define CURRENT_VERSION 1
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
/*
|
||||
* Header
|
||||
*
|
||||
* CHAR[5] | UINT8
|
||||
* --------+--------
|
||||
* VGAR | VERSION
|
||||
*/
|
||||
/*
|
||||
* Path Recording
|
||||
*
|
||||
* PATHSEGMENT[]
|
||||
* -------------
|
||||
* SEGMENTS
|
||||
*/
|
||||
class PathRecording
|
||||
{
|
||||
private:
|
||||
std::uint64_t count = 0;
|
||||
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', 0, CURRENT_VERSION};
|
||||
|
||||
public:
|
||||
void addSegment(PathSegment segment);
|
||||
|
||||
inline std::uint8_t *getBinaryData() { return file.data(); }
|
||||
inline std::size_t getBinaryLength() { return file.size(); }
|
||||
};
|
||||
|
||||
} // namespace germanairlinesva_recording
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "geodata.h"
|
||||
|
||||
namespace germanairlinesva_recording
|
||||
{
|
||||
/*
|
||||
* UINT32 | UINT16 | UINT16 | COORDINATES
|
||||
* -------+----------+-------------+------------
|
||||
* TIME | ALTITUDE | GROUNDSPEED | POINT
|
||||
*/
|
||||
class PathSegment
|
||||
{
|
||||
private:
|
||||
std::uint32_t time = 0;
|
||||
std::uint16_t altitude = 0;
|
||||
std::uint16_t groundSpeed = 0;
|
||||
struct germanairlinesva_geodata::point coordinates;
|
||||
std::vector<std::uint8_t> file;
|
||||
|
||||
public:
|
||||
PathSegment() = default;
|
||||
PathSegment(std::uint32_t time,
|
||||
std::uint16_t altitude,
|
||||
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(); }
|
||||
|
||||
friend inline bool operator==(const PathSegment &lhs,
|
||||
const PathSegment &rhs)
|
||||
{
|
||||
return lhs.altitude == rhs.altitude &&
|
||||
lhs.groundSpeed == rhs.groundSpeed &&
|
||||
lhs.coordinates.latitude == rhs.coordinates.latitude &&
|
||||
lhs.coordinates.longitude == rhs.coordinates.longitude;
|
||||
}
|
||||
friend inline bool operator!=(const PathSegment &lhs,
|
||||
const PathSegment &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
};
|
||||
} // namespace germanairlinesva_recording
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user