00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00002 * 00003 * Copyright (C) 2006-2008 by Jim Pattee <jimp03@email.com> 00004 * Copyright (C) 1998-2002 by Tal Davidson 00005 * <http://www.gnu.org/licenses/lgpl-3.0.html> 00006 * 00007 * This file is a part of Artistic Style - an indentation and 00008 * reformatting tool for C, C++, C# and Java source files. 00009 * <http://astyle.sourceforge.net> 00010 * 00011 * Artistic Style is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License as published 00013 * by the Free Software Foundation, either version 3 of the License, or 00014 * (at your option) any later version. 00015 * 00016 * Artistic Style is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public License 00022 * along with Artistic Style. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 00025 */ 00026 00027 00028 #ifndef ASSTREAMITERATOR_H 00029 #define ASSTREAMITERATOR_H 00030 00031 #include "astyle.h" 00032 #include <iostream> 00033 00034 namespace astyle 00035 { 00036 00037 class ASStreamIterator : public ASSourceIterator 00038 { 00039 public: 00040 bool checkForEmptyLine; 00041 00042 // function declarations 00043 ASStreamIterator(istream *in); 00044 virtual ~ASStreamIterator(); 00045 string nextLine(bool emptyLineWasDeleted); 00046 string peekNextLine(); 00047 void peekReset(); 00048 void saveLastInputLine(); 00049 00050 // inline functions 00051 bool compareToInputBuffer(const string &nextLine) const { return nextLine == prevBuffer; } 00052 const char* getOutputEOL() const { return outputEOL; } 00053 bool hasMoreLines() const { return !inStream->eof(); } 00054 00055 private: 00056 istream * inStream; // pointer to the input stream 00057 string buffer; // current input line 00058 string prevBuffer; // previous input line 00059 int eolWindows; // number of Windows line endings (CRLF) 00060 int eolLinux; // number of Linux line endings (LF) 00061 int eolMacOld; // number of old Mac line endings (CR) 00062 int peekStart; // starting position for peekNextLine() 00063 char outputEOL[4]; // output end of line char 00064 bool prevLineDeleted; // the previous input line was deleted 00065 }; 00066 00067 /* 00068 00069 // typename will be istringstream for GUI and istream otherwise 00070 //template<typename T> 00071 class ASStreamIterator : 00072 public ASSourceIterator 00073 { 00074 public: 00075 // function declarations 00076 ASStreamIterator(istream *in); 00077 virtual ~ASStreamIterator(); 00078 string nextLine(); 00079 string peekNextLine(); 00080 void peekReset(); 00081 void saveLastInputLine(); 00082 00083 // inline functions 00084 bool compareToInputBuffer(const string &nextLine) const { return nextLine == prevBuffer; } 00085 const char* getOutputEOL() const { return outputEOL; } 00086 bool hasMoreLines() const { return !inStream->eof(); } 00087 00088 private: 00089 istream* inStream; // pointer to the input stream 00090 string buffer; // current input line 00091 string prevBuffer; // previous input line 00092 int eolWindows; // number of Windows line endings (CRLF) 00093 int eolLinux; // number of Linux line endings (LF) 00094 int eolMacOld; // number of old Mac line endings (CR) 00095 char outputEOL[4]; // output end of line char 00096 int peekStart; // starting position for peekNextLine() 00097 }; 00098 */ 00099 } 00100 00101 #endif