2022-01-19 11:01:38 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
* Copyright (C) 2016 Furrtek
|
|
|
|
* Copyright (C) 2022 Arjan Onwezen
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* 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 2, 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; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DATABASE_H__
|
|
|
|
#define __DATABASE_H__
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "file.hpp"
|
|
|
|
|
|
|
|
class database {
|
2023-05-18 16:16:05 -04:00
|
|
|
public:
|
|
|
|
#define DATABASE_RECORD_FOUND 0 // record found in database
|
|
|
|
#define DATABASE_NOT_FOUND -1 // database not found / could not be opened
|
|
|
|
#define DATABASE_RECORD_NOT_FOUND -2 // record could not be found in database
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
struct MidDBRecord {
|
|
|
|
char country[32]; // country name
|
|
|
|
};
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
int retrieve_mid_record(MidDBRecord* record, std::string search_term);
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
struct AirlinesDBRecord {
|
|
|
|
char airline[32]; // airline name
|
|
|
|
char country[32]; // country name
|
|
|
|
};
|
2022-03-26 07:05:13 -04:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
int retrieve_airline_record(AirlinesDBRecord* record, std::string search_term);
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
struct AircraftDBRecord {
|
|
|
|
char aircraft_registration[9]; // aircraft registration
|
|
|
|
char aircraft_manufacturer[33]; // aircraft manufacturer
|
|
|
|
char aircraft_model[33]; // aircraft model
|
|
|
|
char icao_type[5]; // ICAO type descripton or when unavailable ICAO type designator
|
|
|
|
char aircraft_owner[33]; // aircraft owner
|
|
|
|
char aircraft_operator[33]; // aircraft operator
|
|
|
|
};
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
int retrieve_aircraft_record(AircraftDBRecord* record, std::string search_term);
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
private:
|
2024-03-25 03:44:49 -04:00
|
|
|
std::filesystem::path file_path = ""; // path including filename
|
|
|
|
int index_item_length = 0; // length of index item
|
|
|
|
int record_length = 0; // length of record
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
File db_file{};
|
|
|
|
int number_of_records = 0;
|
|
|
|
int position = 0;
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
char file_buffer[32]{0};
|
|
|
|
bool found = false;
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
int result = 0;
|
2022-01-19 11:01:38 -05:00
|
|
|
|
2024-03-25 03:44:49 -04:00
|
|
|
int retrieve_record(std::filesystem::path file_path, int index_item_length, int record_length, void* record, std::string search_term);
|
2022-01-19 11:01:38 -05:00
|
|
|
};
|
|
|
|
|
2023-05-18 16:16:05 -04:00
|
|
|
#endif /*__DATABASE_H__*/
|