CLI  2.9
menu.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
31 
32 #ifndef _CLI_MENU_H_
33 #define _CLI_MENU_H_
34 
35 #include "cli/namespace.h"
36 #include "cli/syntax_node.h"
37 #include "cli/tk.h"
38 
39 
41 
42  // Forward declarations.
43  class Cli;
44  class Console;
45  class CommandLine;
46  class Keyword;
47  class Help;
48 
49 
51  class Menu : public SyntaxNode
52  {
53  public:
55  explicit Menu(
56  const char* const STR_Name,
57  const Help& CLI_Help
58  );
59 
61  virtual ~Menu(void);
62 
63  private:
65  explicit Menu(void);
67  Menu(const Menu&);
69  Menu& operator=(const Menu&);
70 
71  public:
74  const tk::String GetName(void) const;
75 
76  public:
77  // Inherit doxygen comments from cli::Element documentation.
78  virtual void SetCli(Cli& CLI_Cli);
79  // Note: use of @param doxygen tag in order to avoid doxygen warnings for reimplementations in sub-classes.
83  virtual const bool ExecuteReserved(const CommandLine& CLI_CommandLine) const;
84  // Note: use of @param doxygen tag in order to avoid doxygen warnings for reimplementations in sub-classes.
88  virtual const bool Execute(const CommandLine& CLI_CommandLine) const;
90  virtual void OnExit(void) const;
93  virtual const tk::String OnPrompt(void) const;
94 
95  private:
97  Keyword* m_pcliHelp;
99  Keyword* m_pcliExit;
101  Keyword* m_pcliQuit;
103  Keyword* m_pcliPwm;
105  Keyword* m_pcliCls;
106  };
107 
108 
110  class MenuRef : public Element
111  {
112  public:
114  explicit MenuRef(
115  const Menu& CLI_Menu
116  );
117 
119  virtual ~MenuRef(void);
120 
121  private:
123  explicit MenuRef(void);
125  MenuRef(const MenuRef&);
127  MenuRef& operator=(const MenuRef&);
128 
129  public:
132  const Menu& GetMenu(void) const;
133 
134  private:
136  const Menu* const m_pcliMenu;
137  };
138 
140 
141 #endif // _CLI_MENU_H_
Main namespace of the CLI library.
SyntaxNode class definition.
Help container class.
Definition: help.h:46
Console intput/output device class.
Definition: console.h:43
Syntax node elements.
Definition: syntax_node.h:51
virtual void OnExit(void) const
Handler on menu exit.
virtual ~MenuRef(void)
Destructor.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
virtual const bool ExecuteReserved(const CommandLine &CLI_CommandLine) const
Reserved commands execution.
Command line parsing.
Definition: command_line.h:52
Namespace management.
Keyword element class.
Definition: keyword.h:47
const tk::String GetName(void) const
Menu name access.
Generic CLI element.
Definition: element.h:55
const Menu & GetMenu(void) const
Target menu accessor.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
virtual void SetCli(Cli &CLI_Cli)
Cli reference setting.
virtual const tk::String OnPrompt(void) const
Handler on prompt display.
virtual ~Menu(void)
Destructor.
CLI toolkit definition.
Menu definition.
Definition: menu.h:51
Menu reference element.
Definition: menu.h:110
CLI definition class.
Definition: cli.h:97
virtual const bool Execute(const CommandLine &CLI_CommandLine) const
User-defined commands execution.