Бібліотечна система
Бібліотечна система для управління книгами
Завантаження...
Пошук...
Нічого не знайдено
Book.hpp
Див. документацію.
1// SPDX-License-Identifier: Proprietary
2// Copyright © 2025 Oleksandr Dreval. All rights reserved.
3
14#ifndef BOOK_HPP
15#define BOOK_HPP
16
17#include <nlohmann/json.hpp>
18#include <optional>
19#include <string>
20#include <vector>
21
23#include "Author.hpp"
24
25// clang-format off
26constexpr int MIN_PAGES = 1;
27constexpr int MIN_YEAR_PUBLISHED = 1455;
28// clang-format on
29
46class Book : public AbstractCollection {
47private:
48 // clang-format off
49 std::string m_title;
50 std::vector<Author> m_authors;
51 std::string m_isbn;
52 std::string m_publisher;
53 int m_numPages;
54 int m_yearPublished;
55 // clang-format on
56
62 bool isValidISBN(std::string_view isbn) const;
63
69 void processTitle(const nlohmann::json& jsonData);
70
76 void processISBN(const nlohmann::json& jsonData);
77
82 void processPublisher(const nlohmann::json& jsonData);
83
89 void processNumPages(const nlohmann::json& jsonData);
90
96 void processYearPublished(const nlohmann::json& jsonData);
97
102 void processBookId(const nlohmann::json& jsonData);
103
109 void processAuthor(const nlohmann::json& jsonData);
110
111public:
121 Book();
122
129 Book(std::string_view title, std::string_view bookId);
130
145 Book(
146 std::string_view title,
147 std::string_view bookId,
148 std::string_view isbn,
149 std::string_view publisher,
150 int numPages,
151 int yearPublished);
152
158 void addAuthor(const Author& author);
159
164 std::string getTitle() const noexcept { return m_title; }
165
170 const std::vector<Author>& getAuthors() const noexcept { return m_authors; }
171
177 void setTitle(std::string_view newTitle) {
178 m_title = newTitle;
180 }
181
194 void display() const override;
195
201 double calculateStat() const noexcept override;
202
214 bool search(const std::string& keyword) const override;
215
235 void fromJson(const nlohmann::json& jsonData);
236
241 std::string getISBN() const noexcept { return m_isbn; }
242
247 std::string getPublisher() const noexcept { return m_publisher; }
248
253 int getNumPages() const noexcept { return m_numPages; }
254
259 int getYearPublished() const noexcept { return m_yearPublished; }
260
265 void setISBN(std::string_view newISBN) noexcept { m_isbn = newISBN; }
266
271 void setPublisher(std::string_view newPublisher) noexcept { m_publisher = newPublisher; }
272
277 void setNumPages(int newNumPages) noexcept { m_numPages = newNumPages; }
278
283 void setYearPublished(int newYearPublished) noexcept { m_yearPublished = newYearPublished; }
284
289 void setAuthors(const std::vector<Author>& authors) noexcept { m_authors = authors; }
290
297 bool setBestBookForAuthor(const std::string& authorName, const std::string& bookTitle) {
298 for(auto& author : m_authors) {
299 if(author.searchByName(authorName)) {
300 author.setBestBook(bookTitle);
301 return true;
302 }
303 }
304 return false;
305 }
306
312 static std::optional<Book> createFromJson(const nlohmann::json& item);
313};
314
315#endif // BOOK_HPP
Визначає абстрактний базовий клас для всіх колекційних об'єктів у системі
Визначення класу для роботи з даними авторів книг у бібліотечній системі
constexpr int MIN_PAGES
Мінімальна допустима кількість сторінок
Definition Book.hpp:26
constexpr int MIN_YEAR_PUBLISHED
Мінімальний допустимий рік видання
Definition Book.hpp:27
Абстрактний базовий клас, що визначає інтерфейс для роботи з колекціями
Definition AbstractCollection.hpp:30
void setName(std::string_view newName) noexcept
Встановлює нову назву колекції
Definition AbstractCollection.hpp:73
Клас, що представляє автора книг у бібліотечній системі
Definition Author.hpp:46
bool searchByName(const std::string &searchName) const
Шукає автора за іменем
Definition Author.cpp:237
void setBestBook(std::string_view bestBook) noexcept
Встановлює нову кращу книгу
Definition Author.hpp:183
Клас, що представляє книгу в бібліотечній системі
Definition Book.hpp:46
const std::vector< Author > & getAuthors() const noexcept
Отримує список авторів книги
Definition Book.hpp:170
void setAuthors(const std::vector< Author > &authors) noexcept
Встановити новий список авторів
Definition Book.hpp:289
std::string getISBN() const noexcept
Отримати ISBN книги
Definition Book.hpp:241
bool setBestBookForAuthor(const std::string &authorName, const std::string &bookTitle)
Встановлює найкращу книгу для автора
Definition Book.hpp:297
int getYearPublished() const noexcept
Отримати рік видання
Definition Book.hpp:259
void addAuthor(const Author &author)
Додає автора до списку авторів книги
Definition Book.cpp:88
Book()
Конструктор за замовчуванням
Definition Book.cpp:36
std::string getPublisher() const noexcept
Отримати видавця книги
Definition Book.hpp:247
void fromJson(const nlohmann::json &jsonData)
Завантажує дані книги з JSON об'єкту
Definition Book.cpp:190
double calculateStat() const noexcept override
Обчислює статистичні дані про книгу @override.
Definition Book.cpp:138
void display() const override
Виводить детальну інформацію про книгу у консоль @override.
Definition Book.cpp:106
void setPublisher(std::string_view newPublisher) noexcept
Встановити нового видавця
Definition Book.hpp:271
void setYearPublished(int newYearPublished) noexcept
Встановити новий рік видання
Definition Book.hpp:283
bool search(const std::string &keyword) const override
Виконує пошук за ключовим словом
Definition Book.cpp:153
std::string getTitle() const noexcept
Отримує назву книги
Definition Book.hpp:164
void setISBN(std::string_view newISBN) noexcept
Встановити новий ISBN.
Definition Book.hpp:265
void setNumPages(int newNumPages) noexcept
Встановити нову кількість сторінок
Definition Book.hpp:277
void setTitle(std::string_view newTitle)
Встановлює нову назву книги
Definition Book.hpp:177
static std::optional< Book > createFromJson(const nlohmann::json &item)
Створює книгу з JSON даних
Definition Book.cpp:383
int getNumPages() const noexcept
Отримати кількість сторінок
Definition Book.hpp:253