-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
CliIncrement.h
125 lines (107 loc) · 3.42 KB
/
CliIncrement.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
//==============================================================================
//
// CliIncrement.h
//
// Copyright (C) 2013-2022 Greg Utas
//
// This file is part of the Robust Services Core (RSC).
//
// RSC is free software: you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// RSC is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along
// with RSC. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef CLIINCREMENT_H_INCLUDED
#define CLIINCREMENT_H_INCLUDED
#include "Immutable.h"
#include <cstddef>
#include <cstdint>
#include <iosfwd>
#include <string>
#include "RegCell.h"
#include "Registry.h"
#include "SysTypes.h"
namespace NodeBase
{
class CliCommand;
}
//------------------------------------------------------------------------------
namespace NodeBase
{
// A set of related CLI commands. Currently, each corresponds one-to-one
// with a static library.
//
class CliIncrement : public Immutable
{
public:
// Removes the increment from CliRegistry. Virtual to allow subclassing.
//
virtual ~CliIncrement();
// Deleted to prohibit copying.
//
CliIncrement(const CliIncrement& that) = delete;
// Deleted to prohibit copy assignment.
//
CliIncrement& operator=(const CliIncrement& that) = delete;
// Used by the CLI to search for a command whose name matches TEXT.
//
CliCommand* FindCommand(const std::string& comm) const;
// Displays a one-line summary of the increment's purpose if LEVEL is 0.
// If LEVEL is 1, displays a one-line summary of each of the increment's
// commands. If LEVEL is 2, displays an overview (if any) followed by
// all parameters for each command. Returns 0.
//
word Explain(std::ostream& stream, int level) const;
// Invoked when the CLI enters the increment. Allocates any resources
// required by the increment when it is active.
//
virtual void Enter();
// Invoked when the CLI exits the increment. Frees any resources that
// were allocated by Enter.
//
virtual void Exit();
// Returns the increment's name.
//
c_string Name() const { return name_; }
// Returns the offset to iid_.
//
static ptrdiff_t CellDiff();
// Overridden to display member variables.
//
void Display(std::ostream& stream,
const std::string& prefix, const Flags& options) const override;
// Overridden for patching.
//
void Patch(sel_t selector, void* arguments) override;
protected:
// Sets the corresponding member variables and adds the increment to
// CliRegistry. Protected because this class is virtual.
//
CliIncrement(c_string name, c_string help, uint32_t size = 32);
// Adds COMM to the increment's dictionary of commands.
//
bool BindCommand(CliCommand& comm);
private:
// The increment's index in CliRegistry.
//
RegCell iid_;
// The increment's name.
//
fixed_string name_;
// The increment's purpose.
//
fixed_string help_;
// The increment's commands.
//
Registry<CliCommand> commands_;
};
}
#endif