-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvty_cmd_history.h
More file actions
35 lines (27 loc) · 791 Bytes
/
vty_cmd_history.h
File metadata and controls
35 lines (27 loc) · 791 Bytes
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
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <vector>
#include <string>
class commandhistory {
size_t hist_index;
std::vector<std::string> history;
public:
commandhistory() : hist_index(0) {}
void add(const std::string& str) { history.push_back(str); }
void clean() { hist_index=0; }
std::string deep_get();
std::string shallow_get();
};
inline std::string commandhistory::deep_get()
{
if (history.empty()) return "";
if (hist_index+2 > history.size()) return *(history.end() - hist_index - 1);
return *(history.end() - ++hist_index);
}
inline std::string commandhistory::shallow_get()
{
if (history.empty()) return "";
if (ssize_t(hist_index)-1 < 0) return *(history.end() - hist_index - 1);
return *(history.end() - --hist_index - 1);
}