Use std C++ algorithmes in model

This commit is contained in:
2011-08-14 19:26:54 +02:00
parent 6596097f72
commit 8d7a019ca7
7 changed files with 45 additions and 37 deletions

View File

@@ -45,11 +45,9 @@ void User::InvalidateOperations()
Category User::GetCategory(const wxString& catId)
{
Category cat;
std::vector<Category>::iterator it;
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), catId);
for (it=_categories.begin(); it !=_categories.end(); it++)
if (it->id == catId)
return *it;
if (it !=_categories.end()) return *it;
if (_db->LoadCategory(catId, wxT(""), cat))
return cat;
@@ -67,11 +65,9 @@ Category User::GetCategory(const wxString& catId)
wxString User::GetCategoryName(const wxString& catId)
{
Category cat;
std::vector<Category>::iterator it;
std::vector<Category>::iterator it = std::find(_categories.begin(), _categories.end(), catId);
for (it=_categories.begin(); it !=_categories.end(); it++)
if (it->id == catId)
return it->name;
if (it !=_categories.end()) return it->name;
if (_db->LoadCategory(catId, wxT(""), cat))
return cat.name;
@@ -109,20 +105,21 @@ const wxFont User::GetCategoryFont(const wxString& catId)
return f;
}
Account User::GetAccount(const wxString& accountId)
Account User::GetAccount(const wxString& accountId) throw (AccountNotFound)
{
std::vector<Account>::iterator it;
for (it=_accounts.begin(); it !=_accounts.end(); it++)
if (it->id == accountId)
return *it;
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
if (it != _accounts.end())
return *it;
throw AccountNotFound();
}
wxString User::GetAccountName(const wxString& accountId)
{
std::vector<Account>::iterator it;
for (it=_accounts.begin(); it !=_accounts.end(); it++)
if (it->id == accountId)
return it->name;
std::vector<Account>::iterator it = std::find(_accounts.begin(), _accounts.end(), accountId);
if (it != _accounts.end()) return it->name;
return _("Unknown") ;
}
@@ -218,9 +215,7 @@ bool User::Group(std::vector<Operation>* ops, const Operation& op)
{
if (it->id == op.parent)
{
for (it2 = it->childs.begin(); it2 != it->childs.end(); it2++)
if (*it2 == op.id)
break;
it2 = std::find(it->childs.begin(), it->childs.end(), op.id);
// Already into childs
if (it2 != it->childs.end()) return true;
it->childs.push_back(op.id);