|
本帖最后由 jimu 于 2016-12-7 10:35 编辑
1.QVector
QVector<QReadMailWindow *> m_pVecReadMailWindows;
//循环删除- for (int i = 0; i < m_pVecReadMailWindows.size(); i++)
- {
- if (m_pVecReadMailWindows.at(i) != NULL)
- {
- delete m_pVecReadMailWindows.at(i);
- m_pVecReadMailWindows.erase(m_pVecReadMailWindows.begin() + i);
- }
- }
复制代码 //添加- QReadMailWindow *rWin = new QReadMailWindow(mailId);
- m_pVecReadMailWindows.push_back(rWin);
复制代码 //查询- foreach(QReadMailWindow * rWin, m_pVecReadMailWindows)
- {
- if (rWin->getCloseStatus())
- {
- return rWin;
- }
- }
复制代码 qFind 查询 to implement operator==().
struct UserOperateAction
{
UserOperateAction()
: serverId(DEFAULT_VALUE_ZERO)
, operType(UOAT_UNKNOWE)
{
}
uint32_t serverId;
QString listPath;
QString uid;
int operType;
bool operator == (const UserOperateAction& rhs) const
{
return (serverId == rhs.serverId &&
listPath == rhs.listPath &&
uid == rhs.uid &&
operType == rhs.operType);
}
};
bool queryUserOperAct(const UserOperateAction & stUserOperateAction)
{
QVector<UserOperateAction>::const_iterator itFind = qFind(m_vecUserOperActs.begin(), m_vecUserOperActs.end(), stUserOperateAction);
if (itFind != m_vecUserOperActs.end())
{
return true;
}
return false;
}
bool clearUserOperAct()
{
for (int i = 0; i < m_vecUserOperActs.size(); i++)
{
m_vecUserOperActs.erase(m_vecUserOperActs.begin() + i);
}
}
bool removeUserOperAct(const UserOperateAction & stUserOperateAction)
{
QMutexLocker locker(&m_userOperActMutex);
QVector<UserOperateAction>::iterator itFind = qFind(m_vecUserOperActs.begin(), m_vecUserOperActs.end(), stUserOperateAction);
if (itFind != m_vecUserOperActs.end())
{
m_vecUserOperActs.erase(itFind);
}
return true;
}
2.QList
QMutex m_folderMutex;
QMutexLocker locker(&m_folderMutex);
QList<MailFolderInfo> m_listMailFoldersData;
//查询
for (int i = 0; i < m_listMailFoldersData.size(); ++i)
{
if (m_listMailFoldersData.at(i).parentId == parentId)
{
return m_listMailFoldersData.at(i).rowId;
}
}
//排序
qSort(m_listMailFoldersData.begin(), m_listMailFoldersData.end(), folderSortAlgorithm);
bool folderSortAlgorithm(const MailFolderInfo &mfi1, const MailFolderInfo &mfi2)
{
return mfi1.name < mfi2.name
}
//添加
bool addMailFolder(MailFolderInfo& stMailFolderInfo)
{
QMutexLocker locker(&m_folderMutex);
m_listMailFoldersData.push_back(stMailFolderInfo);
}
//删除
bool CMemoryDBManager::deleteMailFolder(uint32_t folderId)
{
QMutexLocker locker(&m_folderMutex);
for (int i = 0; i < m_listMailFoldersData.size(); ++i) {
if (m_listMailFoldersData.at(i).rowId == folderId){
m_listMailFoldersData.removeAt(i);
break;
}
}
}
//修改
bool updateMailFolderLegalMailCount(uint32_t folderId, uint32_t count)
{
QMutexLocker locker(&m_folderMutex);
for (int i = 0; i < m_listMailFoldersData.size(); ++i) {
if (m_listMailFoldersData.at(i).rowId == folderId){
m_listMailFoldersData.legalMailCountOnServer = count;
break;
}
}
return true;
}
3.QMap
//查询 不能用 [] 防止引入 新元素
MailHeaderInfo getMailHeader(uint64_t mailId)
{
QMapIterator<uint32_t, MemoryMailData> iter(m_mapMailMemoryData);
while (iter.hasNext()) {
iter.next();
for (int i = 0; i < iter.value().vecMailIndexDatas.size(); ++i) {
if (iter.value().vecMailIndexDatas.at(i).mailId == mailId){
return iter.value().vecMailIndexDatas.at(i);
}
}
}
}
|
|