CLI  2.9
cli.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 
63 
64 #ifndef _CLI_CLI_H_
65 #define _CLI_CLI_H_
66 
67 #include "cli/namespace.h"
68 #include "cli/menu.h"
69 #include "cli/tk.h"
70 
71 
75 
76  // Forward declarations
77  class Cli;
78  class Console;
79  class Help;
80  class ConfigMenu;
81  #ifdef _DEBUG
82  class TracesMenu;
83  #endif
84 
85 
97  class Cli : public Menu
98  {
99  private:
101  explicit Cli(void);
103  Cli(const Cli&);
104 
105  public:
109  explicit Cli(
110  const char* const STR_Name,
111  const Help& CLI_Help
112  );
113 
117  virtual ~Cli(void) = 0;
118 
119  private:
121  Cli& operator=(const Cli&);
122 
123  public:
126  typedef tk::Queue<const Cli*> List;
127 
130  static const int FindFromName(
131  Cli::List& CLI_CliList,
132  const char* const STR_RegExp
133  );
134 
135  public:
138  Menu& AddMenu(
139  Menu* const PCLI_Menu
140  );
141 
144  const Menu* const GetMenu(
145  const char* const STR_MenuName
146  ) const;
147 
148  public:
151  const bool AddCommentLinePattern(
152  const char* const STR_Start
153  );
156  const bool RemoveCommentLinePattern(
157  const char* const STR_Start
158  );
161  const tk::Queue<tk::String>& GetCommentLinePatterns(void) const;
162 
163  public:
165  void SetShell(
166  Shell& CLI_Shell
167  ) const;
170  Shell& GetShell(void) const;
171 
172  // Inherit doxygen comments from cli::Element documentation.
173  virtual void SetCli(Cli& CLI_Cli);
174  // Inherit doxygen comments from cli::Menu documentation.
175  virtual const bool ExecuteReserved(const CommandLine& CLI_CommandLine) const;
178  virtual const bool OnError(
179  const ResourceString& CLI_Location,
180  const ResourceString& CLI_ErrorMessage
181  ) const;
183  virtual void OnExit(void) const;
184 
185  private:
187  ConfigMenu& GetConfigMenu(void);
189  const ConfigMenu& GetConfigMenu(void) const;
191  const Keyword& GetConfigMenuNode(void) const;
192  public:
195  const bool IsConfigMenuEnabled(void) const;
196 
199  const bool EnableConfigMenu(
200  const bool B_Enable
201  );
202 
203  private:
204  #ifdef _DEBUG
205  TracesMenu& GetTracesMenu(void);
208  const TracesMenu& GetTracesMenu(void) const;
210  const Keyword& GetTracesMenuNode(void) const;
211  #endif
212 
213  private:
215  mutable Shell* m_pcliShell;
217  tk::Queue<const Menu*> m_qMenus;
219  tk::Queue<tk::String> m_qCommentLinePatterns;
221  ConfigMenu* m_pcliConfigMenu;
223  Keyword* m_pcliConfigMenuNode;
224  #ifdef _DEBUG
225  TracesMenu* m_pcliTracesMenu;
228  Keyword* m_pcliTracesMenuNode;
229  #endif
230  };
231 
233 
234 #endif // _CLI_CLI_H_
235 
Shell & GetShell(void) const
Returns the shell reference on execution.
const Menu *const GetMenu(const char *const STR_MenuName) const
Menu retrieval.
Main namespace of the CLI library.
Help container class.
Definition: help.h:46
CLI configuration menu definition.
Definition: config_menu.h:47
Console intput/output device class.
Definition: console.h:43
virtual void SetCli(Cli &CLI_Cli)
Cli reference setting.
const bool IsConfigMenuEnabled(void) const
Determines whether the configuration menu is currently enabled.
#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.
ResourceString class.
tk::Queue< const Cli * > List
CLI list type.
Definition: cli.h:126
static const int FindFromName(Cli::List &CLI_CliList, const char *const STR_RegExp)
Retrieve CLI references from their names.
Command line parsing.
Definition: command_line.h:52
Namespace management.
const tk::Queue< tk::String > & GetCommentLinePatterns(void) const
Comment line patterns accessor.
void SetShell(Shell &CLI_Shell) const
Set the shell reference when executing.
const bool RemoveCommentLinePattern(const char *const STR_Start)
Comment line pattern removal.
Keyword element class.
Definition: keyword.h:47
virtual const bool OnError(const ResourceString &CLI_Location, const ResourceString &CLI_ErrorMessage) const
Handler on error.
const bool EnableConfigMenu(const bool B_Enable)
Configuration menu enabling.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
CLI toolkit definition.
Menu definition.
Definition: menu.h:51
virtual ~Cli(void)=0
Destructor.
const bool AddCommentLinePattern(const char *const STR_Start)
Comment line pattern addition.
Traces menu definition.
Definition: traces_menu.h:46
CLI definition class.
Definition: cli.h:97
virtual void OnExit(void) const
Handler on menu exit.
Menu & AddMenu(Menu *const PCLI_Menu)
Menu addition.
Shell management.
Definition: shell.h:50