56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#ifndef GERMANAIRLINESVA_GACONNECTOR_GATE_H
|
|
#define GERMANAIRLINESVA_GACONNECTOR_GATE_H
|
|
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <streambuf>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
/*
|
|
* Representation of X-Plane gate
|
|
* Heading in degrees (0...360)
|
|
*
|
|
* Length in bytes: 18 + length of designator
|
|
* Designator must be null terminated
|
|
*
|
|
* UINT8 | CHAR[] | DOUBLE | DOUBLE | UINT8
|
|
* ------+------------+--------+--------+------
|
|
* LEN | DESIGNATOR | LAT | LON | WIDTH
|
|
*/
|
|
class Gate
|
|
{
|
|
private:
|
|
std::string designator;
|
|
double latitude;
|
|
double longitude;
|
|
std::vector<std::uint8_t> file;
|
|
|
|
public:
|
|
Gate(const std::string &designator, double latitude, double longitude)
|
|
{
|
|
|
|
this->designator = designator;
|
|
this->latitude = latitude;
|
|
this->longitude = longitude;
|
|
|
|
file = std::vector<std::uint8_t>(18 + this->designator.length(), 0);
|
|
std::uint8_t *bufPtr = file.data();
|
|
memset(bufPtr,
|
|
static_cast<std::uint8_t>(this->designator.length()),
|
|
sizeof(std::uint8_t));
|
|
bufPtr++; // Designator length
|
|
memcpy(bufPtr, this->designator.c_str(), this->designator.length());
|
|
bufPtr +=
|
|
this->designator.length() + 1; // Designator plus null termination
|
|
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
|
|
bufPtr += 8; // Latitude
|
|
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
|
|
}
|
|
|
|
std::uint8_t *getBinaryData() { return this->file.data(); }
|
|
std::size_t getBinaryLength() { return this->file.size(); }
|
|
};
|
|
|
|
#endif |