diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/my_nfts/auction.cc | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/my_nfts/auction.cc')
| -rw-r--r-- | graphs/cpp/my_nfts/auction.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/graphs/cpp/my_nfts/auction.cc b/graphs/cpp/my_nfts/auction.cc new file mode 100644 index 0000000..534c61d --- /dev/null +++ b/graphs/cpp/my_nfts/auction.cc @@ -0,0 +1,45 @@ +#include "auction.hh" + +#include <algorithm> +Auction::Auction(Person& organizer, NFT nft, uint initial_bid) + : organizer_{ organizer } + , nft_{ std::move(nft) } + , highest_bidder_{ nullptr } + , highest_bid_{ initial_bid } +{ + if (!nft_ || nft_->empty()) + throw std::invalid_argument{ "Invalid nft!" }; +} +Auction::~Auction() +{ + if (highest_bidder_ == nullptr) + organizer_.add_nft(std::move(nft_)); + else + { + highest_bidder_->add_nft(std::move(nft_)); + organizer_.add_money(highest_bid_); + } +} +bool Auction::bid(Person& person, uint money) +{ + if (money > highest_bid_) + { + if (highest_bidder_ == nullptr) + highest_bidder_ = &person; + else + highest_bidder_->add_money(highest_bid_); + highest_bid_ = money; + highest_bidder_ = &person; + highest_bidder_->remove_money(money); + return true; + } + return false; +} +const std::string& Auction::get_nft_name() const +{ + return *nft_; +} +uint Auction::get_highest_bid() const +{ + return highest_bid_; +}
\ No newline at end of file |
