//****************************************************************************** // Message Object: messages consist of a topic and message text // both of which are bounded character strings. // This is a simple, but limited and possibly inefficient solution // ****** CLASS INVARIANTS // Thus all messages are subject to the size constraints (SIZE_TOPIC and SIZE_TEXT) // and thus will not be listed as a PRECONDITION. // The current implementation will only store up to this maximum size. // ******* PERSISTANCE OF OBJECTS: // Interesting feature is the ability of the message to read/write itself // to an open file - this is reminiscent of the document archiving done // in MFC's CDocument class. // This feature supports persistence of objects where the place for storage is controlled // by the application by the details of storage is arranged by the object itself // Thus the application can decide to store all objects in one file or in many // The non-default constructor will initialize a message from an open file. // AUTHOR: Chris Wild // DATE: July 25, 1997 //*************************************************************** #ifndef MESSAGE_H // to keep from doubly defining this header file #define MESSAGE_H #include const int SIZE_TOPIC = 50; // maximum size for topic field const int SIZE_TEXT = 300; // maximum size for message text field class CMessage { public: //************** constructors and desctructors // Default constructor builds an empty message CMessage(); // This constructor initializes messages from file // fileHandle: is handle to already open message file CMessage(HANDLE fileHandle); // Copy constructor CMessage(const CMessage& Msg); // Copy constructor ~CMessage(); //************** Operations // Sets the message topic //POST: Topic of this message is set to string void SetTopic(const char * ); // Gets the message topic // PRE: thisTopic is big enough (maximum SIZE_TOPIC+1 characters) // POST: returns topic of this message void GetTopic(char * thisTopic) const; // Sets text of message void SetText(const char *); // returns text of message // PRE: thisMessage is big enough (maximum SIZE_TEXT+1 characters) void GetText(char * thisMessage) const; // Read/Write message to already open file bool ReadMsg(HANDLE fileHandle); bool WriteMsg(HANDLE fileHandle) const; private: char topic[SIZE_TOPIC+1]; // fixed string buffer for convenience char text[SIZE_TEXT+1]; }; #endif