diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-06-03 17:23:55 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-06-03 17:23:55 +0300 |
commit | 0bdaa773a4ee5a678c400a1b097190e3856ee5a6 (patch) | |
tree | d9855dad5292cc218be9251fecf3f53aa0fede35 /src | |
parent | 7aec0517fe0874b5ac6e6590d442aa89a6f8f5a7 (diff) | |
download | manaverse-0bdaa773a4ee5a678c400a1b097190e3856ee5a6.tar.gz manaverse-0bdaa773a4ee5a678c400a1b097190e3856ee5a6.tar.bz2 manaverse-0bdaa773a4ee5a678c400a1b097190e3856ee5a6.tar.xz manaverse-0bdaa773a4ee5a678c400a1b097190e3856ee5a6.zip |
Convert UpdateType enum into strong typed enum.
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/client.cpp | 5 | ||||
-rw-r--r-- | src/enums/net/updatetype.h | 18 | ||||
-rw-r--r-- | src/gui/dialogsmanager.cpp | 2 | ||||
-rw-r--r-- | src/gui/windows/logindialog.cpp | 11 | ||||
-rw-r--r-- | src/gui/windows/updaterwindow.cpp | 3 | ||||
-rw-r--r-- | src/gui/windows/updaterwindow.h | 6 | ||||
-rw-r--r-- | src/net/logindata.h | 4 | ||||
-rw-r--r-- | src/net/updatetypeoperators.cpp | 38 | ||||
-rw-r--r-- | src/net/updatetypeoperators.h | 30 |
11 files changed, 100 insertions, 21 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea6e551ab..1b8cc8ee8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -564,6 +564,8 @@ SET(SRCS net/serverinfo.h net/skillhandler.h net/tradehandler.h + net/updatetypeoperators.cpp + net/updatetypeoperators.h enums/net/updatetype.h net/uploadcharinfo.h net/worldinfo.h diff --git a/src/Makefile.am b/src/Makefile.am index aace933c5..d5052ae55 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -709,6 +709,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ net/serverinfo.h \ net/skillhandler.h \ net/tradehandler.h \ + net/updatetypeoperators.cpp \ + net/updatetypeoperators.h \ enums/net/updatetype.h \ net/uploadcharinfo.h \ net/worldinfo.h \ diff --git a/src/client.cpp b/src/client.cpp index bf0bc99ba..5c670696f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -86,6 +86,7 @@ #include "net/loginhandler.h" #include "net/net.h" #include "net/netconsts.h" +#include "net/updatetypeoperators.h" #include "net/packetlimiter.h" #include "net/partyhandler.h" @@ -1078,8 +1079,8 @@ int Client::gameExec() // lower than the default value theme->setMinimumOpacity(0.8F); - loginData.updateType - = serverConfig.getValue("updateType", 0); + loginData.updateType = static_cast<UpdateTypeT>( + serverConfig.getValue("updateType", 0)); mSearchHash = Net::Download::adlerBuffer( const_cast<char*>(mCurrentServer.hostname.c_str()), diff --git a/src/enums/net/updatetype.h b/src/enums/net/updatetype.h index 2245cec28..a461774b0 100644 --- a/src/enums/net/updatetype.h +++ b/src/enums/net/updatetype.h @@ -23,15 +23,15 @@ #ifndef ENUMS_NET_UPDATETYPE_H #define ENUMS_NET_UPDATETYPE_H -namespace UpdateType +#include "enums/simpletypes/enumdefines.h" + +enumStart(UpdateType) { - enum Type - { - Normal = 0, - Close = 1, - Skip = 2, - Custom = 4 - }; -} // namespace UpdateType + Normal = 0, + Close = 1, + Skip = 2, + Custom = 4 +} +enumEnd(UpdateType); #endif // ENUMS_NET_UPDATETYPE_H diff --git a/src/gui/dialogsmanager.cpp b/src/gui/dialogsmanager.cpp index 91fb96103..9df5dcb03 100644 --- a/src/gui/dialogsmanager.cpp +++ b/src/gui/dialogsmanager.cpp @@ -91,7 +91,7 @@ void DialogsManager::createUpdaterWindow() updaterWindow = new UpdaterWindow(settings.updateHost, settings.oldUpdates, false, - 0); + UpdateTypeT::Normal); updaterWindow->postInit(); } diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp index 5230ef4fe..2d7adc09f 100644 --- a/src/gui/windows/logindialog.cpp +++ b/src/gui/windows/logindialog.cpp @@ -43,6 +43,7 @@ #include "net/charserverhandler.h" #include "net/loginhandler.h" +#include "net/updatetypeoperators.h" #include "utils/delete2.h" #include "utils/paths.h" @@ -129,7 +130,7 @@ LoginDialog::LoginDialog(LoginData *const data, mUpdateTypeDropDown->setActionEventId("updatetype"); mUpdateTypeDropDown->setSelected((mLoginData->updateType - | UpdateType::Custom) ^ UpdateType::Custom); + | UpdateType::Custom) ^ static_cast<int>(UpdateType::Custom)); if (!mCustomUpdateHost->isSelected()) mUpdateHostText->setVisible(Visible_false); @@ -280,12 +281,14 @@ void LoginDialog::prepareUpdate() mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); mLoginData->remember = mKeepCheck->isSelected(); - int updateType = mUpdateTypeDropDown->getSelected(); + UpdateTypeT updateType = static_cast<UpdateTypeT>( + mUpdateTypeDropDown->getSelected()); if (mCustomUpdateHost->isSelected() && !mUpdateHostText->getText().empty()) { - updateType |= UpdateType::Custom; + updateType = static_cast<UpdateTypeT>( + updateType | UpdateType::Custom); serverConfig.setValue("customUpdateHost", mUpdateHostText->getText()); @@ -326,7 +329,7 @@ void LoginDialog::prepareUpdate() } mLoginData->updateType = updateType; - serverConfig.setValue("updateType", updateType); + serverConfig.setValue("updateType", static_cast<int>(updateType)); mRegisterButton->setEnabled(false); mServerButton->setEnabled(false); diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp index b8ead9549..ae63d194a 100644 --- a/src/gui/windows/updaterwindow.cpp +++ b/src/gui/windows/updaterwindow.cpp @@ -42,6 +42,7 @@ #include "gui/widgets/scrollarea.h" #include "net/download.h" +#include "net/updatetypeoperators.h" #include "resources/resourcemanager.h" @@ -168,7 +169,7 @@ static std::vector<UpdateFile> loadTxtFile(const std::string &fileName) UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost, const std::string &restrict updatesDir, const bool applyUpdates, - const int updateType) : + const UpdateTypeT updateType) : // TRANSLATORS: updater window name Window(_("Updating..."), Modal_false, nullptr, "update.xml"), ActionListener(), diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h index 06f707528..6484fe09d 100644 --- a/src/gui/windows/updaterwindow.h +++ b/src/gui/windows/updaterwindow.h @@ -24,6 +24,7 @@ #define GUI_WINDOWS_UPDATERWINDOW_H #include "enums/net/downloadstatus.h" +#include "enums/net/updatetype.h" #include "gui/widgets/linkhandler.h" #include "gui/widgets/window.h" @@ -69,7 +70,8 @@ class UpdaterWindow final : public Window, */ UpdaterWindow(const std::string &restrict updateHost, const std::string &restrict updatesDir, - const bool applyUpdates, const int updateType); + const bool applyUpdates, + const UpdateTypeT updateType); A_DELETE_COPY(UpdaterWindow) @@ -242,7 +244,7 @@ class UpdaterWindow final : public Window, /** Index offset for disaplay downloaded file. */ unsigned int mUpdateIndexOffset; - int mUpdateType; + UpdateTypeT mUpdateType; /** A flag to indicate whether to use a memory buffer or a regular * file. diff --git a/src/net/logindata.h b/src/net/logindata.h index acca562fd..1d6e6fd97 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -41,7 +41,7 @@ class LoginData final updateHost(), updateHosts(), lastLogin(), - updateType(0), + updateType(UpdateType::Normal), email(), captchaResponse(), registerUrl(), @@ -60,7 +60,7 @@ class LoginData final std::string updateHost; StringVect updateHosts; std::string lastLogin; - int updateType; + UpdateTypeT updateType; std::string email; std::string captchaResponse; diff --git a/src/net/updatetypeoperators.cpp b/src/net/updatetypeoperators.cpp new file mode 100644 index 000000000..7ce32dc92 --- /dev/null +++ b/src/net/updatetypeoperators.cpp @@ -0,0 +1,38 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "net/updatetypeoperators.h" + +#include "debug.h" + +int operator&(const UpdateTypeT &a, const UpdateTypeT &b) +{ + return static_cast<int>(a) & static_cast<int>(b); +} + +int operator|(const UpdateTypeT &a, const UpdateTypeT &b) +{ + return static_cast<int>(a) | static_cast<int>(b); +} + +int operator|(const int &a, const UpdateTypeT &b) +{ + return a | static_cast<int>(b); +} diff --git a/src/net/updatetypeoperators.h b/src/net/updatetypeoperators.h new file mode 100644 index 000000000..afc8ca185 --- /dev/null +++ b/src/net/updatetypeoperators.h @@ -0,0 +1,30 @@ +/* + * The ManaPlus Client + * Copyright (C) 2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef NET_UPDATETYPEOPERATORS_H +#define NET_UPDATETYPEOPERATORS_H + +#include "enums/net/updatetype.h" + +int operator&(const UpdateTypeT &a, const UpdateTypeT &b); +int operator|(const UpdateTypeT &a, const UpdateTypeT &b); +int operator|(const int &a, const UpdateTypeT &b); + +#endif // NET_UPDATETYPEOPERATORS_H |