code cleanup

This commit is contained in:
Martin Brodbeck 2018-07-20 11:52:26 +02:00
parent 74719b762f
commit 6000bb3ef2
17 changed files with 65 additions and 67 deletions

View file

@ -2,26 +2,20 @@
#include <numeric>
void Sale::addArticle(std::shared_ptr<Article> articlePtr)
void Sale::addArticle(Article* articlePtr)
{
articlePtr->setSale(this);
articles_.push_back(articlePtr);
}
std::vector<Article*> Sale::getArticles()
{
std::vector<Article*> articles(articles_.size());
for (const auto& article : articles_) {
articles.push_back(article.get());
}
return articles;
}
std::vector<Article*>& Sale::getArticles() { return articles_; }
void Sale::removeArticle(const Article* articlePtr)
{
auto it = std::find_if(articles_.begin(), articles_.end(),
[&articlePtr](auto art) { return art.get() == articlePtr; });
/* auto it = std::find_if(articles_.begin(), articles_.end(),
[&articlePtr](auto art) { return art.get() == articlePtr; }); */
auto it = std::find(articles_.begin(), articles_.end(), articlePtr);
if (it != articles_.end()) {
(*it)->setSale(nullptr);
(*it)->setState(
@ -33,7 +27,7 @@ void Sale::removeArticle(const Article* articlePtr)
int Sale::sumInCents()
{
int sum = std::accumulate(articles_.begin(), articles_.end(), 0,
[](int a, std::shared_ptr<Article> b) { return a + b->getPrice(); });
[](int a, const Article* b) { return a + b->getPrice(); });
return sum;
}