You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB
C++

#ifndef EXAMPLE_COMMON_BOOK_H_
#define EXAMPLE_COMMON_BOOK_H_
#include <list>
#include <string>
#include "boost/filesystem/path.hpp"
// In-memory test data.
// There should be some database in a real product.
struct Book {
std::string id;
std::string title;
double price;
boost::filesystem::path photo;
bool IsNull() const { return id.empty(); }
};
std::ostream& operator<<(std::ostream& os, const Book& book);
extern const Book kNullBook;
class BookStore {
public:
const std::list<Book>& books() const {
return books_;
}
const Book& GetBook(const std::string& id) const;
// Add a book, return the ID.
// NOTE: The ID of the input book will be ignored so should be empty.
std::string AddBook(const Book& book);
bool UpdateBook(const Book& book);
bool DeleteBook(const std::string& id);
private:
std::list<Book>::const_iterator FindBook(const std::string& id) const;
std::list<Book>::iterator FindBook(const std::string& id);
// Allocate a new book ID.
std::string NewID() const;
std::list<Book> books_;
};
#endif // EXAMPLE_COMMON_BOOK_H_