Namespacing and Lib for files

This commit is contained in:
2022-09-06 21:15:01 +02:00
parent 2510f4968c
commit 3559b124a7
20 changed files with 262 additions and 119 deletions
+90
View File
@@ -0,0 +1,90 @@
file(GLOB file CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/file/*.cpp)
add_library(file SHARED
${file}
)
target_include_directories(file PRIVATE
${CMAKE_SOURCE_DIR}/file/include
${CMAKE_SOURCE_DIR}/simdata/include
${CMAKE_SOURCE_DIR}/utilities/include
)
set_target_properties(file PROPERTIES
PUBLIC_HEADER ${CMAKE_SOURCE_DIR}/file/include
)
target_compile_options(file PRIVATE
-Wall
-Wextra
-pedantic
)
if(DEBUG)
target_compile_options(file PRIVATE
-g
)
target_link_options(file PRIVATE
-g
)
else()
target_compile_options(file PRIVATE
-O2
)
endif()
if(APPLE)
message("Building file for MacOSX Universal into ${PROJECT_BINARY_DIR}/${PLUGIN_NAME}")
set_target_properties(file PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}"
BUILD_WITH_INSTALL_NAME_DIR TRUE
)
target_compile_options(file PRIVATE
"SHELL:-arch i386"
"SHELL:-arch x86_64"
)
target_link_options(file PRIVATE
"SHELL:-arch i386"
"SHELL:-arch x86_64"
)
target_link_libraries(file PRIVATE
"-framework Security"
)
elseif(UNIX)
message("Building file for Linux ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
set_target_properties(file PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
)
target_compile_options(file PRIVATE
-nodefaultlibs
)
if(BIT STREQUAL "32")
target_compile_options(file PRIVATE
-m32
)
target_link_options(file PRIVATE
-m32
)
endif()
elseif(WIN32)
message("Building file for Windows ${BIT} into ${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}")
set_target_properties(file PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/Plugin/${PLUGIN_NAME}/${BIT}"
)
if(DEBUG)
target_compile_options(file PRIVATE
-gcodeview
)
target_link_options(file PRIVATE
-Wl,-pdb=
)
endif()
target_link_options(file PRIVATE
-static-libgcc
-static-libstdc++
)
endif()
+43
View File
@@ -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
+52
View File
@@ -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
+12
View File
@@ -0,0 +1,12 @@
#include "pathRecording.h"
namespace germanairlinesva_recording
{
void PathRecording::addSegment(PathSegment segment)
{
file.resize(file.size() + segment.getBinaryLength());
std::uint8_t *bufPtr = 6 + file.data() + count * segment.getBinaryLength();
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
count++;
}
} // namespace germanairlinesva_recording
+28
View File
@@ -0,0 +1,28 @@
#include "pathSegment.h"
namespace germanairlinesva_recording
{
PathSegment::PathSegment(std::uint32_t time,
std::uint16_t altitude,
std::uint16_t groundSpeed,
struct germanairlinesva_geodata::point coordinates)
{
this->time = time;
this->altitude = altitude;
this->groundSpeed = groundSpeed;
this->coordinates = coordinates;
file = std::vector<std::uint8_t>(
sizeof(this->time) + sizeof(this->altitude) +
sizeof(this->groundSpeed) + sizeof(this->coordinates),
0);
std::uint8_t *bufPtr = file.data();
memcpy(bufPtr, &this->time, sizeof(this->time));
bufPtr += sizeof(this->time);
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
bufPtr += sizeof(this->altitude);
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
bufPtr += sizeof(this->groundSpeed);
memcpy(bufPtr, &this->coordinates, sizeof(this->coordinates));
};
} // namespace germanairlinesva_recording
-62
View File
@@ -1,62 +0,0 @@
#ifndef GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
#define GERMANAIRLINESVA_GACONNECTOR_PATHSEGMENT_H
#include <cstdint>
#include <cstring>
#include <vector>
/*
* Length in bytes: 20
*
* UINT16 | UINT16 | DOUBLE | DOUBLE |
* ---------+-------------+----------+-----------+
* ALTITUDE | GROUNDSPEED | LATITUDE | LONGITUDE |
*/
class PathSegment
{
private:
std::uint16_t altitude = 0;
std::uint16_t groundSpeed = 0;
double latitude = 0;
double longitude = 0;
std::vector<std::uint8_t> file;
public:
PathSegment() = default;
PathSegment(std::uint16_t altitude,
std::uint16_t groundSpeed,
double latitude,
double longitude)
{
this->altitude = altitude;
this->groundSpeed = groundSpeed;
this->latitude = latitude;
this->longitude = longitude;
file = std::vector<std::uint8_t>(20, 0);
std::uint8_t *bufPtr = file.data();
memcpy(bufPtr, &this->altitude, sizeof(this->altitude));
bufPtr += sizeof(this->altitude);
memcpy(bufPtr, &this->groundSpeed, sizeof(this->groundSpeed));
bufPtr += sizeof(this->groundSpeed);
memcpy(bufPtr, &this->latitude, sizeof(this->latitude));
bufPtr += sizeof(this->latitude);
memcpy(bufPtr, &this->longitude, sizeof(this->longitude));
}
std::uint8_t *getBinaryData() { return file.data(); }
std::size_t getBinaryLength() { return file.size(); }
friend bool operator==(const PathSegment &lhs, const PathSegment &rhs)
{
return lhs.altitude == rhs.altitude &&
lhs.groundSpeed == rhs.groundSpeed &&
lhs.latitude == rhs.latitude && lhs.longitude == rhs.longitude;
}
friend bool operator!=(const PathSegment &lhs, const PathSegment &rhs)
{
return !(lhs == rhs);
}
};
#endif
-29
View File
@@ -1,29 +0,0 @@
#ifndef GERMANAIRLINESVA_GACONNECTOR_RECORDINGPATH_H
#define GERMANAIRLINESVA_GACONNECTOR_RECORDINGPATH_H
#include <cstdint>
#include <cstring>
#include <vector>
#include "pathSegment.hpp"
class Path
{
private:
std::uint64_t count = 0;
std::vector<std::uint8_t> file;
public:
void addSegment(PathSegment segment)
{
file.resize(file.size() + segment.getBinaryLength());
std::uint8_t *bufPtr = file.data() + count * segment.getBinaryLength();
memcpy(bufPtr, segment.getBinaryData(), segment.getBinaryLength());
count++;
}
std::uint8_t *getBinaryData() { return file.data(); }
std::size_t getBinaryLength() { return file.size(); }
};
#endif