-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathManager.h
173 lines (137 loc) · 3 KB
/
Manager.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
#ifndef MANAGER_H
#define MANAGER_H
#define _CRT_SECURE_NO_WARNINGS
#ifdef _WIN32
#include "rapidjson\document.h"
#elif defined __linux__
#include "rapidjson/document.h"
#endif
#include <map>
#include <string>
#include <functional>
#include <iostream>
#include <fstream>
#include "Console.h"
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#include <sstream>
#include <chrono>
#include <ctime>
#include <atomic>
#include <thread>
#include <mutex>
#include <type_traits>
class Spider; // Forward decleration "Spider.h"
enum SortingType { unchanged, lowercase, capitalize, uppercase };
class Settings
{
public:
Settings(); //Horrible :<
int textspeed = 0;
int depth = 2;
bool debug;
bool polite;
bool show_http;
SortingType type = unchanged;
std::map<std::string, SortingType> eMap;
};
//
// MANAGER
//
class Manager
{
public:
static Manager &instance()
{
static Manager m_inst;
return m_inst;
}
void RegisterCommand(std::string in, std::function<void(void*)> lambda)
{
m_CommandList[in] = lambda;
};
void FireCommand(std::string in);
std::vector<std::string> ListCommands(const std::string &in);
void ReadConfig();
void WriteToFile(const std::set<std::string>& data);
void SetDisplay(std::shared_ptr<Console>);
static void CheckProgress();
std::shared_ptr<Console> m_display;
std::unique_ptr<Settings> Config;
//template <typename T>
std::map<std::string, std::function<void(void*)>> m_CommandList{};
std::atomic<bool> m_working{ false };
static std::mutex m_MutexSpiderSet;
static std::set<std::shared_ptr<Spider>> m_SpiderSet;
protected:
void operator=(Manager const&) = delete;
Manager(Manager const&) = delete;
Manager();
~Manager();
};
//
// LOGGER
//
namespace Logger
{
namespace internal {
struct Liner;
}
class Logger
{
public:
friend internal::Liner;
operator internal::Liner() const;
template <typename T>
inline void Log(T in)
{
internal::Liner() << in;
}
static Logger& instance()
{
static Logger m_inst;
return m_inst;
}
void SetLog();
private:
void m_Log(std::string);
std::string m_logname = "Log.txt";
std::ofstream m_file;
protected:
void operator=(Logger const&) = delete;
Logger(Logger const&) = delete;
Logger();
~Logger();
};
namespace internal
{
struct Liner {
friend class Logger;
bool Owned = true;
Liner() = default;
Liner(Liner &&O) : p_s_{ std::move(O.p_s_) } { O.Owned = false; } //Not actually used 0o
~Liner()
{
if (Owned)
{
*p_s_ << std::endl;
Logger::instance().m_Log(p_s_->str());
Manager::instance().m_display->WriteCurrentEvent(p_s_->str());
}
}
std::unique_ptr<std::stringstream> p_s_{ new std::stringstream() };
};
template <typename T>
const Liner &operator<<(const Liner &L, T &&E) {
*L.p_s_ << std::forward<T>(E);
return L;
}
}
inline Logger::operator internal::Liner() const { return {}; }
extern Logger &log; // = Logger::instance();
}
using Logger::internal::operator<<;
#endif // !MANAGER_H