1 #include "linklist.h"
  2 #include <iostream>
  3 #include <climits>
  4 #include <cstdlib>
  5 #include <cstdio>
  6 #include<string>
  7 #include <mysql++.h>
  8 #include <iomanip>
  9
 10
 11
 12 int main(int argv, char **argc){
 13
 14 if(1){ //create a scope to trigger destructors
 15     CHAINLIST::LIST<int> mylist;
 16     mylist.display();
 17 //      int size = mylist.size();
 18     std::cout << "Size of the List is at the start is: " << mylist.size() << std::endl;
 19     mylist.display();
 20     mylist.insert(1);
 21     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 22     mylist.display();
 23     mylist.insert(1);
 24     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 25     mylist.display();
 26     mylist.insert(2);
 27     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 28     mylist.display();
 29     mylist.insert(4);
 30     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 31     mylist.display();
 32     mylist.insert(8);
 33     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 34     mylist.display();
 35     mylist.insert(16);
 36     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 37     mylist.display();
 38     mylist.remove_front();
 39     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 40     mylist.display();
 41     mylist.remove_all();
 42     std::cout << "Size of the List is: " << mylist.size() << std::endl;
 43     mylist.display();
 44
 45     std::cout << "****Testing find****" << std::endl;
 46
 47     int a = 0; int b = 1;int c;int index = 0; const int max = 50000;
 48     mylist.insert(b);
 49     std::cout << "Max Int is ==>" << INT_MAX << std::endl;
 50     for(c=b+a;c < INT_MAX ; index++){
 51         mylist.insert(c);
 52         a = b;
 53         b=c;
 54         c=b+a;
 55         if(c < b){
 56             mylist.insert(b);
 57             break; //This only happens when we get larger than an int
 58         }
 59         std::cout << "Size of the List is: " << mylist.size() << std::endl;
 60         mylist.display();
 61     }
 62
 63
 64     CHAINLIST::NODE<int> * found = mylist.find(1836311903);
 65     if(found != NULL)
 66         std::cout << "Found ==>" << found->value() << " at " << found << std::endl;
 67     else
 68         std::cout << "1597 not found\n";
 69     found = mylist.find(23);
 70     if(found != NULL)
 71         std::cout << "Found ==>" << found->value() << " at " << found << std::endl;
 72     else
 73         std::cout << "23 not found\n";
 74     std::cout << "int b is ==>" << b << std::endl;
 75     for (index = 0; index < max; index++){
 76         found=mylist.find(index);
 77         if(found != NULL)
 78             std::cout << "Found ==>" << found->value() << " at " << found << std::endl;
 79             //else
 80             // cerr << index << " not found\n";
 81         if (index > b) break;
 82     }  
 83     mylist.remove_all();
 84
 85     std::cout << "*********** Test find_all ******************" << std::endl;
 86     std::cout << "Create a huge link list of random numbers between 1-100\n";
 87     int ran;
 88     srand(12345);
 89     for (index = 0; index < 50; index++){
 90         ran = rand();
 91         ran = ran % 101;
 92         mylist.insert(ran);
 93 //              std::cout << "random ==>" << ran << std::endl;
 94     }
 95     mylist.insert(48);
 96     mylist.insert(48);
 97     mylist.insert(0);
 98     mylist.insert(2);
 99     mylist.insert(4);
100     mylist.insert(48);
101     mylist.insert(48);
102     mylist.insert(5);
103     mylist.insert(5);
104     mylist.insert(6);
105     mylist.insert(7);
106     mylist.insert(3);
107     mylist.insert(8);
108     mylist.insert(48);
109     mylist.insert(3);
110     mylist.insert(3);
111     mylist.insert(3);
112     mylist.insert(4);
113     mylist.insert(5);
114     mylist.insert(46);
115     mylist.insert(2);
116     mylist.insert(6);
117     mylist.insert(48);
118
119     std::cout << "List Size ==>" << mylist.size() << std::endl;
120     int cont48 = 0;
121     CHAINLIST::NODE<int> * tmp = mylist.find_all(48);
122     while(tmp != NULL){
123         //std::cout << "Found " << tmp->value() << " at ==>" << tmp << std::endl;
124         tmp = mylist.find_all(48, tmp);
125         cont48++;
126     }
127
128     std::cout << "******TESTING removing of an item****************" << std::endl;
129     std::cout << "Size is ==>" << mylist.size() << std::endl;
130     std::cout << "48 is in this list " << cont48 << " times\n";
131 //      mylist.display();
132     tmp = mylist.find_all(48);
133         
134     CHAINLIST::NODE<int> * tmp2 = tmp;  
135     while(( tmp=mylist.find_all(48,tmp))){
136 //              std::cout << "while::tmp not NULL\n";
137 //              std::cout << "DELETING ==>" << tmp2 << " VALUE==> " << tmp->value() << std::endl;
138         mylist.remove_item(tmp2);
139 //              std::cout << "Node is ==>" << tmp << std::endl;
140         tmp2 = tmp;
141     }
142     mylist.remove_item(tmp2);
143 //      mylist.display();
144     std::cout << "Size is ==>" <<mylist.size() << std::endl;
145 //      mylist.remove_all();
146     std::cout << "size + deletes = " << (mylist.size() + cont48) << std::endl;
147
148     std::cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
149     mylist.insert(NULL,23);
150     mylist.insert(NULL,23);
151     mylist.insert(NULL,23);
152 //      mylist.display();
153 //std::cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
154     mylist.insert(23);
155     mylist.insert(23);
156     mylist.insert(23);
157     mylist.display();
158 //std::cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
159     tmp = mylist.find(23);
160     std::cout << "*************found********************************" << __LINE__ << std::endl;
161 //std::cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
162     mylist.insert(tmp,1111);
163 //std::cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
164 //      mylist.display();
165     tmp = mylist.find_all(23,tmp);
166 //std::cout << "*************found********************************" << __LINE__ << std::endl;
167 //std::cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
168     mylist.insert(tmp,1111);
169 //std::cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
170 //      mylist.display();
171     while((tmp = mylist.find_all(23, tmp))){
172         //std::cout << "*************found********************************" << __LINE__ << std::endl;
173         //std::cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
174         mylist.insert(tmp,1111);
175 //std::cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << std::endl;
176     }
177
178
179     while((tmp = mylist.find_all(23, tmp))){
180         std::cout << "tmp==> "<< tmp << "\t" << "tmp-value()" << tmp->value() << std::endl;
181         std::cout << "*************WHile Loop TESTING SOME INSERTS findall********************************\n";
182         std::cout << tmp->value() << "\t" << (tmp->next())->value() << std::endl;
183     }
184
185     tmp=NULL;
186     while((tmp = mylist.find_all(1111, tmp))){
187         std::cout << "tmp==> "<< tmp << "\t" << "tmp-value()" << tmp->value() << std::endl;
188 //              std::cout << "*************While Loop  findall********************************\n";
189         std::cout << tmp->value() << "\t" << (tmp->next())->value() << std::endl;
190     }
191     mylist.display();
192
193     tmp=NULL;
194     mylist.insert(tmp,8888);
195     mylist.insert(8888);
196     std::cout << "inserted\n\n\n";
197     mylist.display();
198     while((tmp = mylist.find_all(8888, tmp))){
199 //              std::cout << "tmp==> "<< tmp << "\t" << "tmp-value() " << tmp->value() << std::endl;
200 //              std::cout << "*************While Loop TESTING findall********************************\n";
201         std::cout << tmp->value() << "\t" << (tmp->next())->value() << std::endl;
202     }
203     mylist.display();
204
205 }//End of Scope - Watch for the Destructors
206
207 CHAINLIST::LIST<int> * mylist = new CHAINLIST::LIST<int>;
208 mylist->display();
209 mylist->size();
210 CHAINLIST::LIST<std::string> * mylist2 = new CHAINLIST::LIST<std::string>;
211 mylist2->insert("Hello World");
212 mylist2->insert("I love Schmueli Bear");
213 mylist2->insert("Francine Robin is great");
214 mylist2->insert("Life is wonderful");
215 mylist2->insert("Shani is a superstar");
216 mylist2->insert("Aviva is the blondie girl");
217 mylist2->insert("C++ is EASY!!");
218 mylist2->insert("What?");
219 mylist2->insert("Taly is my big girl");
220 mylist2->insert("Dovid Shimon is the MAN");
221 mylist2->insert("Hernandez laces a long line drive..");
222 mylist2->insert("Lets Go Mets");
223 mylist2->display();
224 CHAINLIST::NODE<std::string> * found = mylist2->find("Lets Go Mets");
225 std::cout << "We Found " << found << " ==>" << found->value() << std::endl;
226
227
228 mysqlpp:: Connection handle("rubenmail", 0, "ruben", "nono");
229 if( handle.connected() ){
230     std::cout << "connected\n";
231 }else{
232     std::cout << "no Connection: " <<   handle.error()  << std::endl;
233     return 1;
234 }
235
236
237 /*
238  * =====================================================================================
239  *        Class:  MESSAGE
240  *  Description:  Messages from Mail Database
241  * =====================================================================================
242  */
243
244
245 class MESSAGE
246 {
247     public:
248         /* ====================  LIFECYCLE     ======================================= */
249         inline MESSAGE():id_("blank"), date_("blank"), from_("blank"), subject_("blank"), message_("blank") {}                             /* constructor */
250         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 */
251
252         /* ====================  ACCESSORS     ======================================= */
253         inline std::string id(){ return id_;}
254         inline std::string date(){ return date_;}
255         inline std::string from(){ return from_;}
256         inline std::string subject(){ return subject_;}
257         inline std::string message(){ return message_;}
258
259         inline void id(std::string par ){id_ = par;}
260         inline void date(std::string par){  date_ = par;}
261         inline void from(std::string par){  from_= par;}
262         inline void subject(std::string par){  subject_ = par;}
263         inline void message(std::string par){  message_ = par;}
264
265         /* ====================  MUTATORS      ======================================= */
266
267         /* ====================  OPERATORS     ======================================= */
268         MESSAGE operator()(std::string a, std::string b, std::string c, std::string d, std::string e){
269             id(a);
270             date(b);
271             from(c);
272             subject(d);
273             message(e);
274             return *this;
275         }
276
277
278     protected:
279         /* ====================  DATA MEMBERS  ======================================= */
280
281     private:
282         /* ====================  DATA MEMBERS  ======================================= */
283         std::string id_;
284         std::string date_;
285         std::string from_;
286         std::string subject_;
287         std::string message_;
288
289 }; /* -----  end of class MESSAGE  ----- */
290
291
292 mysqlpp::Query ask(&handle,true, "select id, fromit, day, subject  from postings where fromit like \"%franca%\"");
293 if(mysqlpp::StoreQueryResult fran = ask.store()){
294
295     MESSAGE * onemail = new MESSAGE();
296     std::cout << onemail->id() << onemail->date() << onemail->from() << onemail->subject() << onemail->message() << std::endl;
297     MESSAGE * twomail = new MESSAGE("Oh ", "Hello ", "DOLLY.  ", "Oh ", "Hello");
298     std::cout << twomail->id() << twomail->date() << twomail->from() << twomail->subject() << twomail->message() << std::endl;
299     (*onemail)("Oh ", "Hello ", "DOLLY.  ", " I'm all alone", " We Code for Food");
300     std::cout << onemail->id() << onemail->date() << onemail->from() << onemail->subject() << onemail->message() << std::endl;
301
302
303 }
304
305         
306         
307
308
309         
310
311
312
313
314
315
316
317 return 0;
318 }