[4838] | 1 | /*! |
---|
[7374] | 2 | * @file shell_completion_plugin.h |
---|
| 3 | * @brief The Shell Completion Plugin |
---|
| 4 | */ |
---|
[1853] | 5 | |
---|
[7374] | 6 | #ifndef _SHELL_COMPLETION_PLUGIN_H |
---|
| 7 | #define _SHELL_COMPLETION_PLUGIN_H |
---|
[1853] | 8 | |
---|
[7374] | 9 | #include <list> |
---|
[7373] | 10 | #include <vector> |
---|
[7225] | 11 | #include <string> |
---|
[7407] | 12 | #include "multi_type.h" |
---|
[5779] | 13 | |
---|
[7374] | 14 | namespace OrxShell |
---|
[7373] | 15 | { |
---|
[7377] | 16 | //! The Base of All Completors |
---|
[7407] | 17 | class CompletorPlugin |
---|
[7374] | 18 | { |
---|
[7407] | 19 | public: |
---|
| 20 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const = 0; |
---|
| 21 | virtual ~CompletorPlugin() { }; |
---|
| 22 | |
---|
| 23 | virtual CompletorPlugin* clone() const = 0; |
---|
| 24 | protected: |
---|
| 25 | CompletorPlugin() {}; |
---|
[7374] | 26 | }; |
---|
[7371] | 27 | |
---|
[7407] | 28 | class CompletorDefault : public CompletorPlugin |
---|
| 29 | { |
---|
| 30 | public: |
---|
| 31 | CompletorDefault(const MultiType* value); |
---|
| 32 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; |
---|
[7387] | 33 | |
---|
[7407] | 34 | virtual CompletorPlugin* clone() const; |
---|
| 35 | private: |
---|
| 36 | const MultiType* _value; |
---|
| 37 | }; |
---|
[7387] | 38 | |
---|
| 39 | |
---|
[7377] | 40 | //! Completor that completes static Arrays of Strings. |
---|
[7407] | 41 | class CompletorStringArray : public CompletorPlugin |
---|
[7373] | 42 | { |
---|
[7407] | 43 | public: |
---|
| 44 | CompletorStringArray(const std::string* stringArray, unsigned int size) |
---|
| 45 | : _stringArray(stringArray), _size(size) {}; |
---|
| 46 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; |
---|
[7374] | 47 | |
---|
[7407] | 48 | virtual CompletorPlugin* clone() const; |
---|
| 49 | private: |
---|
| 50 | const std::string* _stringArray; |
---|
| 51 | unsigned int _size; |
---|
[7371] | 52 | }; |
---|
| 53 | |
---|
[7387] | 54 | |
---|
[7407] | 55 | class CompletorList : public CompletorPlugin |
---|
[7387] | 56 | { |
---|
[7407] | 57 | public: |
---|
| 58 | CompletorList(const std::list<std::string>* list); |
---|
| 59 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; |
---|
| 60 | virtual CompletorPlugin* clone() const; |
---|
| 61 | |
---|
| 62 | private: |
---|
| 63 | const std::list<std::string>* _list; |
---|
[7387] | 64 | }; |
---|
| 65 | |
---|
| 66 | |
---|
| 67 | |
---|
[7377] | 68 | //! Completor that completes FileSystem Entries. |
---|
[7407] | 69 | class CompletorFileSystem : public CompletorPlugin |
---|
[7377] | 70 | { |
---|
[7407] | 71 | public: |
---|
| 72 | // Where to search if the completionString is empty. |
---|
| 73 | typedef enum |
---|
| 74 | { |
---|
| 75 | StartAtRoot, |
---|
| 76 | StartAtHome, |
---|
| 77 | StartAtDataDir, |
---|
[7377] | 78 | } StartDirectory; |
---|
| 79 | |
---|
[7407] | 80 | CompletorFileSystem(const std::string& fileExtension = "", |
---|
| 81 | StartDirectory startDir = StartAtDataDir, |
---|
| 82 | const std::string& subDir = ""); |
---|
| 83 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; |
---|
| 84 | virtual CompletorPlugin* clone() const; |
---|
[7377] | 85 | |
---|
[7407] | 86 | private: |
---|
| 87 | std::string _fileExtension; |
---|
| 88 | std::string _subDir; |
---|
| 89 | StartDirectory _startDir; |
---|
[7377] | 90 | }; |
---|
| 91 | |
---|
| 92 | |
---|
[7387] | 93 | |
---|
| 94 | |
---|
[7374] | 95 | //! A Templated Completor |
---|
[7407] | 96 | template<typename CLASS> class CompletorTList : public CompletorPlugin |
---|
[7374] | 97 | { |
---|
[7407] | 98 | public: |
---|
| 99 | CompletorTList(const std::list<CLASS*>& completionList); |
---|
| 100 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) |
---|
| 101 | {}; |
---|
| 102 | virtual CompletorPlugin* clone() const; |
---|
[7374] | 103 | }; |
---|
[7373] | 104 | |
---|
[7374] | 105 | } |
---|
| 106 | #endif /* _SHELL_COMPLETION_PLUGIN_H */ |
---|