MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
line_reader.h
1/* Copyright (c) 2021 OceanBase and/or its affiliates. All rights reserved.
2miniob is licensed under Mulan PSL v2.
3You can use this software according to the terms and conditions of the Mulan PSL v2.
4You may obtain a copy of Mulan PSL v2 at:
5 http://license.coscl.org.cn/MulanPSL2
6THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
7EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
8MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9See the Mulan PSL v2 for more details. */
10
11//
12// Created by Willaaaaaaa in 2025
13//
14
15#ifndef COMMON_LINE_READER_H
16#define COMMON_LINE_READER_H
17
18#include "replxx.hxx"
19
20namespace common {
25{
26 // The following private methods guarantee it's Singleton pattern
27private:
30 MiniobLineReader(const MiniobLineReader &) = delete;
31 MiniobLineReader &operator=(const MiniobLineReader &) = delete;
32
33public:
38 static MiniobLineReader &instance();
39
44 void init(const std::string &history_file);
45
51 std::string my_readline(const std::string &prompt);
52
58 bool is_exit_command(const std::string &cmd);
59
60private:
66
67private:
68 replxx::Replxx reader_;
69 std::string history_file_;
70 time_t previous_history_save_time_;
71 int history_save_interval_;
72};
73} // namespace common
74
75#endif // COMMON_LINE_READER_H
A singleton class for line-reading, providing an interface to replxx。
Definition: line_reader.h:25
bool is_exit_command(const std::string &cmd)
Check if the command is an exit command
Definition: line_reader.cpp:66
std::string my_readline(const std::string &prompt)
Read a line from input
Definition: line_reader.cpp:35
void init(const std::string &history_file)
Initialize the lineReader with history file
Definition: line_reader.cpp:29
static MiniobLineReader & instance()
Get the singleton instance
Definition: line_reader.cpp:23
bool check_and_save_history()
Check if history should be auto-saved
Definition: line_reader.cpp:77