⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repository.cpp

📁 一个帮助你学习英语的软件~~很不错的咯~~ 对功能又做了改进~大家支持下哈~
💻 CPP
字号:
//PK 2007/02/05 - 03/07
//PK Recite

#include "Repository.h"
#include "Book.h"
#include "configurations.h"

CRepository::~CRepository()
{	//PK 2007/02/13
	t_book::iterator itr = _books.begin(), itr_end = _books.end();
	for (; itr != itr_end; ++itr) delete (*itr);
	_books.clear();
}
bool CRepository::load()
{	//PK 2007/02/05 - 03/07
	bool res = _load_books();
	if (!res) return false;
	//PK set active books
	int amount = g_config.active_books_size();
	for (int i = 0; i < amount; ++i) {
		const string & id = g_config.get_active_book(i);
		t_book::iterator itr = _books.begin(), itr_end = _books.end();
		for (; itr != itr_end; ++itr) {
			if ((*itr)->get_book_id() == id) {
				(*itr)->set_active(true);
				break;
			}
		}
	}
	return true;
}
CBook * CRepository::_load_book(const fs::path & dir, const string & name)
{	//PK 2007/03/05
	CBook * book = new CBook();

	if (!name.empty()) book->book_name(name);
	bool res = book->load(dir);
	assert(res);
	_books.push_back(book);

	return book;
}
bool CRepository::_load_books()
{	//PK 2007/02/05 - 03/05
	
	//PK if the repository directory is not existed, create it
	fs::path rep_dir = g_root_dir / g_repository_dir;
	if (!fs::exists(rep_dir)) {
		fs::create_directories(rep_dir);
		return false;
	}

	//PK scan the repository directory, load books
	fs::directory_iterator itr_end;
	for (fs::directory_iterator itr(rep_dir); itr != itr_end; ++itr) {
		if (fs::is_directory(*itr)) {
			string no_name;
			_load_book(*itr, no_name);
		}
	}

	return true;
}
CBook * CRepository::add_book(const string & name, const fs::path & dir)
{	//PK 2007/03/05
	fs::path rep_dir = g_root_dir / g_repository_dir;
	fs::path book_dir = rep_dir / dir;
	if (fs::exists(book_dir)) return NULL;
	fs::create_directory(rep_dir / dir);
	return _load_book(rep_dir / dir, name);
}
CBook * CRepository::get_book(int index)
{	//PK 2007/02/13
	assert(index >= 0);
	if (index > size()) return NULL;
	return _books[index];
}
int CRepository::size()
{	//PK 2007/02/26
	return _books.size(); 
}
bool CRepository::delete_book(CBook * book)
{	//PK 2007/03/07
	assert(book != NULL);
	book->delete_self();
	t_book::iterator itr = find(_books.begin(), _books.end(), book);
	assert(itr != _books.end());
	_books.erase(itr);
	delete book;
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -