Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11007


Ignore:
Timestamp:
Dec 31, 2015, 12:43:34 AM (8 years ago)
Author:
landauf
Message:

made some enums in core library strongly typed. for other enums in core (especially in the input library) this isn't possible because enums are often used like flags (converted to int and compared with binary operators).

Location:
code/branches/cpp11_v2/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/core/XMLPort.h

    r10990 r11007  
    324324    {
    325325    public:
    326         enum ParseResult
     326        enum class ParseResult
    327327        {
    328             PR_not_started,
    329             PR_finished,
    330             PR_waiting_for_default_values
     328            not_started,
     329            finished,
     330            waiting_for_default_values
    331331        };
    332332
    333333        public:
    334334            XMLPortParamContainer()
    335                 { this->parseResult_ = PR_not_started; }
     335                { this->parseResult_ = ParseResult::not_started; }
    336336            virtual ~XMLPortParamContainer() = default;
    337337
     
    415415                            this->loadexecutor_->parse(object, attributeValue, &error, ",");
    416416                            if (!error || (mode  == XMLPort::ExpandObject))
    417                                 this->parseResult_ = PR_finished;
     417                                this->parseResult_ = ParseResult::finished;
    418418                            else
    419                                 this->parseResult_ = PR_waiting_for_default_values;
     419                                this->parseResult_ = ParseResult::waiting_for_default_values;
    420420                        }
    421421                        else if (mode == XMLPort::ExpandObject)
    422                             this->parseResult_ = PR_finished;
     422                            this->parseResult_ = ParseResult::finished;
    423423                        else
    424                             this->parseResult_ = PR_waiting_for_default_values;
     424                            this->parseResult_ = ParseResult::waiting_for_default_values;
    425425                    }
    426426                    catch (ticpp::Exception& ex)
     
    449449            XMLPortParamContainer& portIfWaitingForDefaultValues(const ParseResult& result, const ParseParams& params)
    450450            {
    451                 if (result == PR_waiting_for_default_values)
     451                if (result == ParseResult::waiting_for_default_values)
    452452                    return this->port(this->owner_, params);
    453453                else
  • code/branches/cpp11_v2/src/libraries/core/command/ConsoleCommand.h

    r10765 r11007  
    6060    }
    6161
    62     namespace AccessLevel
     62    /**
     63        @brief Possible access levels: A command can only be executed if the program is in the state which is requested by the access level.
     64    */
     65    enum class AccessLevel
    6366    {
    64         /**
    65             @brief Possible access levels: A command can only be executed if the program is in the state which is requested by the access level.
    66         */
    67         enum Enum
    68         {
    69             All,
    70             Standalone,
    71             Master,
    72             Server,
    73             Client,
    74             Online,
    75             Offline,
    76             None
    77         };
    78     }
     67        All,
     68        Standalone,
     69        Master,
     70        Server,
     71        Client,
     72        Online,
     73        Offline,
     74        None
     75    };
    7976
    8077    /**
     
    249246
    250247                    /// Changes the access level of the command.
    251                     inline ConsoleCommandManipulator& accessLevel(AccessLevel::Enum level)
     248                    inline ConsoleCommandManipulator& accessLevel(AccessLevel level)
    252249                        { if (this->command_) { this->command_->accessLevel(level); } return *this; }
    253250
     
    332329
    333330            /// Changes the access level of the command.
    334             inline ConsoleCommand& accessLevel(AccessLevel::Enum level)
     331            inline ConsoleCommand& accessLevel(AccessLevel level)
    335332                { this->accessLevel_ = level; return *this; }
    336333            /// Returns the access level of the command.
    337             inline AccessLevel::Enum getAccessLevel() const
     334            inline AccessLevel getAccessLevel() const
    338335                { return this->accessLevel_; }
    339336
     
    394391            bool bActive_;                                                  ///< True if the command should be active (it can still be inactive, for example if the function is missing)
    395392            bool bHidden_;                                                  ///< True if the command is hidden (it is still executable, but not visible in the list of available commands)
    396             AccessLevel::Enum accessLevel_;                                 ///< The access level (the state of the game in which you can access the command)
     393            AccessLevel accessLevel_;                                       ///< The access level (the state of the game in which you can access the command)
    397394            std::string baseName_;                                          ///< The name that was first assigned to the command
    398395            std::vector<CommandName> names_;                                ///< All names and aliases of this command
  • code/branches/cpp11_v2/src/libraries/core/command/Executor.h

    r10990 r11007  
    147147                { return this->functor_->hasReturnvalue(); }
    148148            /// Returns the type of the wrapped function (static or member).
    149             inline Functor::Type::Enum getType() const
     149            inline Functor::Type getType() const
    150150                { return this->functor_->getType(); }
    151151            /// Returns the name of the type of a parameter with given index (the first parameter has index 0).
  • code/branches/cpp11_v2/src/libraries/core/command/Functor.h

    r10990 r11007  
    176176    {
    177177        public:
    178             struct Type
    179             {
    180                 /// Defines the type of a function (static or member)
    181                 enum Enum
    182                 {
    183                     Static,
    184                     Member
    185                 };
     178            /// Defines the type of a function (static or member)
     179            enum class Type
     180            {
     181                Static,
     182                Member
    186183            };
    187184
     
    196193
    197194            /// Returns the type of the function: static or member.
    198             virtual Type::Enum getType() const = 0;
     195            virtual Type getType() const = 0;
    199196            /// Returns the number of parameters of the function.
    200197            virtual unsigned int getParamCount() const = 0;
     
    262259
    263260            // see Functor::getType()
    264             virtual inline Functor::Type::Enum getType() const override
     261            virtual inline Functor::Type getType() const override
    265262                { return Functor::Type::Member; }
    266263
     
    339336
    340337            // see Functor::getType()
    341             virtual inline Functor::Type::Enum getType() const override
     338            virtual inline Functor::Type getType() const override
    342339                { return Functor::Type::Static; }
    343340
  • code/branches/cpp11_v2/src/libraries/core/command/IOConsolePOSIX.cc

    r10768 r11007  
    4646    IOConsole* IOConsole::singletonPtr_s = nullptr;
    4747
    48     namespace EscapeMode
    49     {
    50         enum Value
    51         {
    52             None,
    53             First,
    54             Second
    55         };
    56     }
     48    enum class EscapeMode
     49    {
     50        None,
     51        First,
     52        Second
     53    };
    5754
    5855    IOConsole::IOConsole()
     
    9087        std::cout.flush();
    9188        if (!this->origCout_.str().empty())
    92             this->shell_->addOutput(this->origCout_.str(), Shell::Cout);
     89            this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout);
    9390        // Erase input and status lines
    9491        this->cout_ << "\033[1G\033[J";
     
    111108        unsigned char c;
    112109        std::string escapeSequence;
    113         EscapeMode::Value escapeMode = EscapeMode::None;
     110        EscapeMode escapeMode = EscapeMode::None;
    114111        while (std::cin.good())
    115112        {
     
    231228        if (!this->origCout_.str().empty())
    232229        {
    233             this->shell_->addOutput(this->origCout_.str(), Shell::Cout);
     230            this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout);
    234231            this->origCout_.str("");
    235232        }
     
    241238        switch (type)
    242239        {
    243             case Shell::Message:
    244             case Shell::DebugOutput:     this->cout_ << "\033[0m"; break;
    245 
    246             case Shell::UserError:       this->cout_ << "\033[91m"; break;
    247             case Shell::UserWarning:     this->cout_ << "\033[93m"; break;
    248             case Shell::UserStatus:      this->cout_ << "\033[92m"; break;
    249             case Shell::UserInfo:        this->cout_ << "\033[96m"; break;
    250 
    251             case Shell::InternalError:   this->cout_ << "\033[31m"; break;
    252             case Shell::InternalWarning: this->cout_ << "\033[33m"; break;
    253             case Shell::InternalStatus:  this->cout_ << "\033[32m"; break;
    254             case Shell::InternalInfo:    this->cout_ << "\033[36m"; break;
    255 
    256             case Shell::Verbose:         this->cout_ << "\033[94m"; break;
    257             case Shell::VerboseMore:     this->cout_ << "\033[34m"; break;
    258             case Shell::VerboseUltra:    this->cout_ << "\033[34m"; break;
    259 
    260             case Shell::Command:         this->cout_ << "\033[95m"; break;
    261             case Shell::Hint:            this->cout_ << "\033[35m"; break;
    262 
    263             default:                     this->cout_ << "\033[37m"; break;
     240            case Shell::LineType::Message:
     241            case Shell::LineType::DebugOutput:     this->cout_ << "\033[0m"; break;
     242
     243            case Shell::LineType::UserError:       this->cout_ << "\033[91m"; break;
     244            case Shell::LineType::UserWarning:     this->cout_ << "\033[93m"; break;
     245            case Shell::LineType::UserStatus:      this->cout_ << "\033[92m"; break;
     246            case Shell::LineType::UserInfo:        this->cout_ << "\033[96m"; break;
     247
     248            case Shell::LineType::InternalError:   this->cout_ << "\033[31m"; break;
     249            case Shell::LineType::InternalWarning: this->cout_ << "\033[33m"; break;
     250            case Shell::LineType::InternalStatus:  this->cout_ << "\033[32m"; break;
     251            case Shell::LineType::InternalInfo:    this->cout_ << "\033[36m"; break;
     252
     253            case Shell::LineType::Verbose:         this->cout_ << "\033[94m"; break;
     254            case Shell::LineType::VerboseMore:     this->cout_ << "\033[34m"; break;
     255            case Shell::LineType::VerboseUltra:    this->cout_ << "\033[34m"; break;
     256
     257            case Shell::LineType::Command:         this->cout_ << "\033[95m"; break;
     258            case Shell::LineType::Hint:            this->cout_ << "\033[35m"; break;
     259
     260            default:                               this->cout_ << "\033[37m"; break;
    264261        }
    265262
     
    384381    void IOConsole::executed()
    385382    {
    386         this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::Command);
     383        this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::LineType::Command);
    387384    }
    388385
  • code/branches/cpp11_v2/src/libraries/core/command/IOConsoleWindows.cc

    r10765 r11007  
    9797        std::cout.flush();
    9898        if (!this->origCout_.str().empty())
    99             this->shell_->addOutput(this->origCout_.str(), Shell::Cout);
     99            this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout);
    100100
    101101        this->shell_->unregisterListener(this);
     
    190190        if (!this->origCout_.str().empty())
    191191        {
    192             this->shell_->addOutput(this->origCout_.str(), Shell::Cout);
     192            this->shell_->addOutput(this->origCout_.str(), Shell::LineType::Cout);
    193193            this->origCout_.str("");
    194194        }
     
    202202        switch (type)
    203203        {
    204             case Shell::Message:
    205             case Shell::DebugOutput:     colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
    206 
    207             case Shell::UserError:       colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0                | 0              ; break;
    208             case Shell::UserWarning:     colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | 0              ; break;
    209             case Shell::UserStatus:      colour = FOREGROUND_INTENSITY | 0              | FOREGROUND_GREEN | 0              ; break;
    210             case Shell::UserInfo:        colour = FOREGROUND_INTENSITY | 0              | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
    211 
    212             case Shell::InternalError:   colour = 0                    | FOREGROUND_RED | 0                | 0              ; break;
    213             case Shell::InternalWarning: colour = 0                    | FOREGROUND_RED | FOREGROUND_GREEN | 0              ; break;
    214             case Shell::InternalStatus:  colour = 0                    | 0              | FOREGROUND_GREEN | 0              ; break;
    215             case Shell::InternalInfo:    colour = 0                    | 0              | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
    216 
    217             case Shell::Verbose:         colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
    218             case Shell::VerboseMore:     colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
    219             case Shell::VerboseUltra:    colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
    220 
    221             case Shell::Command:         colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0                | FOREGROUND_BLUE; break;
    222             case Shell::Hint:            colour = 0                    | FOREGROUND_RED | 0                | FOREGROUND_BLUE; break;
    223 
    224             default:                     colour = 0                    | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     204            case Shell::LineType::Message:
     205            case Shell::LineType::DebugOutput:     colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     206
     207            case Shell::LineType::UserError:       colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0                | 0              ; break;
     208            case Shell::LineType::UserWarning:     colour = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | 0              ; break;
     209            case Shell::LineType::UserStatus:      colour = FOREGROUND_INTENSITY | 0              | FOREGROUND_GREEN | 0              ; break;
     210            case Shell::LineType::UserInfo:        colour = FOREGROUND_INTENSITY | 0              | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     211
     212            case Shell::LineType::InternalError:   colour = 0                    | FOREGROUND_RED | 0                | 0              ; break;
     213            case Shell::LineType::InternalWarning: colour = 0                    | FOREGROUND_RED | FOREGROUND_GREEN | 0              ; break;
     214            case Shell::LineType::InternalStatus:  colour = 0                    | 0              | FOREGROUND_GREEN | 0              ; break;
     215            case Shell::LineType::InternalInfo:    colour = 0                    | 0              | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
     216
     217            case Shell::LineType::Verbose:         colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
     218            case Shell::LineType::VerboseMore:     colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
     219            case Shell::LineType::VerboseUltra:    colour = FOREGROUND_INTENSITY | 0              | 0                | FOREGROUND_BLUE; break;
     220
     221            case Shell::LineType::Command:         colour = FOREGROUND_INTENSITY | FOREGROUND_RED | 0                | FOREGROUND_BLUE; break;
     222            case Shell::LineType::Hint:            colour = 0                    | FOREGROUND_RED | 0                | FOREGROUND_BLUE; break;
     223
     224            default:                               colour = 0                    | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break;
    225225        }
    226226
     
    331331    void IOConsole::executed()
    332332    {
    333         this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::Command);
     333        this->shell_->addOutput(this->promptString_ + this->shell_->getInput(), Shell::LineType::Command);
    334334    }
    335335
  • code/branches/cpp11_v2/src/libraries/core/command/Shell.cc

    r10916 r11007  
    268268    {
    269269        // yes it was - push the new line to the list
    270         this->outputLines_.push_front(std::make_pair(line, static_cast<LineType>(type)));
     270        this->outputLines_.push_front(std::make_pair(line, type));
    271271
    272272        // adjust the scroll position if needed
     
    381381        const std::string& result = CommandExecutor::query(this->inputBuffer_->get(), &error);
    382382        if (error)
    383             this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", " + CommandExecutor::getErrorDescription(error) + ". (Shell)", UserError);
     383            this->addOutput("Error: Can't execute \"" + this->inputBuffer_->get() + "\", " + CommandExecutor::getErrorDescription(error) + ". (Shell)", LineType::UserError);
    384384        else if (result != "")
    385             this->addOutput(result, Result);
     385            this->addOutput(result, LineType::Result);
    386386
    387387        this->clearInput();
     
    392392    {
    393393        this->inputBuffer_->set(CommandExecutor::evaluate(this->inputBuffer_->get()).complete());
    394         this->addOutput(CommandExecutor::evaluate(this->inputBuffer_->get()).hint(), Hint);
     394        this->addOutput(CommandExecutor::evaluate(this->inputBuffer_->get()).hint(), LineType::Hint);
    395395
    396396        this->inputChanged();
  • code/branches/cpp11_v2/src/libraries/core/command/Shell.h

    r10992 r11007  
    8888        public:
    8989            /// Defines the type of a line of text in the Shell - some types depend on the output level, others are of internal use.
    90             enum LineType
     90            enum class LineType
    9191            {
    9292                DebugOutput     = debug_output,
     
    133133            LineList::const_iterator getEndIterator() const;
    134134
    135             void addOutput(const std::string& text, LineType type = DebugOutput);
    136             void addLine(const std::string& line, LineType type = DebugOutput);
     135            void addOutput(const std::string& text, LineType type = LineType::DebugOutput);
     136            void addLine(const std::string& line, LineType type = LineType::DebugOutput);
    137137            void clearOutput();
    138138
  • code/branches/cpp11_v2/src/orxonox/overlays/InGameConsole.cc

    r10768 r11007  
    292292
    293293        for (int i = LINES - 1; i > max; --i)
    294             this->print("", Shell::DebugOutput, i, true);
     294            this->print("", Shell::LineType::DebugOutput, i, true);
    295295
    296296        for (int i = max; i >= 1; --i)
     
    318318    {
    319319        if (LINES > 0)
    320             this->print(this->shell_->getInput(), Shell::Input, 0);
     320            this->print(this->shell_->getInput(), Shell::LineType::Input, 0);
    321321
    322322        if (this->shell_->getInput().empty())
     
    342342    void InGameConsole::executed()
    343343    {
    344         this->shell_->addOutput(this->shell_->getInput(), Shell::Command);
     344        this->shell_->addOutput(this->shell_->getInput(), Shell::LineType::Command);
    345345    }
    346346
     
    562562        switch (type)
    563563        {
    564             case Shell::Message:
    565             case Shell::DebugOutput:     colourTop = ColourValue(0.9f, 0.9f, 0.9f); break;
    566 
    567             case Shell::UserError:       colourTop = ColourValue(0.9f, 0.0f, 0.0f); break;
    568             case Shell::UserWarning:     colourTop = ColourValue(0.9f, 0.5f, 0.0f); break;
    569             case Shell::UserStatus:      colourTop = ColourValue(0.0f, 0.9f, 0.0f); break;
    570             case Shell::UserInfo:        colourTop = ColourValue(0.0f, 0.8f, 0.8f); break;
    571 
    572             case Shell::InternalError:   colourTop = ColourValue(0.5f, 0.0f, 0.0f); break;
    573             case Shell::InternalWarning: colourTop = ColourValue(0.5f, 0.2f, 0.0f); break;
    574             case Shell::InternalStatus:  colourTop = ColourValue(0.0f, 0.5f, 0.0f); break;
    575             case Shell::InternalInfo:    colourTop = ColourValue(0.0f, 0.4f, 0.4f); break;
    576 
    577             case Shell::Verbose:         colourTop = ColourValue(0.3f, 0.3f, 0.9f); break;
    578             case Shell::VerboseMore:     colourTop = ColourValue(0.2f, 0.2f, 0.7f); break;
    579             case Shell::VerboseUltra:    colourTop = ColourValue(0.1f, 0.1f, 0.5f); break;
    580 
    581             case Shell::Command:         colourTop = ColourValue(0.8f, 0.2f, 0.8f); break;
    582             case Shell::Hint:            colourTop = ColourValue(0.4f, 0.0f, 0.4f); break;
    583             case Shell::Input:           colourTop = ColourValue(0.9f, 0.9f, 0.9f); break;
    584 
    585             default:                     colourTop = ColourValue(0.5f, 0.5f, 0.5f); break;
     564            case Shell::LineType::Message:
     565            case Shell::LineType::DebugOutput:     colourTop = ColourValue(0.9f, 0.9f, 0.9f); break;
     566
     567            case Shell::LineType::UserError:       colourTop = ColourValue(0.9f, 0.0f, 0.0f); break;
     568            case Shell::LineType::UserWarning:     colourTop = ColourValue(0.9f, 0.5f, 0.0f); break;
     569            case Shell::LineType::UserStatus:      colourTop = ColourValue(0.0f, 0.9f, 0.0f); break;
     570            case Shell::LineType::UserInfo:        colourTop = ColourValue(0.0f, 0.8f, 0.8f); break;
     571
     572            case Shell::LineType::InternalError:   colourTop = ColourValue(0.5f, 0.0f, 0.0f); break;
     573            case Shell::LineType::InternalWarning: colourTop = ColourValue(0.5f, 0.2f, 0.0f); break;
     574            case Shell::LineType::InternalStatus:  colourTop = ColourValue(0.0f, 0.5f, 0.0f); break;
     575            case Shell::LineType::InternalInfo:    colourTop = ColourValue(0.0f, 0.4f, 0.4f); break;
     576
     577            case Shell::LineType::Verbose:         colourTop = ColourValue(0.3f, 0.3f, 0.9f); break;
     578            case Shell::LineType::VerboseMore:     colourTop = ColourValue(0.2f, 0.2f, 0.7f); break;
     579            case Shell::LineType::VerboseUltra:    colourTop = ColourValue(0.1f, 0.1f, 0.5f); break;
     580
     581            case Shell::LineType::Command:         colourTop = ColourValue(0.8f, 0.2f, 0.8f); break;
     582            case Shell::LineType::Hint:            colourTop = ColourValue(0.4f, 0.0f, 0.4f); break;
     583            case Shell::LineType::Input:           colourTop = ColourValue(0.9f, 0.9f, 0.9f); break;
     584
     585            default:                               colourTop = ColourValue(0.5f, 0.5f, 0.5f); break;
    586586        }
    587587
Note: See TracChangeset for help on using the changeset viewer.