[Orxonox-commit 6346] r11003 - in code/branches/cpp11_v2/src: modules/notifications modules/questsystem orxonox/infos orxonox/interfaces
landauf at orxonox.net
landauf at orxonox.net
Wed Dec 30 21:24:39 CET 2015
Author: landauf
Date: 2015-12-30 21:24:39 +0100 (Wed, 30 Dec 2015)
New Revision: 11003
Modified:
code/branches/cpp11_v2/src/modules/notifications/NotificationDispatcher.cc
code/branches/cpp11_v2/src/modules/notifications/NotificationManager.cc
code/branches/cpp11_v2/src/modules/notifications/NotificationManager.h
code/branches/cpp11_v2/src/modules/questsystem/QuestDescription.cc
code/branches/cpp11_v2/src/orxonox/infos/GametypeInfo.cc
code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.cc
code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.h
Log:
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.
Modified: code/branches/cpp11_v2/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/branches/cpp11_v2/src/modules/notifications/NotificationDispatcher.cc 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/modules/notifications/NotificationDispatcher.cc 2015-12-30 20:24:39 UTC (rev 11003)
@@ -112,7 +112,7 @@
{
// TODO: Needed?
const std::string message = this->createNotificationMessage();
- NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::local);
+ NotificationListener::sendNotification(message, this->getSender(), NotificationMessageType::info, NotificationSendMode::local);
// Broadcast
if(!GameMode::isStandalone())
@@ -143,7 +143,7 @@
{
const std::string message = this->createNotificationMessage();
// TODO: Make the type configurable.
- NotificationListener::sendNotification(message, this->getSender(), notificationMessageType::info, notificationSendMode::network, clientId);
+ NotificationListener::sendNotification(message, this->getSender(), NotificationMessageType::info, NotificationSendMode::network, clientId);
}
else if(GameMode::isServer())
{
Modified: code/branches/cpp11_v2/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/cpp11_v2/src/modules/notifications/NotificationManager.cc 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/modules/notifications/NotificationManager.cc 2015-12-30 20:24:39 UTC (rev 11003)
@@ -105,7 +105,7 @@
@return
Returns true if successful.
*/
- bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
+ bool NotificationManager::registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type)
{
// TODO: Do something with the type.
Notification* notification = new Notification(message, sender, type);
@@ -123,10 +123,10 @@
@return
Returns true if the command was successfully executed.
*/
- bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
+ bool NotificationManager::executeCommand(NotificationCommand command, const std::string& sender)
{
bool commandExecuted = false;
- if(command == notificationCommand::clear)
+ if(command == NotificationCommand::clear)
{
if(this->commandClear(sender))
commandExecuted = true;
@@ -436,7 +436,7 @@
@param type
*/
- Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
+ Notification::Notification(const std::string& message, const std::string& sender, NotificationMessageType type)
{
this->initialize();
this->message_ = message;
Modified: code/branches/cpp11_v2/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/cpp11_v2/src/modules/notifications/NotificationManager.h 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/modules/notifications/NotificationManager.h 2015-12-30 20:24:39 UTC (rev 11003)
@@ -61,7 +61,7 @@
class _NotificationsExport Notification
{
public:
- Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type);
+ Notification(const std::string& message, const std::string& sender, NotificationMessageType type);
virtual ~Notification();
/**
@@ -88,13 +88,13 @@
@brief Get the type of the Notification.
@return Returns an enum with the type of the Notification.
*/
- inline notificationMessageType::Value getType(void) const
+ inline NotificationMessageType getType(void) const
{ return this->type_; }
private:
std::string message_; //!< The Notification message.
std::string sender_; //!< The sender of the notification.
- notificationMessageType::Value type_; //!< The type of the notification.
+ NotificationMessageType type_; //!< The type of the notification.
void initialize(void); //!< Registers the object and sets some default values.
@@ -127,8 +127,8 @@
*/
static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
- virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type) override;
- virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) override;
+ virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type) override;
+ virtual bool executeCommand(NotificationCommand command, const std::string& sender) override;
bool registerNotification(Notification* notification); // Registers a Notification within the NotificationManager.
void unregisterNotification(Notification* notification, NotificationQueue* queue); // Unregisters a Notification within the NotificationManager for a given NotificationQueue.
Modified: code/branches/cpp11_v2/src/modules/questsystem/QuestDescription.cc
===================================================================
--- code/branches/cpp11_v2/src/modules/questsystem/QuestDescription.cc 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/modules/questsystem/QuestDescription.cc 2015-12-30 20:24:39 UTC (rev 11003)
@@ -118,7 +118,7 @@
return false;
}
- NotificationListener::sendNotification(message, QuestDescription::SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ NotificationListener::sendNotification(message, QuestDescription::SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
return true;
}
Modified: code/branches/cpp11_v2/src/orxonox/infos/GametypeInfo.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/infos/GametypeInfo.cc 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/orxonox/infos/GametypeInfo.cc 2015-12-30 20:24:39 UTC (rev 11003)
@@ -290,7 +290,7 @@
{
if(GameMode::isMaster())
{
- NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ NotificationListener::sendNotification("Press [Fire] to respawn", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
// Remove the player from the list of players that have spawned, since it currently is not.
this->spawnedPlayers_.erase(player);
this->setReadyToSpawnHelper(player, false);
@@ -345,10 +345,10 @@
{
// Display "Press [Fire] to start the match" if the game has not yet ended.
if(!this->hasEnded())
- NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ NotificationListener::sendNotification("Press [Fire] to start the match", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
// Else display "Game has ended".
else
- NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, notificationMessageType::info, notificationSendMode::network, player->getClientID());
+ NotificationListener::sendNotification("Game has ended", GametypeInfo::NOTIFICATION_SENDER, NotificationMessageType::info, NotificationSendMode::network, player->getClientID());
}
}
}
Modified: code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.cc
===================================================================
--- code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.cc 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.cc 2015-12-30 20:24:39 UTC (rev 11003)
@@ -73,22 +73,22 @@
@param messageType
The type of the notification, can be either 'info' or 'important'.
*/
- /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand, notificationMessageType::Value messageType)
+ /*static*/ void NotificationListener::sendNetworkHelper(const std::string& message, const std::string& sender, NotificationSendMode sendMode, unsigned int clientId, bool isCommand, NotificationMessageType messageType)
{
// If we're in standalone mode or we're already no the right client we create and send the notification/command.
- if(GameMode::isStandalone() || sendMode == notificationSendMode::local || (sendMode == notificationSendMode::network && Host::getPlayerID() == clientId))
+ if(GameMode::isStandalone() || sendMode == NotificationSendMode::local || (sendMode == NotificationSendMode::network && Host::getPlayerID() == clientId))
{
sendHelper(message, sender, isCommand, messageType);
}
// If we're on the server (and the server is not the intended recipient of the notification/command) we send it over the network.
- else if(GameMode::isServer() && sendMode == notificationSendMode::network && Host::getPlayerID() != clientId)
+ else if(GameMode::isServer() && sendMode == NotificationSendMode::network && Host::getPlayerID() != clientId)
{
- callStaticNetworkFunction(&NotificationListener::sendHelper, clientId, message, sender, isCommand, (unsigned int)messageType);
+ callStaticNetworkFunction(&NotificationListener::sendHelper, clientId, message, sender, isCommand, messageType);
}
- else if(GameMode::isServer() && sendMode == notificationSendMode::broadcast)
+ else if(GameMode::isServer() && sendMode == NotificationSendMode::broadcast)
{
// TODO: Works as intended?
- callStaticNetworkFunction(&NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, (unsigned int)messageType);
+ callStaticNetworkFunction(&NotificationListener::sendHelper, NETWORK_PEER_ID_BROADCAST, message, sender, isCommand, messageType);
}
}
@@ -104,20 +104,20 @@
@param messageType
The type of the notification.
*/
- /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, unsigned int messageType)
+ /*static*/ void NotificationListener::sendHelper(const std::string& message, const std::string& sender, bool isCommand, NotificationMessageType type)
{
// Iterate through all NotificationListeners and notify them by calling the method they overloaded.
for(NotificationListener* listener : ObjectList<NotificationListener>())
{
// If the notification is a message.
if(!isCommand)
- listener->registerNotification(message, sender, notificationMessageType::Value(messageType));
+ listener->registerNotification(message, sender, type);
// If the notification is a command.
if(isCommand)
{
- notificationCommand::Value command = str2Command(message);
- if(command != notificationCommand::none)
+ NotificationCommand command = str2Command(message);
+ if(command != NotificationCommand::none)
listener->executeCommand(command, sender);
}
}
@@ -129,14 +129,14 @@
@param string
The string to be converted.
@return
- Returns the corresponding enum, notificationCommand::none if the command doesn't exist.
+ Returns the corresponding enum, NotificationCommand::none if the command doesn't exist.
*/
- /*static*/ notificationCommand::Value NotificationListener::str2Command(const std::string& string)
+ /*static*/ NotificationCommand NotificationListener::str2Command(const std::string& string)
{
- notificationCommand::Value command = notificationCommand::none;
+ NotificationCommand command = NotificationCommand::none;
if(string == NotificationListener::COMMAND_CLEAR)
- command = notificationCommand::clear;
+ command = NotificationCommand::clear;
return command;
}
@@ -149,11 +149,11 @@
@return
Returns the corresponding string.
*/
- /*static*/ const std::string& NotificationListener::command2Str(notificationCommand::Value command)
+ /*static*/ const std::string& NotificationListener::command2Str(NotificationCommand command)
{
switch(command)
{
- case notificationCommand::clear:
+ case NotificationCommand::clear:
return NotificationListener::COMMAND_CLEAR;
default:
return NotificationListener::COMMAND_NONE;
Modified: code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.h
===================================================================
--- code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.h 2015-12-30 20:13:14 UTC (rev 11002)
+++ code/branches/cpp11_v2/src/orxonox/interfaces/NotificationListener.h 2015-12-30 20:24:39 UTC (rev 11003)
@@ -48,30 +48,21 @@
namespace orxonox
{
// TODO: Document.
- namespace notificationMessageType
- {
- enum Value {
- info,
- important
- };
- }
+ enum class NotificationMessageType {
+ info,
+ important
+ };
- namespace notificationSendMode
- {
- enum Value {
- local,
- network,
- broadcast
- };
- }
+ enum class NotificationSendMode {
+ local,
+ network,
+ broadcast
+ };
- namespace notificationCommand
- {
- enum Value {
- none,
- clear
- };
- }
+ enum class NotificationCommand {
+ none,
+ clear
+ };
// TODO: Update doc.
/**
@@ -100,22 +91,22 @@
@param message The message that should be sent.
@param sender The sender that sent the notification. Default is 'none'.
@param messageType The type of the message, can be either 'info' or 'important'. Default is 'info'.
- @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.
+ @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.
@param clientId The id of the client the notification should be sent to. Default is 0.
*/
- 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)
+ 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)
{ NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
/**
@brief Sends a specified command to the specified client from the specified sender.
@param command The command that should be sent (and later executed).
@param sender The sender that sent the notification. Default is 'none'.
- @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.
+ @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.
@param clientId The id of the client the command should be sent to. Default is 0.
*/
- static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, notificationSendMode::Value sendMode = notificationSendMode::local, unsigned int clientId = 0)
+ static void sendCommand(const std::string& command, const std::string& sender = NotificationListener::NONE, NotificationSendMode sendMode = NotificationSendMode::local, unsigned int clientId = 0)
{ NotificationListener::sendNetworkHelper(command, sender, sendMode, clientId, true); }
- 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.
+ 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.
//TODO: Make protected?
@@ -127,7 +118,7 @@
@param type The type of the notification.
@return Returns true if the notification was successfully registered, false if not.
*/
- virtual bool registerNotification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
+ virtual bool registerNotification(const std::string& message, const std::string& sender, NotificationMessageType type)
{ return false; }
/**
@brief Executes a command with the NotificationListener
@@ -136,7 +127,7 @@
@param sender The sender of the command.
@return Returns true if the command was successfully executed, false if not.
*/
- virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
+ virtual bool executeCommand(NotificationCommand command, const std::string& sender) { return false; }
public:
@@ -148,10 +139,10 @@
static const std::string COMMAND_NONE;
protected:
- 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.
+ 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.
- static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
- static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
+ static NotificationCommand str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
+ static const std::string& command2Str(NotificationCommand command); // Helper method. Converts a command enum into its corresponding string.
};
}
More information about the Orxonox-commit
mailing list