CLI  2.9
command_line.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_COMMAND_LINE_H_
33 #define _CLI_COMMAND_LINE_H_
34 
35 #include "cli/namespace.h"
36 #include "cli/object.h"
37 #include "cli/element.h"
38 #include "cli/resource_string.h"
39 #include "cli/tk.h"
40 
41 
43 
44  // Forward declarations.
45  class Menu;
46 
47 
52  class CommandLine : public Object
53  {
54  public:
56  explicit CommandLine(void);
57 
59  virtual ~CommandLine(void);
60 
61  private:
63  CommandLine(const CommandLine&);
65  CommandLine& operator=(const CommandLine&);
66 
67  public:
74  const bool Parse(
75  const Menu& CLI_Menu,
76  const tk::String& STR_Line,
77  const bool B_Execution
78  );
80 
83  const Element& GetLastElement(void) const;
84 
91  const char* const GetLastWord(void) const;
92 
97  const int GetNumBackspacesForCompletion(void) const;
98 
103  const ResourceString& GetLastError(void) const;
104 
105  private:
108  const bool Split(
109  const tk::String& STR_Line,
110  tk::Queue<tk::String>& Q_Words,
111  int& I_LastWordPosition
112  );
113 
118  CommandLine& AddElement(
119  const Element* const PCLI_Element
120  );
121 
122  private:
124  Element::List m_cliElements;
126  Element::List m_cliAutoDelete;
128  const Element* m_pcliMenu;
130  tk::String m_strLastWord;
132  bool m_bLastWordValid;
134  int m_iNumBackspacesForCompletion;
136  ResourceString m_cliError;
137 
138  private:
139  // In order to allow access to private members for iteration.
140  friend class CommandLineIterator;
141  };
142 
147  {
148  public:
150  explicit CommandLineIterator(
151  const CommandLine& CLI_CmdLine
152  );
153 
155  virtual ~CommandLineIterator(void);
156 
157  private:
159  explicit CommandLineIterator(void);
163  CommandLineIterator& operator=(const CommandLineIterator&);
164 
165  public:
169  const bool StepIt(void);
170 
173  const bool operator==(
174  const Element& CLI_Element
175  ) const;
176 
179  const Element* const operator*(void) const;
180 
181  private:
183  const CommandLine& m_cliCmdLine;
184 
186  Element::List::Iterator m_cliIterator;
187 
189  const Element* m_pcliCurrentElement;
190  };
191 
193 
194 #endif // _CLI_COMMAND_LINE_H_
195 
Generic object.
Definition: object.h:42
Main namespace of the CLI library.
Element class definition.
const bool operator==(const Element &CLI_Element) const
Checks whether the element corresponds to the current element.
virtual ~CommandLineIterator(void)
Destructor.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
ResourceString class.
const Element & GetLastElement(void) const
Last element accessor.
Command line parsing.
Definition: command_line.h:52
const bool StepIt(void)
Iteration.
Namespace management.
const ResourceString & GetLastError(void) const
Last error.
Generic CLI element.
Definition: element.h:55
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
const char *const GetLastWord(void) const
Last word (for completion).
CLI toolkit definition.
Menu definition.
Definition: menu.h:51
Object class definition.
CommandLine(void)
Default constructor.
Command line iteration.
Definition: command_line.h:146
Help class definition.
tk::Queue< const Element * > List
CLI element list type.
Definition: element.h:61
const bool Parse(const Menu &CLI_Menu, const tk::String &STR_Line, const bool B_Execution)
Parse and analysis invocation.
virtual ~CommandLine(void)
Destructor.
const Element *const operator*(void) const
Current element accessor.
const int GetNumBackspacesForCompletion(void) const
Number of backspaces for completion.