cgma
|
00001 #ifndef CUBITINPUTFILE_HPP 00002 #define CUBITINPUTFILE_HPP 00003 00004 #include "CubitString.hpp" 00005 #include <cstdio> 00006 #include "CubitMessage.hpp" 00007 #include "CubitFile.hpp" 00008 #include "CubitFileUtil.hpp" 00009 00010 struct CubitInputFile 00011 { 00012 enum FileType 00013 { 00014 FILE_NORMAL=1, 00015 FILE_FASTQ=2, 00016 FILE_TEMPORARY=3 00017 }; 00018 00019 CubitString filename; 00020 CubitFile filePointer; 00021 int lineNumber; 00022 CubitInputFile::FileType fileType; 00023 int loopCount; 00024 int breakPoint; 00025 00026 CubitInputFile(const CubitString& fileName, 00027 FileType type=FILE_NORMAL, 00028 int loop=1, 00029 const CubitString& default_path=CubitString()); 00030 00031 00032 ~CubitInputFile(); 00033 00034 }; 00035 00036 inline CubitInputFile::CubitInputFile(const CubitString& fileName, 00037 CubitInputFile::FileType type, 00038 int loop, 00039 const CubitString &includePath) 00040 : breakPoint(0) 00041 { 00042 CubitString file_and_path; 00043 filePointer.open(fileName, "r"); 00044 00045 if (!filePointer && includePath.length()) { 00046 file_and_path = includePath; 00047 file_and_path += "/"; 00048 file_and_path += fileName; 00049 filePointer.open(file_and_path, "r"); 00050 } 00051 00052 if (filePointer) { 00053 if (includePath.length()) 00054 filename = file_and_path; 00055 else 00056 filename = fileName; 00057 } 00058 else { 00059 filename = "<Invalid File>"; 00060 PRINT_WARNING("Could not open file: %s\n", fileName.c_str() ); 00061 } 00062 lineNumber = 1; 00063 fileType = type; 00064 loopCount = --loop; 00065 } 00066 00067 inline CubitInputFile::~CubitInputFile() { 00068 filePointer.close(); 00069 if (fileType == FILE_TEMPORARY) 00070 CubitFileUtil::remove_file(filename); /* Delete file if temporary */ 00071 } 00072 00073 #endif 00074