| 1 | /*! | 
|---|
| 2 | * @file shell_completion_plugin.h | 
|---|
| 3 | * @brief The Shell Completion Plugin | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _SHELL_COMPLETION_PLUGIN_H | 
|---|
| 7 | #define _SHELL_COMPLETION_PLUGIN_H | 
|---|
| 8 |  | 
|---|
| 9 | #include <list> | 
|---|
| 10 | #include <vector> | 
|---|
| 11 | #include <string> | 
|---|
| 12 | #include "multi_type.h" | 
|---|
| 13 |  | 
|---|
| 14 | namespace OrxShell | 
|---|
| 15 | { | 
|---|
| 16 | //! The Base of All Completors | 
|---|
| 17 | class CompletorPlugin | 
|---|
| 18 | { | 
|---|
| 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() {}; | 
|---|
| 26 | }; | 
|---|
| 27 |  | 
|---|
| 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; | 
|---|
| 33 |  | 
|---|
| 34 | virtual CompletorPlugin* clone() const; | 
|---|
| 35 | private: | 
|---|
| 36 | const MultiType*    _value; | 
|---|
| 37 | }; | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 | //! Completor that completes static Arrays of Strings. | 
|---|
| 41 | class CompletorStringArray : public CompletorPlugin | 
|---|
| 42 | { | 
|---|
| 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; | 
|---|
| 47 |  | 
|---|
| 48 | virtual CompletorPlugin* clone() const; | 
|---|
| 49 | private: | 
|---|
| 50 | const std::string*   _stringArray; | 
|---|
| 51 | unsigned int         _size; | 
|---|
| 52 | }; | 
|---|
| 53 |  | 
|---|
| 54 |  | 
|---|
| 55 | class CompletorList : public CompletorPlugin | 
|---|
| 56 | { | 
|---|
| 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; | 
|---|
| 64 | }; | 
|---|
| 65 |  | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 | //! Completor that completes FileSystem Entries. | 
|---|
| 69 | class CompletorFileSystem : public CompletorPlugin | 
|---|
| 70 | { | 
|---|
| 71 | public: | 
|---|
| 72 | CompletorFileSystem(const std::string& fileExtension = "", | 
|---|
| 73 | const std::string& subDir = ""); | 
|---|
| 74 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) const; | 
|---|
| 75 | virtual CompletorPlugin* clone() const; | 
|---|
| 76 |  | 
|---|
| 77 | private: | 
|---|
| 78 | std::string             _fileExtension; | 
|---|
| 79 | std::string             _subDir; | 
|---|
| 80 | }; | 
|---|
| 81 |  | 
|---|
| 82 |  | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | //! A Templated Completor | 
|---|
| 86 | template<typename CLASS> class CompletorTList : public CompletorPlugin | 
|---|
| 87 | { | 
|---|
| 88 | public: | 
|---|
| 89 | CompletorTList(const std::list<CLASS*>& completionList); | 
|---|
| 90 | virtual void addToCompleteList(std::vector<std::string>& completionList, const std::string& completionBegin) | 
|---|
| 91 | {}; | 
|---|
| 92 | virtual CompletorPlugin* clone() const; | 
|---|
| 93 | }; | 
|---|
| 94 |  | 
|---|
| 95 | } | 
|---|
| 96 | #endif /* _SHELL_COMPLETION_PLUGIN_H */ | 
|---|