diff options
Diffstat (limited to 'source/book.cc')
| -rw-r--r-- | source/book.cc | 102 |
1 files changed, 102 insertions, 0 deletions
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 <cstddef> +#include <ostream> +#include <string_view> +#include <utility> +#include <vector> + +#include <book_store/book.hh> +#include <book_store/person.hh> +#include <book_store/price.hh> + +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<class person> { + 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<class person> 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<std::vector<class person>::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 |