1  #ifndef MAILBOX_H
  2  #define MAILBOX_H
  3  
  4  using namespace std;
  5  
  6  #include <string>
  7  #include <queue>
  8  
  9  class Message;
 10  
 11  /**
 12     A mailbox contains messages that can be listed, kept, or discarded
 13  */
 14  class Mailbox
 15  {
 16  public:
 17     /**
 18        Create a mailbox object
 19        @param a_passcode passcode number
 20        @param a_greeting greeting string
 21     */
 22     Mailbox(string a_passcode, string a_greeting);
 23  
 24     /**
 25        Check if the passcode is correct
 26        @param a_passcode a passcode to check
 27     */
 28     bool check_passcode(string a_passcode) const; 
 29  
 30     /**
 31        Add a message to the mailbox
 32        @param a_message the message to be added
 33     */
 34     void add_message(Message* a_message);
 35  
 36     /**
 37        Get the current message
 38        @return the current message
 39     */
 40     Message* get_current_message() const;
 41  
 42     /**
 43        Remove the current message from the mailbox
 44     */
 45     void remove_current_message();
 46  
 47     /**
 48        Save the current message
 49     */
 50     void save_current_message();
 51  
 52     /**
 53        Change the mailbox's greeting
 54        @param new_greeting the new greeting string
 55     */
 56     void set_greeting(string new_greeting);
 57  
 58     /**
 59        Change mailbox's passcode
 60        @param new_passcode the new passcode
 61     */
 62     void set_passcode(string new_passcode);
 63  
 64     /**
 65        Get the mailbox's greeting
 66        @return the greeting
 67     */
 68     string get_greeting() const;
 69  private:
 70     queue<Message*> new_messages;
 71     queue<Message*> kept_messages;
 72     string greeting;
 73     string passcode;
 74  };
 75  
 76  inline Mailbox::Mailbox(string a_passcode, string a_greeting)
 77     : passcode(a_passcode), greeting(a_greeting)
 78  {
 79  }
 80  
 81  inline bool Mailbox::check_passcode(string a_passcode) const
 82  {
 83     return passcode == a_passcode;
 84  }
 85  
 86  inline void Mailbox::add_message(Message* a_message)
 87  {
 88     new_messages.push(a_message);
 89  }
 90  
 91  inline void Mailbox::set_greeting(string new_greeting)
 92  {
 93     greeting = new_greeting;
 94  }
 95  
 96  inline void Mailbox::set_passcode(string new_passcode)
 97  {
 98     passcode = new_passcode;
 99  }
100  
101  inline string Mailbox::get_greeting() const
102  {
103     return greeting;
104  }
105  
106  #endif