| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * file: utilities.ccp | 
					
						
							|  |  |  |  * Author: Frank Dellaert | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/date_time/gregorian/gregorian.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "utilities.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace boost::gregorian; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | string file_contents(const string& filename, bool skipheader) { | 
					
						
							|  |  |  |   ifstream ifs(filename.c_str()); | 
					
						
							|  |  |  |   if(!ifs) throw CantOpenFile(filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // read file into stringstream
 | 
					
						
							|  |  |  |   stringstream ss; | 
					
						
							|  |  |  |   if (skipheader) ifs.ignore(256,'\n'); | 
					
						
							|  |  |  |   ss << ifs.rdbuf(); | 
					
						
							|  |  |  |   ifs.close(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // return string
 | 
					
						
							|  |  |  |   return ss.str(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2010-02-23 22:54:28 +08:00
										 |  |  | bool files_equal(const string& expected, const string& actual, bool skipheader) { | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |   try { | 
					
						
							| 
									
										
										
										
											2010-02-23 22:54:28 +08:00
										 |  |  |     string expected_contents = file_contents(expected, skipheader); | 
					
						
							| 
									
										
										
										
											2009-08-22 06:23:24 +08:00
										 |  |  |     string actual_contents   = file_contents(actual, skipheader); | 
					
						
							|  |  |  |     bool equal = actual_contents == expected_contents; | 
					
						
							|  |  |  |     if (!equal) { | 
					
						
							|  |  |  |       stringstream command; | 
					
						
							|  |  |  |       command << "diff " << actual << " " << expected << endl; | 
					
						
							|  |  |  |       system(command.str().c_str()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return equal; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   catch (const string& reason) { | 
					
						
							|  |  |  |     cerr << "expection: " << reason << endl; | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void emit_header_comment(ofstream& ofs, const string& delimiter) { | 
					
						
							|  |  |  |   date today = day_clock::local_day(); | 
					
						
							|  |  |  |   ofs << delimiter << " automatically generated by wrap on " << today << endl; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ |