FileManager (defined inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/yeremyacuna/LYNX/llms.txt
Use this file to discover all available pages before exploring further.
include/FileManager.h) is the persistence layer for LYNX. All data files live in the assets/ directory relative to the application’s working directory and are loaded at startup by AuthManager. Every time a record is created, updated, or deleted, the relevant manager calls the appropriate FileManager write method to keep the files in sync with the in-memory state.
AuthManager’s constructor calls FileManager methods directly to populate all in-memory structures from the
assets/ files. There is no reloadAll() method — the constructor handles the full initialisation sequence automatically. Individual reload methods (reloadPassengers(), reloadDrivers(), reloadAdmins()) exist on AuthManager for selective refreshes after external file changes.Data Files
| Filename | Format | Field order / Contents |
|---|---|---|
passengers.txt | Pipe-delimited text | passengerId|name|dni|password|rating|totalTrips|totalSpent |
drivers.txt | Pipe-delimited text | driverId|name|dni|password|rating|isAvailable|totalTrips|totalEarnings|plate|brand|model|color|year |
admins.txt | Pipe-delimited text | adminId|username|password |
passwords.bin | Binary | Fixed-width records: tipo[16], id[24], dni[16], password[32] — mirrors passengers then drivers |
passwords.txt | Plain text | Human-readable export generated from passwords.bin — for reference only |
trips.txt | Pipe-delimited text | tripId|origin|destination|price|tipe|status|driverName|driverDni|passengerDni|date |
cities.csv | CSV | id,city,city_ascii,country — city identifiers and display names |
connections.csv | CSV | from_id,from_city_ascii,to_id,to_city_ascii,distance_km — road connections |
Key Methods
Driver File
Writes the entire
vector<Driver> to assets/drivers.txt, one driver per line in the 13-field pipe-delimited format. Overwrites the file on each call.Reads
assets/drivers.txt line by line. Splits each line on |, expects at least 13 fields, and reconstructs the embedded Vehicle from fields 9–13. Creates the file if it does not exist.Passenger File
Writes the entire
vector<Passenger> to assets/passengers.txt in the 7-field format.Reads
assets/passengers.txt, expects at least 7 fields per line, and reconstructs each Passenger. Creates the file if absent.Trip File
Writes all trips to
assets/trips.txt in the 10-field pipe-delimited format.Reads
assets/trips.txt. Handles both 9-field and 10-field lines to maintain backward compatibility with older file versions.Admin File
Writes the admin list to
assets/admins.txt in the 3-field format.Reads
assets/admins.txt, expecting at least 3 fields. Returns an empty vector and creates the file if absent.Seeds
assets/admins.txt with four fixed admin accounts and 111 randomly generated accounts if the file does not yet exist. Called once in AuthManager’s constructor.Produces a zero-padded admin ID string in the format
ADM-XXX.Password Binary File
Writes fixed-size
PasswordRecordBin structs (88 bytes each) to assets/passwords.bin — first all passengers, then all drivers.Reads
passwords.bin sequentially and returns a vector of human-friendly PasswordPreview structs.Calls
leerPasswordsBIN() and writes a plain-text version to assets/passwords.txt. Inserts a blank separator line between the passenger and driver sections.CSV Parsing for the City Graph
FileManager exposes two structs and two methods specifically forTripManager::loadCityGraph().
Structs
leerCitiesCSV
Readsassets/cities.csv, skipping the header row (id column). Expects at least 4 comma-separated fields per line and maps them as:
| CSV column index | Struct field |
|---|---|
| 0 | City.id |
| 2 | City.name (city_ascii) |
| 3 | City.country |
leerConnectionsCSV
Readsassets/connections.csv, skipping the header row (from_id column). Expects at least 5 fields:
| CSV column index | Struct field |
|---|---|
| 0 | Connection.idfrom |
| 1 | Connection.from |
| 2 | Connection.idto |
| 3 | Connection.to |
| 4 | Connection.weight (parsed with stod) |
How TripManager Uses the CSV Data
Nested Public Structs
FileManager exposes three plain structs used by AuthManager as data-transfer types:| Struct | Fields | Used For |
|---|---|---|
PasswordPreview | tipo, id, dni, password (all strings) | Reading back from the binary file |
AdminPreview | id, username, password | Admin record in memory and in admins.txt |
City | id, name, country | City data from cities.csv |
Connection | idfrom, idto, from, to, weight | Road data from connections.csv |
Field Separator
FileManager uses| (pipe) as the field separator in all text files. The constructor stores it as char separador = '|'. An alternate constructor accepts a custom separator: