📄 records.cpp
字号:
//PK 2007/02/10 - 03/01
//PK Recite
#include "stdafx.h"
#include "Records.h"
CRecords::CRecords() : _is_dirty(false)
{ //PK 2007/02/13
}
CRecords::~CRecords()
{ //PK 2007/03/09
t_infos::iterator itr = _infos.begin(), itr_end = _infos.end();
for (; itr != itr_end; ++itr) delete itr->second;
_infos.clear();
}
void CRecords::file_name(fs::path fn)
{ //PK 2007/02/20
if (!fs::exists(fn)) {
fs::path dir = fn.branch_path();
if (!fs::exists(dir)) fs::create_directories(dir);
}
_file_name = fn;
}
bool CRecords::load()
{ //PK 2007/02/10 - 20
if (!fs::exists(_file_name)) return false;
fs::ifstream ifs(_file_name);
ar::text_iarchive ia(ifs);
CRecords & records = *this;
ia >> records;
return true;
}
bool CRecords::save()
{ //PK 2007/02/10 - 14
if (!_is_dirty) return true;
fs::ofstream ofs(_file_name);
ar::text_oarchive oa(ofs);
const CRecords & records = *this;
oa << records;
return true;
}
CItemInfo * CRecords::get_info(const string & name)
{ //PK 2007/02/13 - 03/09
//_print();
t_infos::iterator itr = _infos.find(name);
if (itr == _infos.end()) {
//PK create a new item_info object
CItemInfo * info = new CItemInfo;
_infos[name] = info;
_is_dirty = true;
}
itr = _infos.find(name);
//_print();
return itr->second;
}
void CRecords::_print() const
{ //PK 2007/02/22
stringstream size;
size << "size:" << _infos.size() << std::endl;
OutputDebugString(size.str().c_str());
t_infos::const_iterator itr = _infos.begin(), itr_end = _infos.end();
for (; itr != itr_end; ++itr) {
stringstream pro;
pro << itr->first << " " << itr->second->times() << std::endl;
OutputDebugString(pro.str().c_str());
}
}
void CRecords::trim(t_names & names)
{ //PK 2007/02/26
//PK delete the redundant recorders
assert(names.size() < _infos.size());
t_infos::iterator itr = _infos.begin(), itr_end = _infos.end();
t_names::iterator no_name = names.end();
for (; itr != itr_end;) {
if (no_name == names.find(itr->first)) _infos.erase(itr++);
else ++itr;
}
dirty();
assert(names.size() == _infos.size());
}
bool CRecords::remove_info(const string & title)
{ //PK 2007/03/05
t_infos::iterator itr = _infos.find(title);
if (itr == _infos.end()) return false;
_infos.erase(itr);
dirty();
return true;
}
void CRecords::change_record_name(const string & src, const string & tar)
{ //PK 2007/03/08
t_infos::iterator itr = _infos.find(src);
if (itr == _infos.end()) return;
_infos[tar] = itr->second;
_infos.erase(itr);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -