Changeset View
Changeset View
Standalone View
Standalone View
util/kdevformatfile.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Anton Anikin <anton.anikin@htower.ru> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License along | ||||
15 | with this program; if not, write to the Free Software Foundation, Inc., | ||||
16 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #pragma once | ||||
20 | | ||||
21 | #include <QString> | ||||
22 | #include <QTextStream> | ||||
23 | #include <QVector> | ||||
24 | | ||||
25 | namespace KDevelop { | ||||
26 | | ||||
27 | struct KDevFormatLine | ||||
28 | { | ||||
29 | QStringList wildcards; | ||||
30 | QString command; | ||||
31 | }; | ||||
32 | | ||||
33 | class KDevFormatFile | ||||
34 | { | ||||
35 | public: | ||||
36 | KDevFormatFile(const QString& origFilePath, const QString& tempFilePath); | ||||
37 | | ||||
38 | bool find(); | ||||
39 | bool read(); | ||||
40 | bool apply(); | ||||
41 | | ||||
42 | private: | ||||
43 | bool executeCommand(QString command); | ||||
44 | | ||||
45 | QString m_origFilePath; | ||||
46 | QString m_tempFilePath; | ||||
47 | | ||||
48 | QVector<KDevFormatLine> m_formatLines; | ||||
49 | }; | ||||
50 | | ||||
51 | class AutoFlushingQTextStream : public QTextStream | ||||
52 | { | ||||
53 | public: | ||||
54 | AutoFlushingQTextStream(FILE* f, QIODevice::OpenMode o) | ||||
55 | : QTextStream(f, o) | ||||
56 | { | ||||
57 | } | ||||
58 | | ||||
59 | template<typename T> | ||||
60 | AutoFlushingQTextStream& operator << (T&& s) | ||||
61 | { | ||||
62 | *((QTextStream*) this) << std::forward<T>(s); | ||||
63 | flush(); | ||||
64 | return *this; | ||||
65 | } | ||||
66 | }; | ||||
67 | | ||||
68 | inline AutoFlushingQTextStream& qStdOut() | ||||
69 | { | ||||
70 | static AutoFlushingQTextStream s{stdout, QIODevice::WriteOnly | QIODevice::Text}; | ||||
71 | return s; | ||||
72 | } | ||||
73 | | ||||
74 | } | ||||
75 | |