#include "MsgFolder.h" #include "Message.h" #include #include //***************************************************************************** // Worker Functions: // So why not put these as member functions of CMsgFolder class? // because I prefer to avoid doing screen oriented I/O in a class // What if this is a Gui application? The class should not have to know about // the User Interface. //***************************************************************************** //******** // 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++) { if(!msgFolder.GetMsgTopic(i, topic)) { cout << "Could not access topic - aborting \n "; ExitProcess(1); } 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); if(!msgFolder.PostMsg(thisMsg)) { cerr << "Error in adding message - perhaps you need to open a folder first!\n"; } } //******** // showMessage: Shows message void showMsg(int msgNum, const CMsgFolder& msgFolder) { CMessage thisMsg; char topic[SIZE_TOPIC+1]; char text[SIZE_TEXT+1]; if(!msgFolder.GetMsg(msgNum, thisMsg)) { cout << " could not find message\n"; return; } thisMsg.GetTopic(topic); thisMsg.GetText(text); cout << "Topic: " << topic << endl; cout << "Text: " << text << endl; }