using shared_ptr
This commit is contained in:
parent
92fa2ef42a
commit
2131f12237
4 changed files with 13 additions and 13 deletions
|
@ -22,7 +22,7 @@ inline void Seller::setNumberOfOfferedArticles(int number) { numberOfOfferedArti
|
|||
|
||||
int Seller::getNumberOfOfferedArticles() const { return static_cast<int>(articles_.size()); }
|
||||
|
||||
void Seller::addArticle(Article article) { articles_.push_back(article); }
|
||||
void Seller::addArticle(std::shared_ptr<Article> article) { articles_.push_back(article); }
|
||||
|
||||
std::string Seller::getFirstName() const { return firstName_; }
|
||||
|
||||
|
@ -30,14 +30,14 @@ std::string Seller::getLastName() const { return lastName_; }
|
|||
|
||||
int Seller::getSellerNo() const { return sellerNo_; }
|
||||
|
||||
std::vector<Article*> Seller::getArticles(bool onlySold)
|
||||
std::vector<std::shared_ptr<Article>> Seller::getArticles(bool onlySold)
|
||||
{
|
||||
std::vector<Article*> articles;
|
||||
for (auto& article : articles_) {
|
||||
if (onlySold && article.isSold()) {
|
||||
articles.push_back(&article);
|
||||
std::vector<std::shared_ptr<Article>> articles;
|
||||
for (const auto article : articles_) {
|
||||
if (onlySold && article->isSold()) {
|
||||
articles.push_back(article);
|
||||
} else if (!onlySold) {
|
||||
articles.push_back(&article);
|
||||
articles.push_back(article);
|
||||
}
|
||||
}
|
||||
return articles;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "article.h"
|
||||
#include "entity.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -20,20 +21,20 @@ class Seller : public Entity
|
|||
void setFirstName(const std::string& firstName);
|
||||
void setLastName(const std::string& lastName);
|
||||
void setNumberOfOfferedArticles(int number);
|
||||
void addArticle(Article article);
|
||||
void addArticle(std::shared_ptr<Article> article);
|
||||
|
||||
std::string getFirstName() const;
|
||||
std::string getLastName() const;
|
||||
int getSellerNo() const;
|
||||
int getNumberOfOfferedArticles() const;
|
||||
std::vector<Article*> getArticles(bool onlySold = false);
|
||||
std::vector<std::shared_ptr<Article>> getArticles(bool onlySold = false);
|
||||
|
||||
private:
|
||||
int sellerNo_{-1};
|
||||
int numberOfOfferedArticles_{};
|
||||
std::string firstName_{};
|
||||
std::string lastName_{};
|
||||
std::vector<Article> articles_{};
|
||||
std::vector<std::shared_ptr<Article>> articles_{};
|
||||
};
|
||||
|
||||
#endif
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
BOOST_AUTO_TEST_CASE(create_database)
|
||||
{
|
||||
|
||||
Database db(":memory:");
|
||||
BOOST_CHECK_NO_THROW(db.init());
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ BOOST_AUTO_TEST_CASE(create_many)
|
|||
|
||||
BOOST_AUTO_TEST_CASE(with_article) {
|
||||
Seller seller("Max", "Mustermann");
|
||||
Article article{};
|
||||
article.setDescription("Test article");
|
||||
auto article = std::make_shared<Article>();
|
||||
article->setDescription("Test article");
|
||||
seller.addArticle(article);
|
||||
BOOST_TEST(seller.getArticles().at(0)->getDescription() == "Test article");
|
||||
}
|
Loading…
Reference in a new issue