Changeset 1313
- Timestamp:
- May 17, 2008, 3:58:19 AM (17 years ago)
- Location:
- code/branches/console/src
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/console/src/core/CMakeLists.txt
r1312 r1313 18 18 InputBuffer.cc 19 19 CommandExecutor.cc 20 Shell.cc 20 21 Language.cc 21 22 ClassTreeMask.cc -
code/branches/console/src/core/ClassManager.h
r1062 r1313 49 49 #include "Identifier.h" 50 50 #include "IdentifierDistributor.h" 51 #include "Debug.h" 51 52 52 53 namespace orxonox -
code/branches/console/src/core/ConfigValueContainer.cc
r1062 r1313 123 123 if (index < this->valueVector_.size()) 124 124 { 125 // Erase the entry from the vector, change (shift) all entries beginning with index in the config file, remove the last entry from the file 125 126 this->valueVector_.erase(this->valueVector_.begin() + index); 126 127 for (unsigned int i = index; i < this->valueVector_.size(); i++) -
code/branches/console/src/core/ConfigValueContainer.h
r1062 r1313 107 107 void update(); 108 108 109 bool parse(const std::string& input); 110 bool parse(const std::string& input, const MultiTypeMath& defvalue); 111 112 bool set(unsigned int index, const std::string& input); 113 bool tset(unsigned int index, const std::string& input); 114 bool parse(unsigned int index, const std::string& input); 115 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue); 116 109 117 /** @brief Converts the config-value to a string. @return The string */ 110 118 inline std::string toString() const … … 115 123 116 124 private: 117 bool parse(const std::string& input);118 bool parse(const std::string& input, const MultiTypeMath& defvalue);119 120 bool set(unsigned int index, const std::string& input);121 bool tset(unsigned int index, const std::string& input);122 bool parse(unsigned int index, const std::string& input);123 bool parse(unsigned int index, const std::string& input, const MultiTypeMath& defvalue);124 125 125 bool bIsVector_; //!< True if the container contains a std::vector 126 126 -
code/branches/console/src/core/CorePrereqs.h
r1312 r1313 140 140 class OutputHandler; 141 141 class Shell; 142 class ShellListener; 142 143 template <class T> 143 144 class SubclassIdentifier; -
code/branches/console/src/core/Identifier.h
r1064 r1313 63 63 #include "Debug.h" 64 64 #include "Iterator.h" 65 #include "MetaObjectList.h" 65 66 #include "util/String.h" 66 67 -
code/branches/console/src/core/InputBuffer.cc
r1312 r1313 45 45 this->keyboard_ = InputManager::getSingleton().getKeyboard(); 46 46 this->buffer_ = ""; 47 this->cursor_ = 0; 47 48 } 48 49 … … 52 53 this->keyboard_ = InputManager::getSingleton().getKeyboard(); 53 54 this->buffer_ = ""; 54 } 55 56 void InputBuffer::set(const std::string& input) 55 this->cursor_ = 0; 56 } 57 58 void InputBuffer::unregisterListener(InputBufferListener* listener) 59 { 60 for (std::list<InputBufferListenerTuple>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 61 { 62 if ((*it).listener_ == listener) 63 this->listeners_.erase(it++); 64 else 65 ++it; 66 } 67 } 68 69 void InputBuffer::set(const std::string& input, bool update) 70 { 71 this->clear(false); 72 this->insert(input, update); 73 } 74 75 void InputBuffer::insert(const std::string& input, bool update) 76 { 77 for (unsigned int i = 0; i < input.size(); ++i) 78 { 79 this->insert(input[i], false); 80 81 if (update) 82 this->updated(input[i], false); 83 } 84 85 if (update) 86 this->updated(); 87 } 88 89 void InputBuffer::insert(const char& input, bool update) 90 { 91 if (this->charIsAllowed(input)) 92 { 93 this->buffer_.insert(this->cursor_, 1, input); 94 ++this->cursor_; 95 } 96 97 if (update) 98 this->updated(input, true); 99 } 100 101 void InputBuffer::clear(bool update) 57 102 { 58 103 this->buffer_ = ""; 59 this->append(input); 60 } 61 62 void InputBuffer::append(const std::string& input) 63 { 64 for (unsigned int i = 0; i < input.size(); i++) 65 { 66 if (this->charIsAllowed(input[i])) 67 this->buffer_ += input[i]; 68 69 this->updated(input[i], false); 70 } 71 this->updated(); 72 } 73 74 void InputBuffer::append(const char& input) 75 { 76 if (this->charIsAllowed(input)) 77 this->buffer_ += input; 78 79 this->updated(input, true); 80 } 81 82 void InputBuffer::clear() 83 { 84 this->buffer_ = ""; 85 this->updated(); 86 } 87 88 void InputBuffer::removeLast() 89 { 90 this->buffer_ = this->buffer_.substr(0, this->buffer_.size() - 1); 91 this->updated(); 104 this->cursor_ = 0; 105 106 if (update) 107 this->updated(); 108 } 109 110 void InputBuffer::removeBehindCursor(bool update) 111 { 112 if (this->cursor_ > 0) 113 { 114 --this->cursor_; 115 this->buffer_.erase(this->cursor_, 1); 116 117 if (update) 118 this->updated(); 119 } 120 } 121 122 void InputBuffer::removeAtCursor(bool update) 123 { 124 if (this->cursor_ < this->buffer_.size()) 125 { 126 this->buffer_.erase(this->cursor_, 1); 127 128 if (update) 129 this->updated(); 130 } 92 131 } 93 132 … … 130 169 if (e.key == OIS::KC_V) 131 170 { 132 this-> append(fromClipboard());171 this->insert(fromClipboard()); 133 172 return true; 134 173 } … … 149 188 if (e.key == OIS::KC_INSERT) 150 189 { 151 this-> append(fromClipboard());190 this->insert(fromClipboard()); 152 191 return true; 153 192 } … … 160 199 } 161 200 162 this-> append((char)e.text);201 this->insert((char)e.text); 163 202 return true; 164 203 } -
code/branches/console/src/core/InputBuffer.h
r1312 r1313 102 102 } 103 103 104 void set(const std::string& input); 105 void append(const std::string& input); 106 void append(const char& input); 107 void removeLast(); 108 void clear(); 104 void unregisterListener(InputBufferListener* listener); 105 106 void set(const std::string& input, bool update = true); 107 void insert(const std::string& input, bool update = true); 108 void insert(const char& input, bool update = true); 109 void clear(bool update = true); 110 void removeAtCursor(bool update = true); 111 void removeBehindCursor(bool update = true); 109 112 110 113 void updated(); … … 113 116 inline std::string get() const 114 117 { return this->buffer_; } 118 inline unsigned int getSize() const 119 { return this->buffer_.size(); } 120 121 inline unsigned int getCursorPosition() const 122 { return this->cursor_; } 123 inline void setCursorPosition(unsigned int cursor) 124 { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } } 125 inline void setCursorToEnd() 126 { this->cursor_ = this->buffer_.size(); } 127 inline void setCursorToBegin() 128 { this->cursor_ = 0; } 129 inline void increaseCursor() 130 { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } } 131 inline void decreaseCursor() 132 { if (this->cursor_ > 0) { --this->cursor_; } } 115 133 116 134 private: … … 124 142 std::list<InputBufferListenerTuple> listeners_; 125 143 std::string allowedChars_; 144 unsigned int cursor_; 126 145 }; 127 146 } -
code/branches/console/src/core/InputHandler.cc
r1136 r1313 34 34 #include "InputHandler.h" 35 35 #include "Debug.h" 36 #include "Iterator.h" 36 37 #include "util/Convert.h" 37 38 #include "InputEventListener.h" -
code/branches/console/src/core/Iterator.h
r1063 r1313 50 50 51 51 #include "ObjectList.h" 52 #include "Debug.h"53 52 54 53 namespace orxonox -
code/branches/console/src/core/Language.cc
r1062 r1313 37 37 38 38 #include "CoreSettings.h" 39 40 #include "Debug.h" 39 41 40 42 namespace orxonox -
code/branches/console/src/core/Language.h
r1064 r1313 50 50 #include <map> 51 51 #include <string> 52 53 52 54 53 #define AddLanguageEntry(label, fallbackstring) \ -
code/branches/console/src/core/OrxonoxClass.cc
r1056 r1313 33 33 34 34 #include "OrxonoxClass.h" 35 #include "MetaObjectList.h" 36 #include "Identifier.h" 35 37 36 38 namespace orxonox … … 39 41 OrxonoxClass::OrxonoxClass() 40 42 { 43 this->metaList_ = new MetaObjectList(); 44 41 45 this->setConfigValues(); 42 46 … … 48 52 OrxonoxClass::~OrxonoxClass() 49 53 { 54 delete this->metaList_; 55 50 56 // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class 51 57 if (this->parents_) 52 58 delete this->parents_; 53 59 } 60 61 /** @brief Returns true if the objects class is of the given type or a derivative. */ 62 bool OrxonoxClass::isA(const Identifier* identifier) 63 { return this->getIdentifier()->isA(identifier); } 64 /** @brief Returns true if the objects class is exactly of the given type. */ 65 bool OrxonoxClass::isExactlyA(const Identifier* identifier) 66 { return this->getIdentifier()->isExactlyA(identifier); } 67 /** @brief Returns true if the objects class is a child of the given type. */ 68 bool OrxonoxClass::isChildOf(const Identifier* identifier) 69 { return this->getIdentifier()->isChildOf(identifier); } 70 /** @brief Returns true if the objects class is a direct child of the given type. */ 71 bool OrxonoxClass::isDirectChildOf(const Identifier* identifier) 72 { return this->getIdentifier()->isDirectChildOf(identifier); } 73 /** @brief Returns true if the objects class is a parent of the given type. */ 74 bool OrxonoxClass::isParentOf(const Identifier* identifier) 75 { return this->getIdentifier()->isParentOf(identifier); } 76 /** @brief Returns true if the objects class is a direct parent of the given type. */ 77 bool OrxonoxClass::isDirectParentOf(const Identifier* identifier) 78 { return this->getIdentifier()->isDirectParentOf(identifier); } 79 80 81 /** @brief Returns true if the objects class is of the given type or a derivative. */ 82 bool OrxonoxClass::isA(const SubclassIdentifier<class B>* identifier) 83 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 84 /** @brief Returns true if the objects class is exactly of the given type. */ 85 bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B>* identifier) 86 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } 87 /** @brief Returns true if the objects class is a child of the given type. */ 88 bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B>* identifier) 89 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 90 /** @brief Returns true if the objects class is a direct child of the given type. */ 91 bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B>* identifier) 92 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 93 /** @brief Returns true if the objects class is a parent of the given type. */ 94 bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B>* identifier) 95 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 96 /** @brief Returns true if the objects class is a direct parent of the given type. */ 97 bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B>* identifier) 98 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 99 100 101 /** @brief Returns true if the objects class is of the given type or a derivative. */ 102 bool OrxonoxClass::isA(const SubclassIdentifier<class B> identifier) 103 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 104 /** @brief Returns true if the objects class is exactly of the given type. */ 105 bool OrxonoxClass::isExactlyA(const SubclassIdentifier<class B> identifier) 106 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } 107 /** @brief Returns true if the objects class is a child of the given type. */ 108 bool OrxonoxClass::isChildOf(const SubclassIdentifier<class B> identifier) 109 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 110 /** @brief Returns true if the objects class is a direct child of the given type. */ 111 bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<class B> identifier) 112 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 113 /** @brief Returns true if the objects class is a parent of the given type. */ 114 bool OrxonoxClass::isParentOf(const SubclassIdentifier<class B> identifier) 115 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 116 /** @brief Returns true if the objects class is a direct parent of the given type. */ 117 bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<class B> identifier) 118 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 119 120 121 /** @brief Returns true if the objects class is of the given type or a derivative. */ 122 bool OrxonoxClass::isA(const OrxonoxClass* object) 123 { return this->getIdentifier()->isA(object->getIdentifier()); } 124 /** @brief Returns true if the objects class is exactly of the given type. */ 125 bool OrxonoxClass::isExactlyA(const OrxonoxClass* object) 126 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 127 /** @brief Returns true if the objects class is a child of the given type. */ 128 bool OrxonoxClass::isChildOf(const OrxonoxClass* object) 129 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 130 /** @brief Returns true if the objects class is a direct child of the given type. */ 131 bool OrxonoxClass::isDirectChildOf(const OrxonoxClass* object) 132 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 133 /** @brief Returns true if the objects class is a parent of the given type. */ 134 bool OrxonoxClass::isParentOf(const OrxonoxClass* object) 135 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 136 /** @brief Returns true if the objects class is a direct child of the given type. */ 137 bool OrxonoxClass::isDirectParentOf(const OrxonoxClass* object) 138 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 54 139 } -
code/branches/console/src/core/OrxonoxClass.h
r1062 r1313 43 43 #include <string> 44 44 45 #include "MetaObjectList.h"46 #include "Iterator.h"47 48 45 namespace orxonox 49 46 { … … 75 72 76 73 /** @brief Returns the MetaObjectList of the object, containing a link to all ObjectLists and ObjectListElements the object is registered in. @return The list */ 77 inline MetaObjectList& getMetaList() { return this->metaList_; }74 inline MetaObjectList& getMetaList() { return (*this->metaList_); } 78 75 79 76 80 /** @brief Returns true if the objects class is of the given type or a derivative. */ 81 inline bool isA(const Identifier* identifier) 82 { return this->getIdentifier()->isA(identifier); } 83 /** @brief Returns true if the objects class is exactly of the given type. */ 84 inline bool isExactlyA(const Identifier* identifier) 85 { return this->getIdentifier()->isExactlyA(identifier); } 86 /** @brief Returns true if the objects class is a child of the given type. */ 87 inline bool isChildOf(const Identifier* identifier) 88 { return this->getIdentifier()->isChildOf(identifier); } 89 /** @brief Returns true if the objects class is a direct child of the given type. */ 90 inline bool isDirectChildOf(const Identifier* identifier) 91 { return this->getIdentifier()->isDirectChildOf(identifier); } 92 /** @brief Returns true if the objects class is a parent of the given type. */ 93 inline bool isParentOf(const Identifier* identifier) 94 { return this->getIdentifier()->isParentOf(identifier); } 95 /** @brief Returns true if the objects class is a direct parent of the given type. */ 96 inline bool isDirectParentOf(const Identifier* identifier) 97 { return this->getIdentifier()->isDirectParentOf(identifier); } 77 bool isA(const Identifier* identifier); 78 bool isExactlyA(const Identifier* identifier); 79 bool isChildOf(const Identifier* identifier); 80 bool isDirectChildOf(const Identifier* identifier); 81 bool isParentOf(const Identifier* identifier); 82 bool isDirectParentOf(const Identifier* identifier); 98 83 84 bool isA(const SubclassIdentifier<class B>* identifier); 85 bool isExactlyA(const SubclassIdentifier<class B>* identifier); 86 bool isChildOf(const SubclassIdentifier<class B>* identifier); 87 bool isDirectChildOf(const SubclassIdentifier<class B>* identifier); 88 bool isParentOf(const SubclassIdentifier<class B>* identifier); 89 bool isDirectParentOf(const SubclassIdentifier<class B>* identifier); 99 90 100 /** @brief Returns true if the objects class is of the given type or a derivative. */ 101 inline bool isA(const SubclassIdentifier<class B>* identifier) 102 { return this->getIdentifier()->isA(identifier->getIdentifier()); } 103 /** @brief Returns true if the objects class is exactly of the given type. */ 104 inline bool isExactlyA(const SubclassIdentifier<class B>* identifier) 105 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); } 106 /** @brief Returns true if the objects class is a child of the given type. */ 107 inline bool isChildOf(const SubclassIdentifier<class B>* identifier) 108 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); } 109 /** @brief Returns true if the objects class is a direct child of the given type. */ 110 inline bool isDirectChildOf(const SubclassIdentifier<class B>* identifier) 111 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); } 112 /** @brief Returns true if the objects class is a parent of the given type. */ 113 inline bool isParentOf(const SubclassIdentifier<class B>* identifier) 114 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); } 115 /** @brief Returns true if the objects class is a direct parent of the given type. */ 116 inline bool isDirectParentOf(const SubclassIdentifier<class B>* identifier) 117 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); } 91 bool isA(const SubclassIdentifier<class B> identifier); 92 bool isExactlyA(const SubclassIdentifier<class B> identifier); 93 bool isChildOf(const SubclassIdentifier<class B> identifier); 94 bool isDirectChildOf(const SubclassIdentifier<class B> identifier); 95 bool isParentOf(const SubclassIdentifier<class B> identifier); 96 bool isDirectParentOf(const SubclassIdentifier<class B> identifier); 118 97 119 120 /** @brief Returns true if the objects class is of the given type or a derivative. */ 121 inline bool isA(const SubclassIdentifier<class B> identifier) 122 { return this->getIdentifier()->isA(identifier.getIdentifier()); } 123 /** @brief Returns true if the objects class is exactly of the given type. */ 124 inline bool isExactlyA(const SubclassIdentifier<class B> identifier) 125 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); } 126 /** @brief Returns true if the objects class is a child of the given type. */ 127 inline bool isChildOf(const SubclassIdentifier<class B> identifier) 128 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); } 129 /** @brief Returns true if the objects class is a direct child of the given type. */ 130 inline bool isDirectChildOf(const SubclassIdentifier<class B> identifier) 131 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); } 132 /** @brief Returns true if the objects class is a parent of the given type. */ 133 inline bool isParentOf(const SubclassIdentifier<class B> identifier) 134 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); } 135 /** @brief Returns true if the objects class is a direct parent of the given type. */ 136 inline bool isDirectParentOf(const SubclassIdentifier<class B> identifier) 137 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); } 138 139 140 /** @brief Returns true if the objects class is of the given type or a derivative. */ 141 inline bool isA(const OrxonoxClass* object) 142 { return this->getIdentifier()->isA(object->getIdentifier()); } 143 /** @brief Returns true if the objects class is exactly of the given type. */ 144 inline bool isExactlyA(const OrxonoxClass* object) 145 { return this->getIdentifier()->isExactlyA(object->getIdentifier()); } 146 /** @brief Returns true if the objects class is a child of the given type. */ 147 inline bool isChildOf(const OrxonoxClass* object) 148 { return this->getIdentifier()->isChildOf(object->getIdentifier()); } 149 /** @brief Returns true if the objects class is a direct child of the given type. */ 150 inline bool isDirectChildOf(const OrxonoxClass* object) 151 { return this->getIdentifier()->isDirectChildOf(object->getIdentifier()); } 152 /** @brief Returns true if the objects class is a parent of the given type. */ 153 inline bool isParentOf(const OrxonoxClass* object) 154 { return this->getIdentifier()->isParentOf(object->getIdentifier()); } 155 /** @brief Returns true if the objects class is a direct child of the given type. */ 156 inline bool isDirectParentOf(const OrxonoxClass* object) 157 { return this->getIdentifier()->isDirectParentOf(object->getIdentifier()); } 98 bool isA(const OrxonoxClass* object); 99 bool isExactlyA(const OrxonoxClass* object); 100 bool isChildOf(const OrxonoxClass* object); 101 bool isDirectChildOf(const OrxonoxClass* object); 102 bool isParentOf(const OrxonoxClass* object); 103 bool isDirectParentOf(const OrxonoxClass* object); 158 104 159 105 private: 160 Identifier* identifier_; 106 Identifier* identifier_; //!< The Identifier of the object 161 107 std::set<const Identifier*>* parents_; //!< List of all parents of the object 162 MetaObjectList metaList_;//!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in108 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 163 109 }; 164 110 } -
code/branches/console/src/core/OutputBuffer.cc
r1312 r1313 33 33 namespace orxonox 34 34 { 35 OutputBuffer& OutputBuffer::getOutputBuffer()36 {37 static OutputBuffer instance;38 return instance;39 }40 41 35 void OutputBuffer::registerListener(OutputBufferListener* listener) 42 36 { 43 this->listeners_.insert( listener);37 this->listeners_.insert(this->listeners_.end(), listener); 44 38 } 45 39 46 40 void OutputBuffer::unregisterListener(OutputBufferListener* listener) 47 41 { 48 std::set<OutputBufferListener*>::iterator it = this->listeners_.find(listener); 49 if (it != this->listeners_.end()) 50 this->listeners_.erase(it); 42 for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 43 { 44 if ((*it) == listener) 45 this->listeners_.erase(it++); 46 else 47 ++it; 48 } 51 49 } 52 50 … … 63 61 this->stream_.flush(); 64 62 63 // Return true if this was a whole new line, ended by \n 65 64 return (!eof); 66 65 } … … 68 67 void OutputBuffer::callListeners() 69 68 { 70 for (std:: set<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it)71 (*it)-> bufferChanged();69 for (std::list<OutputBufferListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) 70 (*it)->outputChanged(); 72 71 } 73 72 } -
code/branches/console/src/core/OutputBuffer.h
r1312 r1313 30 30 #define _OutputBuffer_H__ 31 31 32 #include < set>32 #include <list> 33 33 #include <sstream> 34 34 … … 37 37 namespace orxonox 38 38 { 39 class OutputBufferListener39 class _CoreExport OutputBufferListener 40 40 { 41 41 friend class OutputBuffer; 42 42 43 virtual void outputChanged() = 0; 43 44 }; … … 46 47 { 47 48 public: 48 static OutputBuffer& getOutputBuffer(); 49 OutputBuffer() {} 50 ~OutputBuffer() {} 49 51 50 52 template <class T> … … 53 55 this->stream_ << object; 54 56 this->callListeners(); 55 return &this;57 return *this; 56 58 } 57 59 … … 86 88 void unregisterListener(OutputBufferListener* listener); 87 89 90 inline operator std::stringstream&() 91 { 92 return this->stream_; 93 } 94 88 95 private: 89 OutputBuffer() {}90 OutputBuffer(const OutputBuffer& other);91 ~OutputBuffer() {}92 93 96 void callListeners(); 94 97 95 98 std::stringstream stream_; 96 std:: set<OutputBufferListener*> listeners_;99 std::list<OutputBufferListener*> listeners_; 97 100 }; 98 101 } -
code/branches/console/src/core/OutputHandler.cc
r1230 r1313 101 101 } 102 102 103 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 104 Shell::getInstance().getOutputBuffer() << sb; 105 103 106 return *this; 104 107 } … … 119 122 this->logfile_.flush(); 120 123 } 124 125 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 126 manipulator(Shell::getInstance().getOutputBuffer()); 121 127 122 128 return *this; … … 139 145 } 140 146 147 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 148 manipulator(Shell::getInstance().getOutputBuffer()); 149 141 150 return *this; 142 151 } … … 158 167 } 159 168 169 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 170 manipulator(Shell::getInstance().getOutputBuffer()); 171 160 172 return *this; 161 173 } -
code/branches/console/src/core/OutputHandler.h
r1230 r1313 43 43 #include <fstream> 44 44 #include <string> 45 46 #include "Shell.h" 45 47 46 48 namespace orxonox … … 154 156 } 155 157 158 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_) 159 Shell::getInstance().getOutputBuffer() << output; 160 156 161 return *this; 157 162 } … … 175 180 } 176 181 182 if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel()) 183 Shell::getInstance().getOutputBuffer() << output; 184 177 185 return out; 178 186 } -
code/branches/console/src/core/Shell.cc
r1312 r1313 27 27 */ 28 28 29 #include "CorePrereqs.h" 30 31 #include "OrxonoxClass.h" 32 #include "InputBuffer.h" 33 #include "OutputBuffer.h" 29 #include "Shell.h" 30 #include "CommandExecutor.h" 31 #include "CoreIncludes.h" 32 #include "ConfigValueIncludes.h" 33 34 #define SHELL_UPDATE_LISTENERS(function) \ 35 for (std::list<ShellListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ++it) \ 36 (*it)->function() 34 37 35 38 namespace orxonox … … 37 40 Shell::Shell() 38 41 { 42 RegisterRootObject(Shell); 43 44 this->scrollPosition_ = 0; 45 this->maxHistoryLength_ = 100; 46 this->historyPosition_ = 0; 47 this->historyOffset_ = 0; 48 49 this->clearLines(); 50 39 51 this->inputBuffer_.registerListener(this, &Shell::inputChanged, true); 40 52 this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false); 41 53 this->inputBuffer_.registerListener(this, &Shell::hintandcomplete, '\t', true); 42 this->inputBuffer_.registerListener(this, &Shell::clear, '§', true);43 54 this->inputBuffer_.registerListener(this, &Shell::backspace, '\b', true); 55 this->inputBuffer_.registerListener(this, &Shell::deletechar, OIS::KC_DELETE); 44 56 this->inputBuffer_.registerListener(this, &Shell::exit, (char)27, true); 45 57 this->inputBuffer_.registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT); 46 58 this->inputBuffer_.registerListener(this, &Shell::cursor_left, OIS::KC_LEFT); 59 this->inputBuffer_.registerListener(this, &Shell::cursor_end, OIS::KC_END); 60 this->inputBuffer_.registerListener(this, &Shell::cursor_home, OIS::KC_HOME); 47 61 this->inputBuffer_.registerListener(this, &Shell::history_up, OIS::KC_UP); 48 62 this->inputBuffer_.registerListener(this, &Shell::history_down, OIS::KC_DOWN); 49 63 this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP); 50 64 this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN); 65 66 this->setConfigValues(); 51 67 } 52 68 53 69 Shell& Shell::getInstance() 54 70 { 55 static instance Shell;71 static Shell instance; 56 72 return instance; 57 73 } 58 74 59 75 void Shell::setConfigValues() 76 { 77 SetConfigValue(maxHistoryLength_, 100); 78 SetConfigValue(historyOffset_, 0); 79 SetConfigValueVector(commandHistory_, std::vector<std::string>(1, "")); 80 81 if (this->historyOffset_ >= this->maxHistoryLength_) 82 this->historyOffset_ = 0; 83 84 while (this->commandHistory_.size() > this->maxHistoryLength_) 85 { 86 unsigned int index = this->commandHistory_.size() - 1; 87 this->commandHistory_.erase(this->commandHistory_.begin() + index); 88 ModifyConfigValue(commandHistory_, remove, index); 89 } 90 } 91 92 void Shell::registerListener(ShellListener* listener) 93 { 94 this->listeners_.insert(this->listeners_.end(), listener); 95 } 96 97 void Shell::unregisterListener(ShellListener* listener) 98 { 99 for (std::list<ShellListener*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 100 { 101 if ((*it) == listener) 102 this->listeners_.erase(it++); 103 else 104 ++it; 105 } 106 } 107 108 void Shell::setCursorPosition(unsigned int cursor) 109 { 110 this->inputBuffer_.setCursorPosition(cursor); 111 SHELL_UPDATE_LISTENERS(cursorChanged); 112 } 113 114 void Shell::setInput(const std::string& input) 115 { 116 this->inputBuffer_.set(input); 117 this->inputChanged(); 118 } 119 120 void Shell::addLine(const std::string& line, unsigned int level) 121 { 122 if ((*this->lines_.begin()) != "") 123 { 124 orxonox::OutputHandler::getOutStream().setOutputLevel(level) << std::endl; 125 } 126 orxonox::OutputHandler::getOutStream().setOutputLevel(level) << line << std::endl; 127 } 128 129 void Shell::clearLines() 130 { 131 this->lines_.clear(); 132 this->lines_.insert(this->lines_.begin(), ""); 133 this->scrollIterator_ = this->lines_.begin(); 134 135 this->scrollPosition_ = 0; 136 137 SHELL_UPDATE_LISTENERS(linesChanged); 138 } 139 140 std::list<std::string>::const_iterator Shell::getNewestLineIterator() const 141 { 142 if (this->scrollPosition_) 143 return this->scrollIterator_; 144 else 145 return this->lines_.begin(); 146 } 147 148 std::list<std::string>::const_iterator Shell::getEndIterator() const 149 { 150 return this->lines_.end(); 151 } 152 153 void Shell::addToHistory(const std::string& command) 154 { 155 this->historyOffset_ = (this->historyOffset_ + 1) % this->maxHistoryLength_; 156 ModifyConfigValue(commandHistory_, set, this->historyOffset_, command); 157 this->commandHistory_[this->historyOffset_] = command; 158 this->historyPosition_ = 0; 159 } 160 161 std::string Shell::getFromHistory() const 162 { 163 return this->commandHistory_[(this->historyOffset_ - this->historyPosition_) % this->maxHistoryLength_]; 164 } 60 165 61 166 void Shell::outputChanged() 167 { 168 std::string output; 169 while (this->outputBuffer_.getLine(&output)) 170 { 171 (*this->lines_.begin()) += output; 172 this->lines_.insert(this->lines_.begin(), ""); 173 174 if (this->scrollPosition_) 175 this->scrollPosition_++; 176 else 177 this->scrollIterator_ = this->lines_.begin(); 178 179 SHELL_UPDATE_LISTENERS(linesChanged); 180 SHELL_UPDATE_LISTENERS(lineAdded); 181 } 182 183 (*this->lines_.begin()) += output; 184 SHELL_UPDATE_LISTENERS(onlyLastLineChanged); 185 } 186 62 187 void Shell::inputChanged() 188 { 189 SHELL_UPDATE_LISTENERS(inputChanged); 190 SHELL_UPDATE_LISTENERS(cursorChanged); 191 } 192 63 193 void Shell::execute() 194 { 195 if (CommandExecutor::execute(this->inputBuffer_.get())) 196 this->addLine(this->inputBuffer_.get(), 0); 197 else 198 this->addLine("Error: Can't execute \"" + this->inputBuffer_.get() + "\".", 1); 199 200 this->clear(); 201 } 202 64 203 void Shell::hintandcomplete() 204 { 205 this->addLine(CommandExecutor::hint(this->inputBuffer_.get()), 0); 206 this->inputBuffer_.set(CommandExecutor::complete(this->inputBuffer_.get())); 207 208 this->inputChanged(); 209 } 210 65 211 void Shell::backspace() 212 { 213 this->inputBuffer_.removeBehindCursor(); 214 SHELL_UPDATE_LISTENERS(inputChanged); 215 SHELL_UPDATE_LISTENERS(cursorChanged); 216 } 217 218 void Shell::deletechar() 219 { 220 this->inputBuffer_.removeAtCursor(); 221 SHELL_UPDATE_LISTENERS(inputChanged); 222 } 223 66 224 void Shell::clear() 225 { 226 this->inputBuffer_.clear(); 227 SHELL_UPDATE_LISTENERS(inputChanged); 228 SHELL_UPDATE_LISTENERS(cursorChanged); 229 } 230 67 231 void Shell::cursor_right() 232 { 233 this->inputBuffer_.increaseCursor(); 234 SHELL_UPDATE_LISTENERS(cursorChanged); 235 } 236 68 237 void Shell::cursor_left() 238 { 239 this->inputBuffer_.decreaseCursor(); 240 SHELL_UPDATE_LISTENERS(cursorChanged); 241 } 242 243 void Shell::cursor_end() 244 { 245 this->inputBuffer_.setCursorToEnd(); 246 SHELL_UPDATE_LISTENERS(cursorChanged); 247 } 248 249 void Shell::cursor_home() 250 { 251 this->inputBuffer_.setCursorToBegin(); 252 SHELL_UPDATE_LISTENERS(cursorChanged); 253 } 254 69 255 void Shell::history_up() 256 { 257 if (this->historyPosition_ < (this->commandHistory_.size() - 1)) 258 { 259 this->historyPosition_++; 260 this->inputBuffer_.set(this->getFromHistory()); 261 } 262 } 263 70 264 void Shell::history_down() 265 { 266 if (this->historyPosition_ > 0) 267 { 268 this->historyPosition_++; 269 this->inputBuffer_.set(this->getFromHistory()); 270 } 271 } 272 71 273 void Shell::scroll_up() 274 { 275 if (this->scrollIterator_ != this->lines_.end()) 276 { 277 ++this->scrollIterator_; 278 ++this->scrollPosition_; 279 280 SHELL_UPDATE_LISTENERS(linesChanged); 281 } 282 } 283 72 284 void Shell::scroll_down() 285 { 286 if (this->scrollIterator_ != this->lines_.begin()) 287 { 288 --this->scrollIterator_; 289 --this->scrollPosition_; 290 291 SHELL_UPDATE_LISTENERS(linesChanged); 292 } 293 } 294 73 295 void Shell::exit() 296 { 297 if (this->inputBuffer_.getSize() > 0) 298 { 299 this->clear(); 300 return; 301 } 302 303 this->clear(); 304 SHELL_UPDATE_LISTENERS(exit); 305 } 74 306 } -
code/branches/console/src/core/Shell.h
r1312 r1313 30 30 #define _Shell_H__ 31 31 32 #include <list> 33 #include <vector> 34 32 35 #include "CorePrereqs.h" 33 36 … … 38 41 namespace orxonox 39 42 { 40 class ShellListener43 class _CoreExport ShellListener 41 44 { 42 virtual void outputChanged() = 0; 43 virtual void lastLineChanged() = 0; 44 virtual void inputChanged() = 0; 45 virtual void exit() = 0; 46 } 45 friend class Shell; 46 47 virtual void linesChanged() {} 48 virtual void onlyLastLineChanged() {} 49 virtual void lineAdded() {} 50 virtual void inputChanged() {} 51 virtual void cursorChanged() {} 52 virtual void exit() {} 53 }; 47 54 48 55 class _CoreExport Shell : virtual public OrxonoxClass, public InputBufferListener, public OutputBufferListener … … 53 60 virtual void setConfigValues(); 54 61 62 void registerListener(ShellListener* listener); 63 void unregisterListener(ShellListener* listener); 64 65 inline InputBuffer& getInputBuffer() 66 { return this->inputBuffer_; } 67 inline OutputBuffer& getOutputBuffer() 68 { return this->outputBuffer_; } 69 70 void setCursorPosition(unsigned int cursor); 71 inline unsigned int getCursorPosition() const 72 { return this->inputBuffer_.getCursorPosition(); } 73 74 void setInput(const std::string& input); 75 76 inline void clearInput() 77 { this->setInput(""); } 78 inline std::string getInput() const 79 { return this->inputBuffer_.get(); } 80 81 inline std::list<std::string>::const_iterator getNewestLineIterator() const; 82 inline std::list<std::string>::const_iterator getEndIterator() const; 83 84 void addLine(const std::string& line, unsigned int level); 85 void clearLines(); 86 87 inline unsigned int getNumLines() const 88 { return this->lines_.size(); } 89 inline unsigned int getScrollPosition() const 90 { return this->scrollPosition_; } 91 55 92 private: 56 93 Shell(); 57 94 Shell(const Shell& other); 58 ~Shell() {} 95 virtual ~Shell() {} 96 97 void addToHistory(const std::string& command); 98 std::string getFromHistory() const; 59 99 60 100 virtual void outputChanged(); … … 63 103 void hintandcomplete(); 64 104 void backspace(); 105 void deletechar(); 106 void clear(); 65 107 void cursor_right(); 66 108 void cursor_left(); 109 void cursor_end(); 110 void cursor_home(); 67 111 void history_up(); 68 112 void history_down(); … … 71 115 void exit(); 72 116 117 std::list<ShellListener*> listeners_; 73 118 InputBuffer inputBuffer_; 74 OutputBuffer OutputBuffer_;119 OutputBuffer outputBuffer_; 75 120 std::list<std::string> lines_; 76 unsigned int cursor_; 121 std::list<std::string>::const_iterator scrollIterator_; 122 unsigned int scrollPosition_; 77 123 std::vector<std::string> commandHistory_; 78 124 unsigned int maxHistoryLength_; 125 unsigned int historyPosition_; 126 unsigned int historyOffset_; 79 127 }; 80 128 } -
code/branches/console/src/orxonox/Orxonox.cc
r1188 r1313 115 115 void removeLast() const 116 116 { 117 this->ib_->remove Last();117 this->ib_->removeBehindCursor(); 118 118 } 119 119 void exit() const -
code/branches/console/src/orxonox/console/InGameConsole.cc
r1181 r1313 92 92 93 93 void InGameConsole::removeLast(){ 94 this->ib_->remove Last();94 this->ib_->removeBehindCursor(); 95 95 } 96 96
Note: See TracChangeset
for help on using the changeset viewer.