blob: a2c0a1380cad13fcec459fd32094e75885c939c3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
|