From fa3595d69f817ad1a67b7189ed65dbde1ba9f77d Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 26 May 2024 18:01:25 -0700 Subject: feat: initial commit --- source/book.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 source/book.cc (limited to 'source/book.cc') diff --git a/source/book.cc b/source/book.cc new file mode 100644 index 0000000..6b0bd6a --- /dev/null +++ b/source/book.cc @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace book_store::product { +using namespace consumer; + +auto book::title() const noexcept -> std::string_view { return this->_title; } + +auto book::authors() const noexcept -> std::vector { + return this->_authors; +} + +auto book::publisher() const noexcept -> std::string_view { + return this->_publisher; +} + +auto book::isbn() const noexcept -> std::string_view { return this->_isbn; } + +auto book::price_usd() const noexcept -> price::usd { return this->_price_usd; } + +auto book::copies() const noexcept -> book::size_type { return this->_copies; } + +auto book::title(std::string_view title) noexcept -> book & { + this->_title = title; + + return *this; +} + +auto book::authors(std::vector authors) -> book & { + this->_authors = std::move(authors); + + return *this; +} + +auto book::author(const class person &author) -> book & { + while (this->_authors.size() < 4) { + this->_authors.emplace_back(author); + + break; + } + + return *this; +} + +auto book::remove_author_by_id(std::size_t author_id) -> book & { + this->_authors.erase( + this->_authors.begin() + + static_cast::difference_type>(author_id)); + + return *this; +} + +auto book::publisher(std::string_view publisher) noexcept -> book & { + this->_publisher = publisher; + + return *this; +} + +auto book::isbn(std::string_view isbn) noexcept -> book & { + this->_isbn = isbn; + + return *this; +} + +auto book::price_usd(price::usd price) noexcept -> book & { + this->_price_usd = price; + + return *this; +} + +auto book::copies(book::size_type copies) noexcept -> book & { + this->_copies = copies; + + return *this; +} + +auto operator<<(std::ostream &output_stream, const book &book) + -> std::ostream & { + output_stream << "Title: " << book._title << '\n'; + output_stream << "Authors: "; + + for (const auto &author : book._authors) { + output_stream << author.full_name() + << ((&author == &book._authors.back()) ? "" : ", "); + } + + output_stream << '\n'; + output_stream << "Publisher: " << book._publisher << '\n'; + output_stream << "ISBN: " << book._isbn << '\n'; + output_stream << "Price: $" << book._price_usd << '\n'; + output_stream << "Copies: " << book._copies << '\n'; + + return output_stream; +} +} // namespace book_store::product -- cgit v1.2.3