#ifndef HIGHSCORERECORD_H #define HIGHSCORERECORD_H #include #include using namespace std; extern void unload(); class HighScoreRecord { char *recordName; int recordScore; char *recordDate; bool owner; public: HighScoreRecord(char *desiredRecordName, int desiredRecordScore, char *desiredRecordDate, bool desiredOwner) : recordName(desiredRecordName), recordScore(desiredRecordScore), recordDate(desiredRecordDate), owner(desiredOwner) {} HighScoreRecord() : owner(false) {} HighScoreRecord(const HighScoreRecord &source) : recordScore(source.recordScore), owner(source.owner) { if (source.owner) { recordName = (char*)malloc((strlen(source.recordName) + 1) * sizeof(char)); if (!recordName) { unload(); allegro_message("Out of memory."); exit(0); } recordDate = (char*)malloc((strlen(source.recordDate) + 1) * sizeof(char)); if (!recordDate) { unload(); allegro_message("Out of memory."); exit(0); } strcpy(recordName, source.recordName); strcpy(recordDate, source.recordDate); } else { recordName = source.recordName; recordDate = source.recordDate; } } ~HighScoreRecord() { if (owner) { free(recordName); free(recordDate); } } HighScoreRecord& operator=(const HighScoreRecord &source) { if (this == &source) return *this; if (owner) { free(recordName); free(recordDate); } if (source.owner) { recordName = (char*)malloc((strlen(source.recordName) + 1) * sizeof(char)); if (!recordName) { unload(); allegro_message("Out of memory."); exit(0); } recordDate = (char*)malloc((strlen(source.recordDate) + 1) * sizeof(char)); if (!recordDate) { unload(); allegro_message("Out of memory."); exit(0); } strcpy(recordName, source.recordName); strcpy(recordDate, source.recordDate); owner = true; } else { recordName = source.recordName; recordDate = source.recordDate; owner = false; } recordScore = source.recordScore; return *this; } char* getRecordName(); int getRecordScore(); char* getRecordDate(); }; #endif