File indexing completed on 2024-05-05 04:38:45
0001 /* 0002 SPDX-FileCopyrightText: 2016 Anton Anikin <anton.anikin@htower.ru> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QString> 0010 #include <QTextStream> 0011 #include <QVector> 0012 0013 namespace KDevelop { 0014 0015 struct KDevFormatLine 0016 { 0017 QStringList wildcards; 0018 QString command; 0019 }; 0020 0021 class KDevFormatFile 0022 { 0023 public: 0024 KDevFormatFile(const QString& origFilePath, const QString& tempFilePath); 0025 0026 bool find(); 0027 bool read(); 0028 bool apply(); 0029 0030 private: 0031 bool executeCommand(QString command); 0032 0033 /// This is logically a static constant, but since this class is instantiated 0034 /// once in non-test code, making it a non-static member is safe and efficient. 0035 const QString formatFileName; 0036 0037 const QString m_origFilePath; 0038 const QString m_tempFilePath; 0039 0040 QVector<KDevFormatLine> m_formatLines; 0041 }; 0042 0043 class AutoFlushingQTextStream : public QTextStream 0044 { 0045 public: 0046 AutoFlushingQTextStream(FILE* f, QIODevice::OpenMode o) 0047 : QTextStream(f, o) 0048 { 0049 } 0050 0051 template<typename T> 0052 AutoFlushingQTextStream& operator <<(T&& s) 0053 { 0054 *(( QTextStream* ) this) << std::forward<T>(s); 0055 flush(); 0056 return *this; 0057 } 0058 }; 0059 0060 inline AutoFlushingQTextStream& qStdOut() 0061 { 0062 static AutoFlushingQTextStream s{stdout, QIODevice::WriteOnly | QIODevice::Text}; 0063 return s; 0064 } 0065 0066 } 0067 0068 Q_DECLARE_TYPEINFO(KDevelop::KDevFormatLine, Q_MOVABLE_TYPE);