| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file FileWriter.h | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @brief Wrapper for writing files and avoiding overwriting existing files | 
					
						
							|  |  |  |  * This class wraps a stream object and will check that the file is | 
					
						
							|  |  |  |  * actually different to write the new generated file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @date Jan 15, 2012 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FileWriter { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   bool verbose_; | 
					
						
							|  |  |  |   std::string filename_; | 
					
						
							|  |  |  |   std::string comment_str_; | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   std::ostringstream oss; ///< Primary stream for operating on the file
 | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** Create a writer with a filename and delimiter for the header comment */ | 
					
						
							|  |  |  |   FileWriter(const std::string& filename, bool verbose, const std::string& comment_str); | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /** Writes the contents of the stringstream to the file, checking if actually new */ | 
					
						
							|  |  |  |   void emit(bool add_header, bool force=false) const; | 
					
						
							| 
									
										
										
										
											2012-01-16 05:42:41 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace wrap
 |