MTK++ Latest version: 0.2.0

inputParser.h
Go to the documentation of this file.
00001 
00033 #ifndef INPUTPARSER_H
00034 #define INPUTPARSER_H
00035 
00036 #include "baseParser.h"
00037 #include "Log/errorHandler.h"
00038 #include "Utils/constants.h"
00039 namespace MTKpp
00040 {
00041 
00058 inline int readInputFile(std::string inputFile, std::vector<std::vector<std::string> >& inputFileContents)
00059 {
00060     std::ifstream iFile;
00061     iFile.open(inputFile.c_str());
00062 
00063     if (!iFile) {
00064       std::string errMess = "UNABLE TO OPEN INPUT FILE FILENAME = " + inputFile + " ... exiting ";
00065       errorLogger.throwError("readInputFile", errMess, MTK_ERROR);
00066       return 1;
00067     }
00068 
00069     std::string errorMessage = "Commands read: \n";
00070 
00071     std::string fileline = "";
00072     const char comment = '#';
00073 
00074     while (iFile) {
00075       std::string buffer(80,'*');
00076       std::string preFileLine;
00077       getline(iFile, preFileLine);
00078 
00079       // Strip any spaces at the begin and end of the line
00080       std::string fileline = stripString(preFileLine, " ");
00081 
00082       // If line is not blank or starts with "#"
00083       if ((fileline != "") and (fileline[0] != comment)) {
00084         errorMessage += fileline + "\n";
00085         // User may have a comment at end of line
00086         std::vector<std::string> splitLine1;
00087         splitString(fileline, "#", splitLine1, 0);
00088         fileline = splitLine1[0];
00089 
00090         std::vector<std::string> splitLine2;
00091         splitString(fileline, " ", splitLine2, 0);
00092         inputFileContents.push_back(splitLine2);
00093       }
00094     } // while (iFile)
00095     iFile.close();
00096 
00097     errorLogger.throwError("readInputFile", errorMessage, INFO);
00098 
00099     return 0;
00100 };
00101 
00109 inline int readListFile(std::string listFile, std::vector<std::string>& listFileContents)
00110 {
00111     std::ifstream iFile;
00112     iFile.open(listFile.c_str());
00113 
00114     if (!iFile) {
00115       std::cout << "\nUNABLE TO OPEN LIST FILE" << "\nFILENAME = "
00116                 << listFile << "\nEXITING...\n" << std::endl;
00117       return 1;
00118     }
00119     std::string fileline = "";
00120 
00121     while (iFile) {
00122       std::string buffer(80,'*');
00123       getline(iFile, fileline);
00124       if (fileline != "") {
00125         listFileContents.push_back(fileline);
00126       }
00127     } // while (iFile)
00128     iFile.close();
00129     return 0;
00130 };
00131 
00132 } // MTKpp namespace
00133 
00134 #endif // INPUTPARSER_H
00135 

Generated on Fri Dec 23 2011 09:28:50 for MTK++ by Doxygen 1.7.5.1