/
RConsoleHistory.hpp
91 lines (68 loc) · 2.26 KB
/
RConsoleHistory.hpp
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
/*
* RConsoleHistory.hpp
*
* Copyright (C) 2009-11 by RStudio, Inc.
*
* This program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
#ifndef R_SESSION_CONSOLE_HISTORY_HPP
#define R_SESSION_CONSOLE_HISTORY_HPP
#include <string>
#include <boost/utility.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/signal.hpp>
#include <core/json/Json.hpp>
namespace core {
class Error ;
class FilePath;
}
namespace r {
namespace session {
// singleton
class ConsoleHistory ;
ConsoleHistory& consoleHistory();
class ConsoleHistory : boost::noncopyable
{
public:
typedef boost::circular_buffer<std::string>::value_type value_type;
typedef boost::circular_buffer<std::string>::const_iterator const_iterator;
typedef boost::signal<void (const std::string&)> AddSignal;
private:
ConsoleHistory();
friend ConsoleHistory& consoleHistory();
// COPYING: boost::noncopyable
public:
void setCapacity(long capacity);
void setRemoveDuplicates(bool removeDuplicates);
void add(const std::string& command);
const_iterator begin() const { return historyBuffer_.begin(); }
const_iterator end() const { return historyBuffer_.end(); }
long size() const
{
return historyBuffer_.size();
}
void clear();
void subset(long beginIndex, // inclusive
long endIndex, // exclusive,
std::vector<std::string>* pEntries) const;
void asJson(core::json::Array* pHistoryArray) const;
core::Error loadFromFile(const core::FilePath& filePath, bool verifyFile);
core::Error saveToFile(const core::FilePath& filePath) const;
boost::signals::connection connectOnAdd(
const AddSignal::slot_function_type& slot)
{
return onAdd_.connect(slot);
}
private:
bool removeDuplicates_;
boost::circular_buffer<std::string> historyBuffer_ ;
AddSignal onAdd_;
};
} // namespace session
} // namespace r
#endif // R_SESSION_CONSOLE_HISTORY_HPP