1 /*
  2  * =====================================================================================
  3  *
  4  *       Filename:  message.h
  5  *
  6  *    Description:  class that holds MYSQL messages from my mail database
  7  *
  8  *        Version:  1.0
  9  *        Created:  03/30/2011 01:55:54 AM
 10  *       Revision:  none
 11  *       Compiler:  gcc
 12  *
 13  *         Author:  YOUR NAME Ruben Safir,
 14  *        Company: NYLXS
 15  *
 16  * =====================================================================================
 17  */
 18
 19 #ifndef MESSAGE_RIS
 20 #define MESSAGE_RIS
 21 #include <iostream>
 22 #include <climits>
 23 #include <cstdlib>
 24 #include <cstdio>
 25 #include<string>
 26 #include <mysql++.h>
 27 #include <iomanip>
 28
 29
 30 namespace mess {
 31 class MESSAGE
 32 {
 33     friend std::ostream & operator<<(std::ostream &, const MESSAGE&);
 34     public:
 35         /* ====================  LIFECYCLE     ======================================= */
 36         inline MESSAGE():id_("blank"), date_("blank"), from_("blank"), subject_("blank"), message_("blank") {}            /* constructor */
 37 //      inline MESSAGE(int a) {
 38 //      if(a != 0)
 39 //          std::cerr << "Failed Construction:  Used and interger:  Line==> " << __LINE__ << std::endl;
 40 //
 41 //      }                             /* constructor */
 42         inline MESSAGE(std::string a,std::string b,std::string c,std::string d,std::string e):id_(a), date_(b), from_(c), subject_(d), message_(e) {}                             /* constructor */
 43
 44         /* ====================  ACCESSORS     ======================================= */
 45         inline std::string& id()  { return id_;}
 46         inline std::string& date()  { return date_;}
 47         inline std::string& from()  { return from_;}
 48         inline std::string& subject()  { return subject_;}
 49         inline std::string& message()  { return message_;}
 50
 51         inline void id(std::string &par ){id_ = par;}
 52         inline void date(std::string &par){  date_ = par;}
 53         inline void from(std::string &par){  from_= par;}
 54         inline void subject(std::string &par){  subject_ = par;}
 55         inline void message(std::string &par){  message_ = par;}
 56
 57         /* ====================  MUTATORS      ======================================= */
 58
 59         /* ====================  OPERATORS     ======================================= */
 60         MESSAGE operator()(std::string a, std::string b, std::string c, std::string d, std::string e){ //This is NOT a CONSTRUCTOR
 61             id(a);
 62             date(b);
 63             from(c);
 64             subject(d);
 65             message(e);
 66             return *this;
 67         }
 68         bool operator<(MESSAGE val2){
 69                 if(this->subject() < val2.subject()) {
 70                         return true;
 71                 } else{        
 72                         return false ;
 73                 }
 74         }
 75
 76         bool operator>(MESSAGE val2){
 77                 if(this->subject() > val2.subject()) {
 78                         return true;
 79                 } else{        
 80                         return false ;
 81                 }
 82         }
 83
 84         bool operator<=(MESSAGE val2){
 85                 if(this->subject() <= val2.subject()) {
 86                         return true;
 87                 } else{        
 88                         return false ;
 89                 }
 90         }
 91
 92         bool operator>=(MESSAGE val2){
 93                 if(this->subject() >= val2.subject()) {
 94                         return true;
 95                 } else{        
 96                         return false ;
 97                 }
 98         }
 99
100         bool operator==(MESSAGE val2){
101                 if(this->subject() == val2.subject()) {
102                         return true;
103                 } else{        
104                         return false ;
105                 }
106         }
107
108         MESSAGE& operator=( MESSAGE val){
109                 id(val.id()) ;
110                 date() = val.date() ;
111                 from() = val.from() ;
112                 subject() = val.subject() ;
113                 message() = val.message() ;
114                 return *this;
115         }
116
117         std::string operator[](int index){
118
119                 std::string rval;
120
121                 if(index > 4)
122                         exit(EXIT_FAILURE);          
123
124                 switch ( index ) {
125                         case 0:      rval = id();
126                                 break;
127
128                         case 1:      rval = date();
129                                 break;
130
131                         case 2:      rval = from();
132                                 break;
133                         
134                         case 3:      rval = subject();
135                                 break;
136
137                         case 4:      rval = message();
138                                 break;
139
140                         default: rval = "ERROR";    
141                                 break;
142                 }
143                 return rval;
144         }               /* -----  end switch  ----- */
145
146
147
148
149
150     protected:
151         /* ====================  DATA MEMBERS  ======================================= */
152
153     private:
154         /* ====================  DATA MEMBERS  ======================================= */
155         std::string id_;
156         std::string date_;
157         std::string from_;
158         std::string subject_;
159         std::string message_;
160
161 }; /* -----  end of class MESSAGE  ----- */
162
163 std::ostream & operator<<(std::ostream& outbound, MESSAGE& mes){
164     outbound << "ID ==> " << mes.id() << std::endl << "Date==> " << mes.date() << std::endl<< "From==> " << mes.from() << std::endl << "Subject==> " << mes.subject()<< std::endl << mes.message() << std::endl;
165     return outbound;
166 }
167
168 }               /* -----  end of namespace mess  ----- */
169 #endif