64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
#ifndef APP_HPP
|
|
#define APP_HPP
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include "book.hpp"
|
|
|
|
/// @brief 图书管理系统的主控类
|
|
///
|
|
/// 提供增删改查等核心业务逻辑,内部使用 std::vector<Book> 存储。
|
|
class App {
|
|
public:
|
|
/// @brief 默认构造函数,初始化空的图书系统
|
|
App() = default;
|
|
|
|
/// @brief 添加一本图书
|
|
/// @param book 要添加的图书对象
|
|
/// @return true 如果添加成功;如果 ISBN 已存在则返回 false
|
|
bool addBook(const Book& book);
|
|
|
|
/// @brief 根据 ISBN 删除图书
|
|
/// @param isbn 要删除的图书 ISBN
|
|
/// @return true 如果找到并删除成功;否则返回 false
|
|
bool removeBook(const std::string& isbn);
|
|
|
|
/// @brief 根据 ISBN 查找图书
|
|
/// @param isbn 要查找的 ISBN
|
|
/// @return 指向找到的图书的指针,未找到返回 nullptr
|
|
[[nodiscard]] const Book* findByIsbn(const std::string& isbn) const;
|
|
|
|
/// @brief 根据关键字搜索(匹配书名或作者,不区分大小写)
|
|
/// @param keyword 搜索关键字
|
|
/// @return 匹配的图书列表
|
|
[[nodiscard]] std::vector<Book> search(const std::string& keyword) const;
|
|
|
|
/// @brief 借出图书
|
|
/// @param isbn 要借出的图书 ISBN
|
|
/// @return true 如果图书存在且未被借出;否则 false
|
|
bool borrowBook(const std::string& isbn);
|
|
|
|
/// @brief 归还图书
|
|
/// @param isbn 要归还的图书 ISBN
|
|
/// @return true 如果图书存在且已借出;否则 false
|
|
bool returnBook(const std::string& isbn);
|
|
|
|
/// @brief 获取所有图书列表
|
|
/// @return 所有图书的常量引用向量
|
|
[[nodiscard]] const std::vector<Book>& getAllBooks() const noexcept;
|
|
|
|
/// @brief 获取图书数量
|
|
/// @return 当前图书总数
|
|
[[nodiscard]] size_t size() const noexcept;
|
|
|
|
private:
|
|
std::vector<Book> books_;
|
|
|
|
/// @brief 辅助函数:将字符串转为小写
|
|
/// @param str 输入字符串
|
|
/// @return 全小写字符串
|
|
static std::string toLower(const std::string& str);
|
|
};
|
|
|
|
#endif // APP_HPP
|