code cleanup

This commit is contained in:
Martin Brodbeck 2019-10-06 10:47:15 +02:00
parent 4f9151d85b
commit f0ec980e8d
4 changed files with 17 additions and 13 deletions

View file

@ -1,5 +1,9 @@
#include "entityint.h"
EntityInt::EntityInt(int id) {
id_ = id;
}
void EntityInt::setId(int id) {
id_ = id;
}

View file

@ -5,11 +5,13 @@
class EntityInt : public Entity
{
public:
public:
EntityInt() = default;
EntityInt(int id);
void setId(int id);
int getId() const {return id_;};
int getId() const { return id_; };
protected:
protected:
int id_{};
};

View file

@ -7,15 +7,14 @@
Seller::Seller(const std::string& firstName, const std::string& lastName, int sellerNo,
int numArticlesOffered)
: EntityInt()
: EntityInt(sellerNo)
{
firstName_ = firstName;
lastName_ = lastName;
sellerNo_ = sellerNo;
numArticlesOffered_ = numArticlesOffered;
}
void Seller::setSellerNo(int seller_no) { sellerNo_ = seller_no; id_ = seller_no;}
void Seller::setSellerNo(int seller_no) { setId(seller_no); }
void Seller::setFirstName(const std::string& firstName) { firstName_ = firstName; }
@ -33,13 +32,13 @@ std::string Seller::getFirstName() const { return firstName_; }
std::string Seller::getLastName() const { return lastName_; }
int Seller::getSellerNo() const { return sellerNo_; }
int Seller::getSellerNo() const { return getId(); }
std::string Seller::getSellerNoAsString() const
{
std::stringstream selNoStr;
selNoStr << std::setfill('0') << std::setw(3) << sellerNo_;
selNoStr << std::setfill('0') << std::setw(3) << id_;
return selNoStr.str();
;
@ -104,8 +103,8 @@ int Seller::sumInCents()
std::string Seller::sumAsString() { return formatCentAsEuroString(sumInCents()); }
bool operator<(const Seller& li, const Seller& re) { return li.sellerNo_ < re.sellerNo_; }
bool operator<(const Seller& li, const Seller& re) { return li.id_ < re.id_; }
bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re)
{
return li->sellerNo_ < re->sellerNo_;
return li->id_ < re->id_;
}

View file

@ -14,7 +14,7 @@ class Seller : public EntityInt
{
public:
Seller() = default;
// virtual ~Seller() = default;
~Seller() = default;
Seller(const std::string& firstName, const std::string& lastName, int sellerNo = 0,
int numArticlesOffered = 0);
@ -42,7 +42,6 @@ class Seller : public EntityInt
friend bool operator<(const std::unique_ptr<Seller>& li, const std::unique_ptr<Seller>& re);
private:
int sellerNo_{-1};
int numArticlesOffered_{};
std::string firstName_{};
std::string lastName_{};