-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXSearch.cpp
94 lines (78 loc) · 2.04 KB
/
XSearch.cpp
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
#include "XSearch.h"
#include "Runnable/Search.h"
#include "Runnable/FileReader.h"
#include "FileSystem/FileSystem.h"
#include "FileSystem/Local/LocalFile.h"
#include "FileSystem/Local/LocalDirectory.h"
#include "Search/RegularSearch/RegularSearch.h"
#include "Search/RegexSearch/RegexSearch.h"
#include "Style/Ack/Ack.h"
XSearch::XSearch()
{
}
XSearch::~XSearch()
{
m_config.m_threadPool.shutdown(true);
/*
delete m_config.m_fileSystem;
delete m_config.m_searchEngine;
delete m_config.m_style;
*/
}
void XSearch::setStyle(const std::string& _style)
{
m_config.m_style = nullptr;
if (_style == "ack")
{
m_config.m_style = new Ack;
}
}
void XSearch::setSearchEngine(const std::string& _engine)
{
m_config.m_searchEngine = nullptr;
if (_engine == "regular")
{
m_config.m_searchEngine = new RegularSearch;
}
else if (_engine == "regex")
{
m_config.m_searchEngine = new RegexSearch;
}
}
void XSearch::setFileSystem(const std::string& _fileSystem)
{
m_config.m_fileSystem = nullptr;
if (_fileSystem == "local")
{
m_config.m_fileSystem = new FileSystem<LocalDirectory, LocalFile>();
}
}
void XSearch::setFilenameMatch(const std::string& _match)
{
m_config.m_fileMatch = _match;
}
void XSearch::setExtensionMatch(const std::vector<std::string>& _extensions)
{
for (auto& extension : _extensions)
{
m_config.m_extensionMatch.add(extension);
}
}
void XSearch::setContextLine(size_t _before, size_t _after)
{
m_config.m_beforeContext = _before;
m_config.m_afterContext = _after;
}
void XSearch::setCaseSensitive(bool _state)
{
m_config.m_searchEngine->setCaseSensitive(_state);
}
void XSearch::setRecursive(bool _recursive)
{
m_config.m_recursive = _recursive;
}
void XSearch::start(const std::string& _term, const std::string& _dir)
{
Search::m_config = FileReader::m_config = &m_config;
Search(_term, _dir).run();
}