Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 19, 2010, 2:11:28 AM (14 years ago)
Author:
landauf
Message:

continued working on the new console command interface and implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc

    r7179 r7185  
    8080    _ConsoleCommand::_ConsoleCommandManipulator test(_ModifyConsoleCommand("BaseObject", "setName").setFunction(&BaseObject::setActive));
    8181
    82     _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
    83     {
    84         this->state_ = state;
     82    _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
     83    {
     84        this->bActive_ = true;
     85        this->bInitialized_ = bInitialized;
    8586        _ConsoleCommand::registerCommand(group, name, this);
    8687    }
     
    110111    }
    111112
    112     void _ConsoleCommand::setActive(bool bActive)
    113     {
    114         if (bActive)
    115         {
    116             if (this->state_ == State::Inactive)
    117                 this->state_ = State::Active;
    118             else if (this->state_ == State::UninitializedInactive)
    119                 this->state_ = State::UninitializedActive;
    120         }
    121         else
    122         {
    123             if (this->state_ == State::Active)
    124                 this->state_ = State::Inactive;
    125             else if (this->state_ == State::UninitializedActive)
    126                 this->state_ = State::UninitializedInactive;
    127         }
    128     }
    129 
    130     void _ConsoleCommand::setInitialized(bool bInitialized)
    131     {
    132         if (bInitialized)
    133         {
    134             if (this->state_ == State::UninitializedActive)
    135                 this->state_ = State::Active;
    136             else if (this->state_ == State::UninitializedInactive)
    137                 this->state_ = State::Inactive;
    138         }
    139         else
    140         {
    141             if (this->state_ == State::Active)
    142                 this->state_ = State::UninitializedActive;
    143             else if (this->state_ == State::Inactive)
    144                 this->state_ = State::UninitializedInactive;
    145         }
    146     }
    147 
    148     void _ConsoleCommand::setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode)
     113    bool _ConsoleCommand::setFunctor(Functor* functor, bool bForce)
    149114    {
    150115        if (!functor)
    151116        {
    152             this->setInitialized(false);
    153             return;
    154         }
    155 
    156         if (!this->functionHeaderMatches(functor))
     117            this->bInitialized_ = false;
     118            return true;
     119        }
     120
     121        if (!bForce && !this->functionHeaderMatches(functor))
    157122        {
    158123            COUT(1) << "Error: Couldn't assign new function to console command with name \"" << this->getName() << "\", headers don't match." << std::endl;
    159             return;
    160         }
    161 
    162         switch (mode)
    163         {
    164             default:
    165             case _ConsoleCommand::ObjectPointer::Null:
    166             {
    167                 this->functor_ = functor;
    168             }
    169             break;
    170 
    171             case _ConsoleCommand::ObjectPointer::RawCopy:
    172             {
    173                 void* object = (this->functor_) ? this->functor_->getRawObjectPointer() : 0;
    174 
    175                 this->functor_ = functor;
    176 
    177                 if (!this->functor_->getBaseObject())
    178                     this->functor_->setRawObjectPointer(object);
    179             }
    180             break;
    181 
    182             case _ConsoleCommand::ObjectPointer::CastViaBaseObject:
    183             {
    184                 BaseObject* object = (this->functor_) ? this->functor_->getBaseObject() : 0;
    185 
    186                 this->functor_ = functor;
    187 
    188                 if (!this->functor_->getBaseObject())
    189                     this->functor_->setBaseObject(object);
    190             }
    191             break;
    192         }
     124            return false;
     125        }
     126
     127        this->functor_ = functor;
     128        this->bInitialized_ = true;
     129        return true;
     130    }
     131
     132    void _ConsoleCommand::pushFunctor(Functor* functor, bool bForce)
     133    {
     134        Functor* oldfunctor = this->getFunctor();
     135
     136        if (this->setFunctor(functor, bForce));
     137            this->functorStack_.push(oldfunctor);
     138    }
     139
     140    void _ConsoleCommand::popFunctor()
     141    {
     142        Functor* newfunctor = 0;
     143        if (!this->functorStack_.empty())
     144        {
     145            newfunctor = this->functorStack_.top();
     146            this->functorStack_.pop();
     147        }
     148        this->setFunctor(newfunctor);
     149    }
     150
     151    Functor* _ConsoleCommand::getFunctor() const
     152    {
     153        if (this->bInitialized_)
     154            return this->functor_;
     155        else
     156            return 0;
    193157    }
    194158
     
    198162        {
    199163            assert(false);
    200             return false;
    201         }
    202         return (functor->getHeaderIdentifier() == this->functor_->getHeaderIdentifier());
     164            return true;
     165        }
     166        return (functor->getHeaderIdentifier() == this->functionHeader_);
    203167    }
    204168
     
    207171        if (this->functor_)
    208172            this->functor_->setRawObjectPointer(object);
    209     }
    210 
    211     void _ConsoleCommand::setObject(BaseObject* object)
     173        else if (object)
     174            COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
     175    }
     176
     177    void _ConsoleCommand::pushObject(void* object)
    212178    {
    213179        if (this->functor_)
    214             this->functor_->setBaseObject(object);
     180        {
     181            this->objectStack_.push(this->getObject());
     182            this->setObject(object);
     183        }
     184        else
     185            COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
     186    }
     187
     188    void _ConsoleCommand::popObject()
     189    {
     190        void* newobject = 0;
     191        if (!this->objectStack_.empty())
     192        {
     193            newobject = this->objectStack_.top();
     194            this->objectStack_.pop();
     195        }
     196        this->setObject(newobject);
     197    }
     198
     199    void* _ConsoleCommand::getObject() const
     200    {
     201        if (this->functor_)
     202            return this->functor_->getRawObjectPointer();
     203        else
     204            return 0;
    215205    }
    216206
Note: See TracChangeset for help on using the changeset viewer.