forked from Andersbakken/rtags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryJob.h
113 lines (102 loc) · 4 KB
/
QueryJob.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* This file is part of RTags.
RTags is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTags is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#ifndef Job_h
#define Job_h
#include <rct/ThreadPool.h>
#include <rct/List.h>
#include <rct/String.h>
#include <rct/EventLoop.h>
#include <rct/SignalSlot.h>
#include <regex>
#include "RTagsClang.h"
#include "QueryMessage.h"
#include <mutex>
class Location;
class QueryMessage;
class Project;
class Connection;
struct Symbol;
class QueryJob
{
public:
enum Flag {
None = 0x0,
WriteUnfiltered = 0x1,
QuoteOutput = 0x2,
QuietJob = 0x4
};
enum { Priority = 10 };
QueryJob(const std::shared_ptr<QueryMessage> &msg, unsigned int jobFlags, const std::shared_ptr<Project> &proj);
QueryJob(unsigned int jobFlags, const std::shared_ptr<Project> &project);
~QueryJob();
bool hasFilter() const { return mPathFilters || mPathFiltersRegex; }
List<String> pathFilters() const { return mPathFilters ? *mPathFilters : List<String>(); }
uint32_t fileFilter() const;
enum WriteFlag {
NoWriteFlags = 0x0,
IgnoreMax = 0x1,
DontQuote = 0x2,
Unfiltered = 0x4
};
bool write(const String &out, unsigned int flags = NoWriteFlags);
bool write(const Symbol &symbol, unsigned int cursorInfoFlags = 0, unsigned int flags = NoWriteFlags);
bool write(const Location &location, unsigned int flags = NoWriteFlags);
template <int StaticBufSize> bool write(unsigned int flags, const char *format, ...);
template <int StaticBufSize> bool write(const char *format, ...);
unsigned int jobFlags() const { return mJobFlags; }
void setJobFlags(unsigned int flags) { mJobFlags = flags; }
void setJobFlag(Flag flag, bool on = true) { if (on) { mJobFlags |= flag; } else { mJobFlags &= ~flag; } }
unsigned int queryFlags() const { return mQueryMessage ? mQueryMessage->flags() : 0; }
unsigned int keyFlags() const { return QueryMessage::keyFlags(queryFlags()); }
bool filter(const String &val) const;
Signal<std::function<void(const String &)> > &output() { return mOutput; }
std::shared_ptr<Project> project() const { return mProject; }
virtual int execute() = 0;
int run(const std::shared_ptr<Connection> &connection = 0);
bool isAborted() const { std::lock_guard<std::mutex> lock(mMutex); return mAborted; }
void abort() { std::lock_guard<std::mutex> lock(mMutex); mAborted = true; }
std::mutex &mutex() const { return mMutex; }
bool &aborted() { return mAborted; }
const std::shared_ptr<Connection> &connection() const { return mConnection; }
private:
mutable std::mutex mMutex;
bool mAborted;
int mLinesWritten;
bool writeRaw(const String &out, unsigned int flags);
std::shared_ptr<QueryMessage> mQueryMessage;
unsigned int mJobFlags;
Signal<std::function<void(const String &)> > mOutput;
std::shared_ptr<Project> mProject;
List<String> *mPathFilters;
List<std::regex> *mPathFiltersRegex;
String mBuffer;
std::shared_ptr<Connection> mConnection;
};
template <int StaticBufSize>
inline bool QueryJob::write(unsigned int flags, const char *format, ...)
{
va_list args;
va_start(args, format);
const String ret = String::format<StaticBufSize>(format, args);
va_end(args);
return write(ret, flags);
}
template <int StaticBufSize>
inline bool QueryJob::write(const char *format, ...)
{
va_list args;
va_start(args, format);
const String ret = String::format<StaticBufSize>(format, args);
va_end(args);
return write(ret);
}
#endif