#pragma once #ifndef SHARED_LIB_H #define SHARED_LIB_H #include #include #include "../Assignment-03/TAVL.h" /// /// Delegate type for processing a name read from a file. /// /// The index of the name (0-based). /// The total number of names. /// The first name read from the file. /// The last name read from the file. /// Returns true to continue reading, false to stop. typedef bool (*FNameRead)( const int aIndex, const int aTotalCount, const std::string& aFirstName, const std::string& aLastName ); /// /// Use this function to read names from a specified file and process them using a callback function. /// /// readNamesFromFile /// Reads names from a specified file and invokes a callback for each name read. /// The path to the file containing names. /// A callback function that is called for each name read. It takes two parameters: firstName and lastName. If the callback returns false, the reading process stops. /// The first name read from the file. /// The last name read from the file. /// None. void readNamesFromFile(const std::string& aFilename, FNameRead aOnNameRead); /// /// Delegate type for processing a node read from the file. /// /// Function pointer type for a callback that processes nodes read from a file. /// The index of the node (0-based). /// The total number of nodes. /// The node std::string. /// Returns true to continue reading, false to stop. typedef bool (*FNodeRead)(const int aIndex, const int aTotalCount, const std::string& aNode); /// /// Delegate type for processing an edge read from the file. /// /// Function pointer type for a callback that processes edges read from a file. /// The index of the edge (0-based). /// The total number of edges. /// The from node std::string. /// The to node std::string. /// The weight of the edge. /// Returns true to continue reading, false to stop. typedef bool (*FEdgeRead)(const int aIndex, const int aTotalCount, const std::string& aFromNode, const std::string& aToNode, float aWeight); /// /// Use this function to read a graph from a specified file and process its nodes and edges using callback functions. /// /// readGraphFromFile /// /// Reads a graph from a specified file and invokes callbacks for each node and edge read. /// All nodes are read first, followed by edges. /// /// The path to the file containing the graph data. /// A callback function that is called for each node read. It takes one parameter: the node std::string. If the callback returns false, the reading process stops. /// A callback function that is called for each edge read. It takes three parameters: the fromNode std::string, the toNode std::string, and the weight float. If the callback returns false, the reading process stops. void readGraphFromFile(const std::string& aFilename, FNodeRead aOnNodeRead, FEdgeRead aOnEdgeRead); /// /// Delegate type for processing a song read from the file. /// /// The index of the song (0-based). /// The total number of songs. /// The artist. /// The title. /// The release year (as a std::string). /// The genre. /// The source. /// Returns true to continue reading, false to stop. typedef bool (*FSongRead)( const int aIndex, const int aTotalCount, const std::string& aArtist, const std::string& aTitle, const std::string& aYear, const std::string& aGenre, const std::string& aSource ); /// /// Reads song data from a file and processes them using a callback. /// This function automatically skips the "records:=" header. /// /// The path to the file (e.g., "songs.txt"). /// The callback function called for each song. void ReadSongsFromFile(const std::string& aFilename, FSongRead aOnSongRead); #endif // SHARED_LIB_H