#include "MsgFolder.h" #include "Message.h" #include #include //***************************************************************************** // Worker Functions: //***************************************************************************** //******** // listMessages: list messages currently available // OUTPUT FORMAT: // #: Topic // where # is an arbitrary messages number which = index in message array void listMsgs(const CMsgFolder& msgFolder) { char topic[SIZE_TOPIC+1]; for(int i = 1; i <= msgFolder.NumMsgs(); i++) { assert(msgFolder.GetMsgTopic(i, topic)); cout << i << ": " << topic << endl; } } //******** // addMessage: adds a message to folder // topic must fit on one line // text is multi-line terminating in an empty line void addMsg(CMsgFolder& msgFolder) { int i; char topic[SIZE_TOPIC+1]; char text[SIZE_TEXT+1]; CMessage thisMsg; cout << "topic(up to " << SIZE_TOPIC << " characters)\n"; cin.getline(topic,SIZE_TOPIC); thisMsg.SetTopic(topic); cout << "text (up to " << SIZE_TEXT << " characters), end text with empty line\n"; bool newLine = true; // used for detecting empty lines for(i = 0; i < SIZE_TEXT; i++) { if((text[i] = cin.get()) == '\n') { if(newLine) break; newLine = true; } else newLine = false; } text[i] = '\0'; // terminate string thisMsg.SetText(text); msgFolder.PostMsg(thisMsg); } //******** // deleteMessage: void deleteMsg(int msgNum, CMsgFolder& msgFolder) { msgFolder.DeleteMsg(msgNum); } //******** // showMessage: Shows message void showMsg(int msgNum, const CMsgFolder& msgFolder) { CMessage thisMsg; char topic[SIZE_TOPIC+1]; char text[SIZE_TEXT+1]; thisMsg = msgFolder.GetMsg(msgNum); thisMsg.GetTopic(topic); thisMsg.GetText(text); cout << "Topic: " << topic << endl; cout << "Text: " << text << endl; } //******** // openMsgFolder: opens message folder with name folderName // raises exception if cannot open(eventually I'll do this) CMsgFolder openMsgFolder(const char* folderName) { CMsgFolder folder(folderName); return folder; } //******** // closeFolder: closes message folder void closeMsgFolder(CMsgFolder& msgFolder) { }