mirror of
				https://github.com/aportelli/LatAnalyze.git
				synced 2025-10-24 21:34:48 +01:00 
			
		
		
		
	IO: polymorphic file opening
This commit is contained in:
		
							
								
								
									
										18
									
								
								lib/Io.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								lib/Io.cpp
									
									
									
									
									
								
							| @@ -40,3 +40,21 @@ string Io::getFirstName(const string &fileName) | |||||||
|         LATAN_ERROR(Io, "unknown file extension '" + ext + "'"); |         LATAN_ERROR(Io, "unknown file extension '" + ext + "'"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | unique_ptr<File> Io::open(const std::string &fileName, const unsigned int mode) | ||||||
|  | { | ||||||
|  |     string ext = extension(fileName); | ||||||
|  |      | ||||||
|  |     if (ext == "h5") | ||||||
|  |     { | ||||||
|  |         return unique_ptr<File>(new Hdf5File(fileName, mode)); | ||||||
|  |     } | ||||||
|  |     else if ((ext == "dat")||(ext == "sample")||(ext == "seed")) | ||||||
|  |     { | ||||||
|  |         return unique_ptr<File>(new AsciiFile(fileName, mode)); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         LATAN_ERROR(Io, "unknown file extension '" + ext + "'"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
| @@ -47,6 +47,8 @@ public: | |||||||
|     template <typename FileType> |     template <typename FileType> | ||||||
|     static std::string getFirstName(const std::string &fileName); |     static std::string getFirstName(const std::string &fileName); | ||||||
|     static std::string getFirstName(const std::string &fileName); |     static std::string getFirstName(const std::string &fileName); | ||||||
|  |     static std::unique_ptr<File> open(const std::string &fileName, | ||||||
|  |                                       const unsigned int mode = File::Mode::write); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // template implementation ///////////////////////////////////////////////////// | // template implementation ///////////////////////////////////////////////////// | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user