From 6596097f72d5ab7d980dfb342310054c3a8670c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 14 Aug 2011 18:29:18 +0200 Subject: [PATCH] Creates operator() for Account and remove sortAccounts --- src/controller/KissCount.cpp | 2 +- src/model/Account.cpp | 34 ---------------------------------- src/model/Account.h | 16 ++++++++++++++-- 3 files changed, 15 insertions(+), 37 deletions(-) delete mode 100644 src/model/Account.cpp diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index c8f83e9..185bdad 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -193,7 +193,7 @@ void KissCount::UpdateAccount(Account& ac) _user->_accounts[i] = ac; if (ac._default) - std::sort(_user->_accounts.begin(), _user->_accounts.end(), sortAccounts); + std::sort(_user->_accounts.begin(), _user->_accounts.end(), Account()); } void KissCount::DeleteAccount(Account& ac, const wxString& replacement) diff --git a/src/model/Account.cpp b/src/model/Account.cpp deleted file mode 100644 index b207df9..0000000 --- a/src/model/Account.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2010-2011 Grégory Soutadé - - This file is part of KissCount. - - KissCount 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 3 of the License, or - (at your option) any later version. - - KissCount 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 KissCount. If not, see . -*/ - -#include "Account.h" - -bool sortAccounts(Account ac1, Account ac2) -{ - if (ac1._default) return true; - if (ac2._default) return false; - - if (!ac1.blocked && ac2.blocked) return true; - if (ac1.blocked && !ac2.blocked) return false; - - if (!ac1._virtual && ac2._virtual) return true; - if (ac1._virtual && !ac2._virtual) return false; - - return (ac1.name.Cmp(ac2.name) < 0); -} diff --git a/src/model/Account.h b/src/model/Account.h index e49ee0f..42d2fcc 100644 --- a/src/model/Account.h +++ b/src/model/Account.h @@ -31,8 +31,20 @@ struct Account { bool _default; bool is_owner; bool _virtual; + + bool operator() (const Account& ac1, const Account& ac2) const + { + if (ac1._default) return true; + if (ac2._default) return false; + + if (!ac1.blocked && ac2.blocked) return true; + if (ac1.blocked && !ac2.blocked) return false; + + if (!ac1._virtual && ac2._virtual) return true; + if (ac1._virtual && !ac2._virtual) return false; + + return (ac1.name.Cmp(ac2.name) < 0); + } }; -bool sortAccounts(Account ac1, Account ac2); - #endif