Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 30, 2015, 9:24:39 PM (9 years ago)
Author:
landauf
Message:

using strongly typed enum class in notifications.
NotificationListener::sendHelper (a network function) now uses the new enum instead of an unsigned int for the message-type. this is possible due to MultiType's new support for strongly typed enums.

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

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/modules/notifications/NotificationDispatcher.cc

    r10765 r11003  
    113113        // TODO: Needed?
    114114        const std::string message = this->createNotificationMessage();
    115         NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::local);
     115        NotificationListener::sendNotification(message, this->getSender(), NotificationMessageType::info, NotificationSendMode::local);
    116116
    117117        // Broadcast
     
    144144            const std::string message = this->createNotificationMessage();
    145145            // TODO: Make the type configurable.
    146             NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId);
     146            NotificationListener::sendNotification(message, this->getSender(), NotificationMessageType::info, NotificationSendMode::network, clientId);
    147147        }
    148148        else if(GameMode::isServer())
  • code/branches/cpp11_v2/src/modules/notifications/NotificationManager.cc

    r10917 r11003  
    106106        Returns true if successful.
    107107    */
    108     bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     108    bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type)
    109109    {
    110110        // TODO: Do something with the type.
     
    124124        Returns true if the command was successfully executed.
    125125    */
    126     bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
     126    bool NotificationManager::executeCommand(NotificationCommand command, const std::string& sender)
    127127    {
    128128        bool commandExecuted = false;
    129         if(command == notificationCommand::clear)
     129        if(command == NotificationCommand::clear)
    130130        {
    131131            if(this->commandClear(sender))
     
    437437
    438438    */
    439     Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     439    Notification::Notification(const std::string& message, const std::string& sender, NotificationMessageType type)
    440440    {
    441441        this->initialize();
  • code/branches/cpp11_v2/src/modules/notifications/NotificationManager.h

    r10817 r11003  
    6262    {
    6363        public:
    64             Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
     64            Notification(const std::string& message, const std::string& sender, NotificationMessageType type);
    6565            virtual ~Notification();
    6666
     
    8989            @return Returns an enum with the type of the Notification.
    9090            */
    91             inline notificationMessageType::Value getType(void) const
     91            inline NotificationMessageType getType(void) const
    9292                { return this->type_; }
    9393
     
    9595            std::string message_; //!< The Notification message.
    9696            std::string sender_; //!< The sender of the notification.
    97             notificationMessageType::Value type_; //!< The type of the notification.
     97            NotificationMessageType type_; //!< The type of the notification.
    9898
    9999            void initialize(void); //!< Registers the object and sets some default values.
     
    128128            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
    129129
    130             virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type) override;
    131             virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) override;
     130            virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) override;
     131            virtual bool executeCommand(NotificationCommand command, const std::string& sender) override;
    132132
    133133            bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
  • code/branches/cpp11_v2/src/modules/questsystem/QuestDescription.cc

    r9667 r11003  
    119119        }
    120120
    121         NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     121        NotificationListener::sendNotification(message, QuestDescription::SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
    122122        return true;
    123123    }
  • code/branches/cpp11_v2/src/orxonox/infos/GametypeInfo.cc

    r10919 r11003  
    291291        if(GameMode::isMaster())
    292292        {
    293             NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     293            NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
    294294            // Remove the player from the list of players that have spawned, since it currently is not.
    295295            this->spawnedPlayers_.erase(player);
     
    346346                // Display "Press [Fire] to start the match" if the game has not yet ended.
    347347                if(!this->hasEnded())
    348                     NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     348                    NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
    349349                // Else display "Game has ended".
    350350                else
    351                     NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
     351                    NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
    352352            }
    353353        }
  • code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.cc

    r10919 r11003  
    7474        The type of the notification, can be either 'info' or 'important'.
    7575    */
    76     /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand, notificationMessageType::Value messageType)
     76    /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, NotificationSendMode sendMode, unsigned int clientId, bool isCommand, NotificationMessageType messageType)
    7777    {
    7878        // If we're in standalone mode or we're already no the right client we create and send the notification/command.
    79         if(GameMode::isStandalone() || sendMode == notificationSendMode::local || (sendMode ==  notificationSendMode::network && Host::getPlayerID() == clientId))
     79        if(GameMode::isStandalone() || sendMode == NotificationSendMode::local || (sendMode ==  NotificationSendMode::network && Host::getPlayerID() == clientId))
    8080        {
    8181            sendHelper(message, sender, isCommand, messageType);
    8282        }
    8383        // If we're on the server (and the server is not the intended recipient of the notification/command) we send it over the network.
    84         else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId)
     84        else if(GameMode::isServer() && sendMode == NotificationSendMode::network && Host::getPlayerID() != clientId)
    8585        {
    86             callStaticNetworkFunction(&NotificationListener::sendHelper, clientId, message, sender, isCommand, (unsigned int)messageType);
     86            callStaticNetworkFunction(&NotificationListener::sendHelper, clientId, message, sender, isCommand, messageType);
    8787        }
    88         else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast)
     88        else if(GameMode::isServer() && sendMode == NotificationSendMode::broadcast)
    8989        {
    9090            // TODO: Works as intended?
    91             callStaticNetworkFunction(&NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, (unsigned int)messageType);
     91            callStaticNetworkFunction(&NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, messageType);
    9292        }
    9393    }
     
    105105        The type of the notification.
    106106    */
    107     /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, unsigned int messageType)
     107    /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, NotificationMessageType type)
    108108    {
    109109        // Iterate through all NotificationListeners and notify them by calling the method they overloaded.
     
    112112            // If the notification is a message.
    113113            if(!isCommand)
    114                 listener->registerNotification(message, sender, notificationMessageType::Value(messageType));
     114                listener->registerNotification(message, sender, type);
    115115
    116116            // If the notification is a command.
    117117            if(isCommand)
    118118            {
    119                 notificationCommand::Value command = str2Command(message);
    120                 if(command != notificationCommand::none)
     119                NotificationCommand command = str2Command(message);
     120                if(command != NotificationCommand::none)
    121121                    listener->executeCommand(command, sender);
    122122            }
     
    130130        The string to be converted.
    131131    @return
    132         Returns the corresponding enum, notificationCommand::none if the command doesn't exist.
     132        Returns the corresponding enum, NotificationCommand::none if the command doesn't exist.
    133133    */
    134     /*static*/ notificationCommand::Value NotificationListener::str2Command(const std::string& string)
     134    /*static*/ NotificationCommand NotificationListener::str2Command(const std::string& string)
    135135    {
    136         notificationCommand::Value command = notificationCommand::none;
     136        NotificationCommand command = NotificationCommand::none;
    137137
    138138        if(string == NotificationListener::COMMAND_CLEAR)
    139             command = notificationCommand::clear;
     139            command = NotificationCommand::clear;
    140140
    141141        return command;
     
    150150        Returns the corresponding string.
    151151    */
    152     /*static*/ const std::string& NotificationListener::command2Str(notificationCommand::Value command)
     152    /*static*/ const std::string& NotificationListener::command2Str(NotificationCommand command)
    153153    {
    154154        switch(command)
    155155        {
    156             case notificationCommand::clear:
     156            case NotificationCommand::clear:
    157157                return NotificationListener::COMMAND_CLEAR;
    158158            default:
  • code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.h

    r9667 r11003  
    4949{
    5050    // TODO: Document.
    51     namespace notificationMessageType
    52     {
    53         enum Value {
    54             info,
    55             important
    56         };
    57     }
     51    enum class NotificationMessageType {
     52        info,
     53        important
     54    };
    5855   
    59     namespace notificationSendMode
    60     {
    61         enum Value {
    62             local,
    63             network,
    64             broadcast
    65         };
    66     }
     56    enum class NotificationSendMode {
     57        local,
     58        network,
     59        broadcast
     60    };
    6761   
    68     namespace notificationCommand
    69     {
    70         enum Value {
    71             none,
    72             clear
    73         };
    74     }
     62    enum class NotificationCommand {
     63        none,
     64        clear
     65    };
    7566
    7667    // TODO: Update doc.
     
    10192            @param sender The sender that sent the notification. Default is 'none'.
    10293            @param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
    103             @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is notificationSendMode::local.
     94            @param sendMode The mode in which the notification is sent, can be 'local' to send the notification to the client where this function is executed, 'network' if the notification is to be sent to the client with the specified clientID, or 'broadcast' if the notification should be sent to all hosts. Default is NotificationSendMode::local.
    10495            @param clientId The id of the client the notification should be sent to. Default is 0.
    10596            */
    106             static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, notificationMessageType::Value messageType = notificationMessageType::info, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     97            static void sendNotification(const std::string& message, const std::string& sender = NotificationListener::NONE, NotificationMessageType messageType = NotificationMessageType::info, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0)
    10798                { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
    10899            /**
     
    110101            @param command The command that should be sent (and later executed).
    111102            @param sender The sender that sent the notification. Default is 'none'.
    112             @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.
     103            @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is NotificationSendMode::local.
    113104            @param clientId The id of the client the command should be sent to. Default is 0.
    114105            */
    115             static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
     106            static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0)
    116107                { NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
    117108
    118             static void sendHelper(const std::string& message, const std::string& sender, bool isCommand = false, unsigned int messageMode = 0); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
     109            static void sendHelper(const std::string& message, const std::string& sender, bool isCommand, NotificationMessageType type); // Helper method to register a notification/execute a command with all NotificationListeners after it has been sent over the network.
    119110
    120111            //TODO: Make protected?
     
    128119            @return Returns true if the notification was successfully registered, false if not.
    129120            */
    130             virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     121            virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type)
    131122                { return false; }
    132123            /**
     
    137128            @return Returns true if the command was successfully executed, false if not.
    138129            */
    139             virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
     130            virtual bool executeCommand(NotificationCommand command, const std::string& sender) { return false; }
    140131
    141132        public:
     
    149140           
    150141        protected:
    151             static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.
     142            static void sendNetworkHelper(const std::string& message, const std::string& sender, NotificationSendMode sendMode, unsigned int clientId, bool isCommand = false, NotificationMessageType messageType = NotificationMessageType::info); // Helper method to send both notifications and commands over the network.
    152143
    153             static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
    154             static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
     144            static NotificationCommand str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
     145            static const std::string& command2Str(NotificationCommand command); // Helper method. Converts a command enum into its corresponding string.
    155146    };
    156147}
Note: See TracChangeset for help on using the changeset viewer.