-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathxhistory_manager.cpp
91 lines (73 loc) · 2.93 KB
/
xhistory_manager.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
/***************************************************************************
* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay and *
* Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include <string>
#include <vector>
#include "xeus/xhistory_manager.hpp"
#include "xin_memory_history_manager.hpp"
namespace xeus
{
xhistory_manager::xhistory_manager()
{
}
void xhistory_manager::configure()
{
configure_impl();
}
void xhistory_manager::store_inputs(int line_num, const std::string& input)
{
store_inputs_impl(line_num, input);
}
nl::json xhistory_manager::process_request(const nl::json& content) const
{
nl::json history;
std::string hist_access_type = content.value("hist_access_type", "tail");
if (hist_access_type.compare("tail") == 0)
{
int n = content.value("n", 10);
bool raw = content.value("raw", true);
bool output = content.value("output", false);
history = get_tail(n, raw, output);
}
if (hist_access_type.compare("search") == 0)
{
std::string pattern = content.value("pattern", "*");
bool raw = content.value("raw", true);
bool output = content.value("output", false);
int n = content.value("n", 10);
bool unique = content.value("unique", false);
history = search(pattern, raw, output, n, unique);
}
if (hist_access_type.compare("range") == 0)
{
int session = content.value("session", 0);
int start = content.value("start", 1);
int stop = content.value("stop", 10);
bool raw = content.value("raw", true);
bool output = content.value("output", false);
history = get_range(session, start, stop, raw, output);
}
return history;
}
nl::json xhistory_manager::get_tail(int n, bool raw, bool output) const
{
return get_tail_impl(n, raw, output);
}
nl::json xhistory_manager::get_range(int session, int start, int stop, bool raw, bool output) const
{
return get_range_impl(session, start, stop, raw, output);
}
nl::json xhistory_manager::search(const std::string& pattern, bool raw, bool output, int n, bool unique) const
{
return search_impl(pattern, raw, output, n, unique);
}
std::unique_ptr<xhistory_manager> make_in_memory_history_manager()
{
return std::make_unique<xin_memory_history_manager>();
}
}