Compare commits

...

2 commits

Author SHA1 Message Date
7c40ea6f97 use non-owning raw pointers in getArticles() 2018-07-12 12:15:27 +02:00
d64606c861 beautify code 2018-07-12 12:06:55 +02:00
4 changed files with 17 additions and 10 deletions

View file

@ -10,8 +10,10 @@ void Article::setPrice(int price) { price_ = price; }
void Article::setDescription(const std::string& description) { description_ = description; }
std::string Article::getDescription() { return description_; }
void Article::setSale(std::shared_ptr<Sale> salePtr) { salePtr_ = salePtr; }
bool Article::isSold() { return salePtr_ ? true : false; }
bool Article::isSold() { return salePtr_ ? true : false; }
std::string Article::getDescription() { return description_; }
Seller* Article::getSeller() { return sellerPtr_.get(); }

View file

@ -18,11 +18,13 @@ class Article : public Entity
void setArticleNo(int articleNo);
void setPrice(int price);
void setDescription(const std::string& description);
std::string getDescription();
bool isSold();
void setSale(std::shared_ptr<Sale> salePtr);
void setSeller(std::shared_ptr<Seller> sellerPtr);
std::string getDescription();
Seller* getSeller();
private:
std::shared_ptr<Seller> sellerPtr_{};
std::shared_ptr<Sale> salePtr_{};

View file

@ -30,15 +30,17 @@ std::string Seller::getLastName() const { return lastName_; }
int Seller::getSellerNo() const { return sellerNo_; }
std::vector<std::shared_ptr<Article>> Seller::getArticles(bool onlySold)
std::vector<Article*> Seller::getArticles(bool onlySold) const
{
std::vector<std::shared_ptr<Article>> articles;
std::vector<Article*> articles;
for (const auto article : articles_) {
if (onlySold && article->isSold()) {
articles.push_back(article);
articles.push_back(article.get());
} else if (!onlySold) {
articles.push_back(article);
articles.push_back(article.get());
}
}
return articles;
}
}
size_t Seller::soldArticles() const { return getArticles(true).size(); }

View file

@ -27,7 +27,8 @@ class Seller : public Entity
std::string getLastName() const;
int getSellerNo() const;
int getNumberOfOfferedArticles() const;
std::vector<std::shared_ptr<Article>> getArticles(bool onlySold = false);
size_t soldArticles() const;
std::vector<Article*> getArticles(bool onlySold = false) const;
private:
int sellerNo_{-1};