Changeset 5129 in orxonox.OLD for trunk/src/util/shell_command.h
- Timestamp:
- Aug 25, 2005, 10:52:11 PM (19 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/util/shell_command.h
r5127 r5129 1 1 /*! 2 * @file shell .h2 * @file shell_command.h 3 3 * Definition of a on-screen-shell 4 4 */ 5 5 6 #ifndef _SHELL_ H7 #define _SHELL_ H6 #ifndef _SHELL_COMMAND_H 7 #define _SHELL_COMMAND_H 8 8 9 #include "element_2d.h" 10 #include "event_listener.h" 9 #include "base_object.h" 11 10 12 11 #include <stdarg.h> 13 12 14 #define SHELL_BUFFER_SIZE 16384 //!< The Size of the input-buffers (should be large enough to carry any kind of input) 13 typedef enum ShellParameterType 14 { 15 ShellParameterNull, 16 ShellParameterChar, 17 ShellParameterString, 18 ShellParameterInt, 19 ShellParameterUInt, 20 ShellParameterFloat, 21 /* ... */ 22 }; 15 23 16 24 // FORWARD DECLARATION 17 class Text;18 25 template<class T> class tList; 19 26 template<class T> class tIterator; 27 #define MAX_SHELL_COMMAND_SIZE 20 28 21 //! A class that is able to redirect all output to a openGL-Shell, and that one can use to input some commands 22 /** 23 * the major idea is, that all the Output can be redirected to the Shell, 24 * and does not have to be displayed to the opening Shell, this is good, 25 * for developers using Windows, where all output is otherwise redirected 26 * to stdout.txt 27 * 28 * Furthermore the Shell should enable us, to input some simple commands 29 * Each Class can tell check itself in to the Shell, and listen for commands. 30 * 31 * @todo implement what is written above :/ 32 */ 33 class Shell : public Element2D, public EventListener { 29 class ShellCommandBase 30 { 31 public: 32 static bool execute (const char* executionString); 34 33 35 public: 36 virtual ~Shell(); 37 /** @returns a Pointer to the only object of this Class */ 38 inline static Shell* getInstance() { if (!Shell::singletonRef) Shell::singletonRef = new Shell(); return Shell::singletonRef; }; 34 protected: 35 ShellCommandBase(const char* commandName, ClassID classID); 39 36 40 41 void activate(); 42 void deactivate(); 43 44 void setTextSize(unsigned int textSize, unsigned int lineSpacing = 1); 45 void rebuildText(); 46 47 // BUFFER // 48 void setBufferSize(unsigned int bufferSize) { this->bufferSize = bufferSize; }; 49 void setBufferDisplaySize(unsigned int bufferDisplaySize); 50 void flushBuffers(); 51 static bool addBufferLineStatic(const char* line, ...); 52 void addBufferLine(const char* line, va_list arg); 53 void printToDisplayBuffer(const char* text); 54 void moveBuffer(int lineCount); 55 const char* getBufferLine(unsigned int lineNumber); 56 57 // InputLine 58 void flushInputLine(); 59 void addCharacter(char character); 60 void addCharacters(const char* characters); 61 void removeCharacters(unsigned int characterCount = 1); 62 bool executeCommand(); 63 64 void setRepeatDelay(float repeatDelay, float repeatRate); 65 66 // EventListener 67 virtual void process(const Event &event); 68 69 // Element2D-functions 70 void tick(float dt); 71 virtual void draw() const; 72 73 void help() const; 74 void debug() const; 75 76 private: 77 bool autoComplete(); 78 bool classComplete(const char* classBegin); 79 bool objectComplete(const char* objectBegin, long classID); 80 bool functionComplete(const char* functionBegin); 81 82 bool generalComplete(const tList<const char>* stringList, const char* begin, const char* displayAs = "%s", const char* addBack = NULL, const char* addFront = NULL); 83 84 const tList<const char>* Shell::createCompleteList(const tList<const char>* inputList, const char* classNameBegin); 85 const tList<const char>* Shell::createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin); 86 87 // helpers // 88 Vector calculateLinePosition(unsigned int lineNumber); 37 static bool isRegistered(const char* commandName, ClassID classID); 89 38 90 39 91 40 private: 92 Shell();93 static Shell* singletonRef; //!< The singleton-reference to the only memeber of this class.41 char* commandName; //!< The name of the Command when executed 42 long classID; //!< The ID of the Class asociated to this Command 94 43 95 unsigned int bufferSize; //!< The Size of the buffer96 unsigned int bufferDisplaySize; //!< The Size of the Display-buffer, in lines (not in characters)97 44 98 Text* inputLineText; //!< The inputLine of the Shell 99 char* inputLine; //!< the Char-Array of the Buffer 100 float repeatRate; //!< The Repeat-Delay. 101 float repeatDelay; //!< The delay of the first Character of a given Character. 102 float delayed; //!< how much of the delay is remaining. 103 int pressedKey; //!< the pressed key that will be repeated. 104 105 tList<char>* buffer; //!< A list of stored char-arrays(strings) to store the history 106 tIterator<char>* bufferIterator; //!< An iterator for the Shells main buffer. 107 108 Text** bufferText; //!< A list of stored bufferTexts for the display of the buffer 109 unsigned int textSize; //!< The size of the text. 110 unsigned int lineSpacing; //!< The Spacing between lines. 111 unsigned int shellHeight; //!< The hight of the Shell in Pixels 112 bool bActive; //!< if the shell is active; 113 114 char bufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER for fast writing 115 char keepBufferArray[SHELL_BUFFER_SIZE]; //!< a BUFFER to have multi-non-newLine commands be copied into the shell. 116 bool keepBuffer; 117 118 // completion 119 tList<const char>* completionList; //!< A list of completions, that are io. 45 static tList<ShellCommandBase>* commandList; //!< A list of availiable commands. 120 46 }; 121 47 122 #endif /* _SHELL_H */ 48 //! keeps information about a ShellCommand 49 template<class T> class ShellCommand : public ShellCommandBase 50 { 51 public: 52 static void registerCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object = NULL); 53 54 static void unregisterCommand(const char* commandNaame, ClassID classID); 55 56 private: 57 ShellCommand(const char* command, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object = NULL); 58 59 60 public: 61 void* functionPointer; //!< The pointer to the function of the Class (or static pointer if ClassID == CL_NULL ) 62 T* Object; //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL ) 63 }; 64 65 template<class T> 66 ShellCommand<T>::ShellCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object) 67 : ShellCommandBase (command, classID) 68 { 69 70 } 71 72 template<class T> 73 void ShellCommand<T>::registerCommand(const char* commandName, void* pointerToFunction, ClassID classID, ShellParameterType param1Type, void* Object) 74 { 75 if (isRegistered() == true) 76 return; 77 else 78 { 79 ShellCommand<T>* newCommand = new ShellCommand<T>(command); 80 elem->functionPointer = pointerToFunction; 81 elem->parameter1 = param1Type; 82 elem->Object = Object; 83 84 85 } 86 } 87 88 #endif /* _SHELL_COMMAND_H */
Note: See TracChangeset
for help on using the changeset viewer.