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
|
#ifndef BOOK_HH
#define BOOK_HH
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include "book_count.hh"
#include "person.hh"
#include "price.hh"
namespace book_store::product {
class book {
public:
using size_type = book_count;
using price_type = price::usd;
private:
std::string _title;
std::vector<consumer::person> _authors;
std::string _publisher;
std::string _isbn;
price_type _price_usd;
size_type _copies;
public:
book(std::string title, std::vector<consumer::person> authors,
std::string publisher, std::string isbn, price::usd price,
size_type copies)
: _title(std::move(title)), _authors(std::move(authors)),
_publisher(std::move(publisher)), _isbn(std::move(isbn)),
_price_usd(price), _copies(copies) {}
book() noexcept : _authors({}), _price_usd(0.0), _copies(0) {}
book(const book &) noexcept = default;
book(book &&) noexcept = default;
[[nodiscard]] auto title() const noexcept -> std::string_view;
[[nodiscard]] auto authors() const noexcept -> std::vector<consumer::person>;
[[nodiscard]] auto publisher() const noexcept -> std::string_view;
[[nodiscard]] auto isbn() const noexcept -> std::string_view;
[[nodiscard]] auto price_usd() const noexcept -> price_type;
[[nodiscard]] auto copies() const noexcept -> size_type;
auto title(std::string_view title) noexcept -> book &;
auto authors(std::vector<consumer::person> authors) -> book &;
auto author(const consumer::person &author) -> book &;
auto remove_author_by_id(std::size_t author_id) -> book &;
auto publisher(std::string_view publisher) noexcept -> book &;
auto isbn(std::string_view isbn) noexcept -> book &;
auto price_usd(price_type price) noexcept -> book &;
auto copies(size_type copies) noexcept -> book &;
auto operator=(const book &) -> book & = default;
auto operator=(book &&) -> book & = default;
friend auto operator<<(std::ostream &output_stream, const book &book)
-> std::ostream &;
};
} // namespace book_store::product
#endif // BOOK_HH
|