libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef __FORTRAN_FORMAT__ 00019 #define __FORTRAN_FORMAT__ 00020 00021 #include "StringBasics.h" 00022 #include "IntArray.h" 00023 00024 class FortranFormat 00025 { 00026 public: 00027 // This class reads a user specified input file, one line at a time, 00028 // and returns individual fields according to a user specified format 00029 // statement 00030 FortranFormat(); 00031 00032 // Set the fortran format statement 00033 void SetFormat(const String & formatString); 00034 00035 // Set the input file 00036 void SetInputFile(IFILE & file); 00037 00038 // Read one field from input file 00039 void GetNextField(String & field); 00040 int GetNextInteger(); 00041 char GetNextCharacter(); 00042 00043 // Process a token in format statement and return true 00044 // if token corresponds to input field. Return false if 00045 // token led to processing of white-space or input line 00046 // positioning 00047 bool ProcessToken(String & field); 00048 00049 // Flush the pattern -- this finishes processing the current 00050 // pattern and ensures that all trailing new-lines, etc. are 00051 // handled correctly 00052 void Flush(); 00053 00054 private: 00055 // The input line and current position along it 00056 String inputLine; 00057 int inputPos; 00058 00059 // The Fortran format statement and current position along it 00060 String format; 00061 int formatPos; 00062 00063 // The position of the pattern we are repeating, if any 00064 int repeatCount; 00065 00066 // Returns an integer from the current format statement, if any 00067 int GetIntegerFromFormat(); 00068 00069 // These functions check the next character in format string 00070 bool DigitFollows(); 00071 bool CharacterFollows(); 00072 00073 // This function finish the input field 00074 void FinishField(bool haveSlash = false); 00075 00076 // Reject width were appropriate 00077 void RejectWidth(char type); 00078 00079 // The input file 00080 IFILE input; 00081 00082 // Stacks to keep track of nested parenthesis 00083 IntArray bracketStack; 00084 IntArray bracketCount; 00085 IntArray bracketCounter; 00086 00087 int lastBracket; 00088 int lastCount; 00089 00090 // Buffer for reading fields 00091 String buffer; 00092 00093 // Flag that indicates whether we have reached end-of-pattern 00094 bool endOfPattern; 00095 }; 00096 00097 #endif 00098 00099