Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/shell/shell_completion.h @ 8448

Last change on this file since 8448 was 7415, checked in by bensch, 19 years ago

orxonox/trunk: Super-good completion :), and extremely tired bensch

File size: 2.6 KB
Line 
1/*!
2 * @file shell_completion.h
3 * @brief The Shell Completion Tasks
4 *
5 * @todo if the second string is a Command, the third should not be completed!
6 * @todo also make some completion for registered (or special) Types
7*/
8
9#ifndef _SHELL_COMPLETION_H
10#define _SHELL_COMPLETION_H
11
12#include <vector>
13#include <list>
14#include <string>
15
16// FORWARD DECLARATION
17class BaseObject;
18
19namespace OrxShell
20{
21  class ShellCommand;
22
23  //! A class for Completing the an InputString.
24  class ShellCompletion
25  {
26      //! an enumerator for different types the Shell can complete.
27      typedef enum {
28        NullCompletion         = 0,
29        ClassCompletion        = 1,
30        ObjectCompletion       = 2,
31        FunctionCompletion     = 4,
32        AliasCompletion        = 8,
33        ParamCompletion        = 16,
34    } CompletionType;
35
36      //! A struct for ShellElements (these are used as containers to identify an Input for what it is)
37      struct CompletionElement
38      {
39        CompletionElement(std::string name, CompletionType type) : name(name), type(type) {}
40        std::string     name;     //!< the Name of the Element to be completed.
41        CompletionType  type;     //!< the type of the Element
42      };
43
44    public:
45      ShellCompletion();
46      virtual ~ShellCompletion();
47
48
49      // Functions to produce the Complete Lists.
50      bool autoComplete(std::string& input);
51
52      static const std::string& ShellCompletion::typeToString(ShellCompletion::CompletionType type);
53
54    private:
55      bool objectComplete(const std::string& objectBegin, long classID);
56      bool commandComplete(const std::string& commandBegin, const std::string& className);
57      bool aliasComplete(const std::string& aliasBegin);
58      bool paramComplete(const std::string& paramBegin, const ShellCommand* command, unsigned int paramNumber);
59
60      // Generally Completes.
61      bool generalComplete(std::string& input,
62                           const std::string& begin, const std::string& displayAs = "%s",
63                           const std::string& addBack = "", const std::string& addFront = "");
64
65
66      bool addToCompleteList(const std::list<std::string>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type);
67      bool addToCompleteList(const std::list<BaseObject*>& inputList, const std::string& completionBegin, ShellCompletion::CompletionType type);
68
69      // Helpers.
70      void clearCompletionList();
71
72    private:
73      std::vector<CompletionElement>  completionList;          //!< A list of completions, that are io.
74
75      static const std::string        typeNames[];             //!< A list of Completion-Type-Names.
76  };
77
78}
79
80#endif /* _SHELL_COMPLETION_H */
Note: See TracBrowser for help on using the repository browser.