-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ESE file parser to extract [POSITIONS]
- Loading branch information
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "stdafx.h" | ||
#include "ESEHandler.h" | ||
#include <filesystem> | ||
#include <fstream> | ||
|
||
std::vector<std::string> ESEHandler::path_to_ese; | ||
std::vector<ESEPositionItem> ESEHandler::positions; | ||
|
||
bool ESEHandler::LocateESEFile(std::string relative_path_to_ese) | ||
{ | ||
path_to_ese.clear(); | ||
for (auto& file : std::filesystem::directory_iterator(relative_path_to_ese)) | ||
{ | ||
if (file.is_regular_file() && stricmp(file.path().filename().extension().string().c_str(), ".ese") == 0) | ||
{ | ||
path_to_ese.push_back(file.path().string()); | ||
} | ||
} | ||
return path_to_ese.size() > 0; | ||
} | ||
|
||
int ESEHandler::ParsePositions(void) | ||
{ | ||
if (path_to_ese.size() > 0) | ||
{ | ||
for (auto& file : path_to_ese) | ||
{ | ||
bool start_pos = false; | ||
std::ifstream fs(file); | ||
std::string line; | ||
while (std::getline(fs, line)) | ||
{ | ||
if (line == "[POSITIONS]") | ||
{ | ||
start_pos = true; | ||
continue; | ||
} | ||
if (!start_pos) continue; | ||
|
||
if (!(line[0] >= 'A' && line[0] <= 'Z')) | ||
{ | ||
if (line[0] == '[') break; | ||
continue; | ||
} | ||
|
||
ESEPositionItem pos; | ||
int idx1 = line.find_first_of(':'); | ||
pos.callsign = line.substr(0, idx1); | ||
int idx2 = line.find_first_of(':', idx1 + 1); | ||
pos.radio_callsign = line.substr(idx1 + 1, idx2 - idx1 - 1); | ||
idx1 = line.find_first_of(':', idx2 + 1); | ||
pos.frequency = line.substr(idx2 + 1, idx1 - idx2 - 1); | ||
positions.push_back(pos); | ||
} | ||
fs.close(); | ||
} | ||
} | ||
return positions.size(); | ||
} | ||
|
||
void ESEHandler::GetRadioCallsigns(std::map<std::string, std::string>& rcs) | ||
{ | ||
rcs.clear(); | ||
for (auto& pos : positions) | ||
{ | ||
rcs.insert(std::pair<std::string, std::string>(pos.callsign, pos.radio_callsign)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Copyright(C) 2023-2024 Kirollos Nashaat | ||
This program is free software : you can redistribute it and /or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program.If not, see < https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
#include <map> | ||
|
||
|
||
struct ESEPositionItem | ||
{ | ||
std::string callsign; | ||
std::string radio_callsign; | ||
std::string frequency; | ||
}; | ||
|
||
class ESEHandler | ||
{ | ||
private: | ||
static std::vector<std::string> path_to_ese; | ||
static std::vector<ESEPositionItem> positions; | ||
public: | ||
static bool LocateESEFile(std::string relative_path_to_ese); | ||
static int ParsePositions(void); | ||
static void GetRadioCallsigns(std::map<std::string, std::string>& rcs); | ||
}; |