Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1313


Ignore:
Timestamp:
May 17, 2008, 3:58:19 AM (16 years ago)
Author:
landauf
Message:
  • implemented Shell, but not yet linked with the graphical console
  • added new features (cursor, OIS::KeyCode listener) to InputBuffer
  • changed some includes to avoid circular header-dependencies in OrxonoxClass and Shell
Location:
code/branches/console/src
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • code/branches/console/src/core/CMakeLists.txt

    r1312 r1313  
    1818  InputBuffer.cc
    1919  CommandExecutor.cc
     20  Shell.cc
    2021  Language.cc
    2122  ClassTreeMask.cc
  • code/branches/console/src/core/ClassManager.h

    r1062 r1313  
    4949#include "Identifier.h"
    5050#include "IdentifierDistributor.h"
     51#include "Debug.h"
    5152
    5253namespace orxonox
  • code/branches/console/src/core/ConfigValueContainer.cc

    r1062 r1313  
    123123            if (index < this->valueVector_.size())
    124124            {
     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
    125126                this->valueVector_.erase(this->valueVector_.begin() + index);
    126127                for (unsigned int i = index; i < this->valueVector_.size(); i++)
  • code/branches/console/src/core/ConfigValueContainer.h

    r1062 r1313  
    107107            void update();
    108108
     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
    109117            /** @brief Converts the config-value to a string. @return The string */
    110118            inline std::string toString() const
     
    115123
    116124        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 
    125125            bool                       bIsVector_;                  //!< True if the container contains a std::vector
    126126
  • code/branches/console/src/core/CorePrereqs.h

    r1312 r1313  
    140140  class OutputHandler;
    141141  class Shell;
     142  class ShellListener;
    142143  template <class T>
    143144  class SubclassIdentifier;
  • code/branches/console/src/core/Identifier.h

    r1064 r1313  
    6363#include "Debug.h"
    6464#include "Iterator.h"
     65#include "MetaObjectList.h"
    6566#include "util/String.h"
    6667
  • code/branches/console/src/core/InputBuffer.cc

    r1312 r1313  
    4545        this->keyboard_ = InputManager::getSingleton().getKeyboard();
    4646        this->buffer_ = "";
     47        this->cursor_ = 0;
    4748    }
    4849
     
    5253        this->keyboard_ = InputManager::getSingleton().getKeyboard();
    5354        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)
    57102    {
    58103        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        }
    92131    }
    93132
     
    130169            if (e.key == OIS::KC_V)
    131170            {
    132                 this->append(fromClipboard());
     171                this->insert(fromClipboard());
    133172                return true;
    134173            }
     
    149188            if (e.key == OIS::KC_INSERT)
    150189            {
    151                 this->append(fromClipboard());
     190                this->insert(fromClipboard());
    152191                return true;
    153192            }
     
    160199        }
    161200
    162         this->append((char)e.text);
     201        this->insert((char)e.text);
    163202        return true;
    164203    }
  • code/branches/console/src/core/InputBuffer.h

    r1312 r1313  
    102102            }
    103103
    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);
    109112
    110113            void updated();
     
    113116            inline std::string get() const
    114117                { 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_; } }
    115133
    116134        private:
     
    124142            std::list<InputBufferListenerTuple> listeners_;
    125143            std::string allowedChars_;
     144            unsigned int cursor_;
    126145    };
    127146}
  • code/branches/console/src/core/InputHandler.cc

    r1136 r1313  
    3434#include "InputHandler.h"
    3535#include "Debug.h"
     36#include "Iterator.h"
    3637#include "util/Convert.h"
    3738#include "InputEventListener.h"
  • code/branches/console/src/core/Iterator.h

    r1063 r1313  
    5050
    5151#include "ObjectList.h"
    52 #include "Debug.h"
    5352
    5453namespace orxonox
  • code/branches/console/src/core/Language.cc

    r1062 r1313  
    3737
    3838#include "CoreSettings.h"
     39
     40#include "Debug.h"
    3941
    4042namespace orxonox
  • code/branches/console/src/core/Language.h

    r1064 r1313  
    5050#include <map>
    5151#include <string>
    52 
    5352
    5453#define AddLanguageEntry(label, fallbackstring) \
  • code/branches/console/src/core/OrxonoxClass.cc

    r1056 r1313  
    3333
    3434#include "OrxonoxClass.h"
     35#include "MetaObjectList.h"
     36#include "Identifier.h"
    3537
    3638namespace orxonox
     
    3941    OrxonoxClass::OrxonoxClass()
    4042    {
     43        this->metaList_ = new MetaObjectList();
     44
    4145        this->setConfigValues();
    4246
     
    4852    OrxonoxClass::~OrxonoxClass()
    4953    {
     54        delete this->metaList_;
     55
    5056        // parents_ exists only if isCreatingHierarchy() of the associated Identifier returned true while creating the class
    5157        if (this->parents_)
    5258            delete this->parents_;
    5359    }
     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()); }
    54139}
  • code/branches/console/src/core/OrxonoxClass.h

    r1062 r1313  
    4343#include <string>
    4444
    45 #include "MetaObjectList.h"
    46 #include "Iterator.h"
    47 
    4845namespace orxonox
    4946{
     
    7572
    7673            /** @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_); }
    7875
    7976
    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);
    9883
     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);
    9990
    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);
    11897
    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);
    158104
    159105        private:
    160             Identifier* identifier_;                    //!< The Identifier of the object
     106            Identifier* identifier_;                   //!< The Identifier of the object
    161107            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 in
     108            MetaObjectList* metaList_;                 //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in
    163109    };
    164110}
  • code/branches/console/src/core/OutputBuffer.cc

    r1312 r1313  
    3333namespace orxonox
    3434{
    35     OutputBuffer& OutputBuffer::getOutputBuffer()
    36     {
    37         static OutputBuffer instance;
    38         return instance;
    39     }
    40 
    4135    void OutputBuffer::registerListener(OutputBufferListener* listener)
    4236    {
    43         this->listeners_.insert(listener);
     37        this->listeners_.insert(this->listeners_.end(), listener);
    4438    }
    4539
    4640    void OutputBuffer::unregisterListener(OutputBufferListener* listener)
    4741    {
    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        }
    5149    }
    5250
     
    6361            this->stream_.flush();
    6462
     63        // Return true if this was a whole new line, ended by \n
    6564        return (!eof);
    6665    }
     
    6867    void OutputBuffer::callListeners()
    6968    {
    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();
    7271    }
    7372}
  • code/branches/console/src/core/OutputBuffer.h

    r1312 r1313  
    3030#define _OutputBuffer_H__
    3131
    32 #include <set>
     32#include <list>
    3333#include <sstream>
    3434
     
    3737namespace orxonox
    3838{
    39     class OutputBufferListener
     39    class _CoreExport OutputBufferListener
    4040    {
    4141        friend class OutputBuffer;
     42
    4243        virtual void outputChanged() = 0;
    4344    };
     
    4647    {
    4748        public:
    48             static OutputBuffer& getOutputBuffer();
     49            OutputBuffer() {}
     50            ~OutputBuffer() {}
    4951
    5052            template <class T>
     
    5355                this->stream_ << object;
    5456                this->callListeners();
    55                 return &this;
     57                return *this;
    5658            }
    5759
     
    8688            void unregisterListener(OutputBufferListener* listener);
    8789
     90            inline operator std::stringstream&()
     91            {
     92                return this->stream_;
     93            }
     94
    8895        private:
    89             OutputBuffer() {}
    90             OutputBuffer(const OutputBuffer& other);
    91             ~OutputBuffer() {}
    92 
    9396            void callListeners();
    9497
    9598            std::stringstream stream_;
    96             std::set<OutputBufferListener*> listeners_;
     99            std::list<OutputBufferListener*> listeners_;
    97100    };
    98101}
  • code/branches/console/src/core/OutputHandler.cc

    r1230 r1313  
    101101        }
    102102
     103        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     104            Shell::getInstance().getOutputBuffer() << sb;
     105
    103106        return *this;
    104107    }
     
    119122            this->logfile_.flush();
    120123        }
     124
     125        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     126            manipulator(Shell::getInstance().getOutputBuffer());
    121127
    122128        return *this;
     
    139145        }
    140146
     147        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     148            manipulator(Shell::getInstance().getOutputBuffer());
     149
    141150        return *this;
    142151    }
     
    158167        }
    159168
     169        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     170            manipulator(Shell::getInstance().getOutputBuffer());
     171
    160172        return *this;
    161173    }
  • code/branches/console/src/core/OutputHandler.h

    r1230 r1313  
    4343#include <fstream>
    4444#include <string>
     45
     46#include "Shell.h"
    4547
    4648namespace orxonox
     
    154156        }
    155157
     158        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= this->outputLevel_)
     159            Shell::getInstance().getOutputBuffer() << output;
     160
    156161        return *this;
    157162    }
     
    175180        }
    176181
     182        if (OutputHandler::getSoftDebugLevel(OutputHandler::LD_Shell) >= out.getOutputLevel())
     183            Shell::getInstance().getOutputBuffer() << output;
     184
    177185        return out;
    178186    }
  • code/branches/console/src/core/Shell.cc

    r1312 r1313  
    2727 */
    2828
    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()
    3437
    3538namespace orxonox
     
    3740    Shell::Shell()
    3841    {
     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
    3951        this->inputBuffer_.registerListener(this, &Shell::inputChanged, true);
    4052        this->inputBuffer_.registerListener(this, &Shell::execute, '\r', false);
    4153        this->inputBuffer_.registerListener(this, &Shell::hintandcomplete, '\t', true);
    42         this->inputBuffer_.registerListener(this, &Shell::clear, '§', true);
    4354        this->inputBuffer_.registerListener(this, &Shell::backspace, '\b', true);
     55        this->inputBuffer_.registerListener(this, &Shell::deletechar, OIS::KC_DELETE);
    4456        this->inputBuffer_.registerListener(this, &Shell::exit, (char)27, true);
    4557        this->inputBuffer_.registerListener(this, &Shell::cursor_right, OIS::KC_RIGHT);
    4658        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);
    4761        this->inputBuffer_.registerListener(this, &Shell::history_up, OIS::KC_UP);
    4862        this->inputBuffer_.registerListener(this, &Shell::history_down, OIS::KC_DOWN);
    4963        this->inputBuffer_.registerListener(this, &Shell::scroll_up, OIS::KC_PGUP);
    5064        this->inputBuffer_.registerListener(this, &Shell::scroll_down, OIS::KC_PGDOWN);
     65
     66        this->setConfigValues();
    5167    }
    5268
    5369    Shell& Shell::getInstance()
    5470    {
    55         static instance Shell;
     71        static Shell instance;
    5672        return instance;
    5773    }
    5874
    5975    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    }
    60165
    61166    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
    62187    void Shell::inputChanged()
     188    {
     189        SHELL_UPDATE_LISTENERS(inputChanged);
     190        SHELL_UPDATE_LISTENERS(cursorChanged);
     191    }
     192
    63193    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
    64203    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
    65211    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
    66224    void Shell::clear()
     225    {
     226        this->inputBuffer_.clear();
     227        SHELL_UPDATE_LISTENERS(inputChanged);
     228        SHELL_UPDATE_LISTENERS(cursorChanged);
     229    }
     230
    67231    void Shell::cursor_right()
     232    {
     233        this->inputBuffer_.increaseCursor();
     234        SHELL_UPDATE_LISTENERS(cursorChanged);
     235    }
     236
    68237    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
    69255    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
    70264    void Shell::history_down()
     265    {
     266        if (this->historyPosition_ > 0)
     267        {
     268            this->historyPosition_++;
     269            this->inputBuffer_.set(this->getFromHistory());
     270        }
     271    }
     272
    71273    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
    72284    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
    73295    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    }
    74306}
  • code/branches/console/src/core/Shell.h

    r1312 r1313  
    3030#define _Shell_H__
    3131
     32#include <list>
     33#include <vector>
     34
    3235#include "CorePrereqs.h"
    3336
     
    3841namespace orxonox
    3942{
    40     class ShellListener
     43    class _CoreExport ShellListener
    4144    {
    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    };
    4754
    4855    class _CoreExport Shell : virtual public OrxonoxClass, public InputBufferListener, public OutputBufferListener
     
    5360            virtual void setConfigValues();
    5461
     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
    5592        private:
    5693            Shell();
    5794            Shell(const Shell& other);
    58             ~Shell() {}
     95            virtual ~Shell() {}
     96
     97            void addToHistory(const std::string& command);
     98            std::string getFromHistory() const;
    5999
    60100            virtual void outputChanged();
     
    63103            void hintandcomplete();
    64104            void backspace();
     105            void deletechar();
     106            void clear();
    65107            void cursor_right();
    66108            void cursor_left();
     109            void cursor_end();
     110            void cursor_home();
    67111            void history_up();
    68112            void history_down();
     
    71115            void exit();
    72116
     117            std::list<ShellListener*> listeners_;
    73118            InputBuffer inputBuffer_;
    74             OutputBuffer OutputBuffer_;
     119            OutputBuffer outputBuffer_;
    75120            std::list<std::string> lines_;
    76             unsigned int cursor_;
     121            std::list<std::string>::const_iterator scrollIterator_;
     122            unsigned int scrollPosition_;
    77123            std::vector<std::string> commandHistory_;
    78124            unsigned int maxHistoryLength_;
     125            unsigned int historyPosition_;
     126            unsigned int historyOffset_;
    79127    };
    80128}
  • code/branches/console/src/orxonox/Orxonox.cc

    r1188 r1313  
    115115      void removeLast() const
    116116      {
    117         this->ib_->removeLast();
     117        this->ib_->removeBehindCursor();
    118118      }
    119119      void exit() const
  • code/branches/console/src/orxonox/console/InGameConsole.cc

    r1181 r1313  
    9292
    9393    void InGameConsole::removeLast(){
    94         this->ib_->removeLast();
     94        this->ib_->removeBehindCursor();
    9595    }
    9696
Note: See TracChangeset for help on using the changeset viewer.