CompoundResourceMap.cpp 4.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
#include "stdafx.h"
#include "CompoundResourceMap.h"
#include "BookInfo.h"
#include "Function.h"
#include <string>
CCompoundResourceMap::CCompoundResourceMap(void)
{
	
	
	for(int n=0;n<3;n++)
	{
		vector<COMPOUNDRES*> vc_temp;
		int nRand=0;

		for(int nn=0;nn<2;nn++)
		{
			COMPOUNDRES* aa =new COMPOUNDRES;
			nRand =nn+n;
			CString strnum=L"";
			strnum.Format(L"RES10%d",nRand);

			aa->strResID =strnum;
			if(nn==0)
			{
				aa->nStatus =CompoundRes_State::CompoundRES_Download_OK;
			}else
			{
				aa->nStatus =CompoundRes_State::CompoundRES_Download_None;
				aa->llDownloadedSize =300;
				aa->llFileSize = 3000;
			}
			vc_temp.push_back(aa);
		}
		
		CString strBookId=L"";

		if(n==0)
		{
			strBookId.Format(L"UUid99%d",n);
		}else
		{
			strBookId.Format(L"UUid00%d",n);
		}
		
		AddResData(strBookId,vc_temp);
	
	}

	COMPOUNDRES* bb = new COMPOUNDRES;
	GetFirstNeedDownLoadData(*bb);
	if(bb->strResID !="")
	{
		AfxMessageBox(bb->strResID);
	}
	DeleteResData(L"RES003");
	

}


CCompoundResourceMap::~CCompoundResourceMap(void)
{
}

BOOL CCompoundResourceMap::AddResData(CString strKey,vector<COMPOUNDRES*> v_pCompoundRes)
{
	//判断是否有KEY 存在则Erase 后再新增
	//for(int nSize=0;nSize<v_pCompoundRes.size();nSize++)
	//{
	//	if(strKey == )
	//}student.insert(map<int,string>::value_type(1,"liMing"));
	CFunction fun;
	std::pair<std::unordered_map<std::string,vector<COMPOUNDRES*>>::iterator,bool>ret;
	ret =m_map_CompoundResData.insert(std::unordered_map<std::string,vector<COMPOUNDRES*>>::value_type(fun.UnicodeToAscii(strKey),v_pCompoundRes));
	
	//ret =m_map_CompoundResData.insert(pair<CString,vector<COMPOUNDRES*>>(strKey,v_pCompoundRes));
	return ret.second;
}

void CCompoundResourceMap::ClearAllData()
{
	
	BOOL bRet=FALSE;

	if(!m_map_CompoundResData.empty())
	{
		//FirstRes =m_map_CompoundResData.at(0);
		std::unordered_map<std::string,std::vector<COMPOUNDRES*>>::iterator it;
		for (it = m_map_CompoundResData.begin(); it != m_map_CompoundResData.end(); it++)
		{

			std::string strBookId = it->first;
			std::vector<COMPOUNDRES*> vc_AllResTemp =it->second;
			for(int nSize=0;nSize<vc_AllResTemp.size();nSize++)
			{
				COMPOUNDRES* p_CompoundResData= vc_AllResTemp.at(nSize);
				if(p_CompoundResData)
				{
					delete p_CompoundResData;
					p_CompoundResData=NULL;
				}
			}
			vc_AllResTemp.clear();
		}
		m_map_CompoundResData.clear();
	}
	
}

int CCompoundResourceMap::GetSizeOfMap()
{
	return m_map_CompoundResData.size();
}

BOOL CCompoundResourceMap::GetFirstNeedDownLoadData(COMPOUNDRES& FirstRes)
{
	BOOL bRet=FALSE;
	//找到第一笔 待下载的资源
	if(!m_map_CompoundResData.empty())
	{
		//FirstRes =m_map_CompoundResData.at(0);
		std::unordered_map<std::string,std::vector<COMPOUNDRES*>>::iterator it;
		for (it = m_map_CompoundResData.begin(); it != m_map_CompoundResData.end(); it++) {

			std::string strBookId = it->first;
			std::vector<COMPOUNDRES*> vc_AllResTemp =it->second;
			for(int nSize=0;nSize<vc_AllResTemp.size();nSize++)
			{
				COMPOUNDRES* p_CompoundResData= vc_AllResTemp.at(nSize);
				//判断下载状态
				if((p_CompoundResData->nStatus!=CompoundRes_State::CompoundRES_Download_OK)&&(p_CompoundResData->llDownloadedSize<p_CompoundResData->llFileSize))
				{
					//需要下载的资源
					FirstRes = *p_CompoundResData;
					return TRUE;
				}
			}
		}

		bRet =TRUE;
	}
	return bRet;
}

BOOL CCompoundResourceMap::FindResData(CString strResID,COMPOUNDRES& FindRes)
{
	//对所有Map 查找 
	BOOL bRet=FALSE;
	//找到符合的资源
	if(!m_map_CompoundResData.empty())
	{
		//FirstRes =m_map_CompoundResData.at(0);
		std::unordered_map<std::string,std::vector<COMPOUNDRES*>>::iterator it;
		for (it = m_map_CompoundResData.begin(); it != m_map_CompoundResData.end(); it++)
		{

			std::string strBookId = it->first;
			std::vector<COMPOUNDRES*> vc_AllResTemp =it->second;
			for(int nSize=0;nSize<vc_AllResTemp.size();nSize++)
			{
				COMPOUNDRES* p_CompoundResData= vc_AllResTemp.at(nSize);
				
				if((p_CompoundResData->strResID==strResID))
				{
					//查找的资源
					FindRes = *p_CompoundResData;
					return TRUE;
				}
			}
		}
	}
	return bRet;
	//返回改笔数据
}

void CCompoundResourceMap::DeleteResData(CString strResID)
{
	//对所有Map 查找 
	BOOL bRet=FALSE;
	//找到符合的资源
	if(!m_map_CompoundResData.empty())
	{
		//FirstRes =m_map_CompoundResData.at(0);
		std::unordered_map<std::string,std::vector<COMPOUNDRES*>>::iterator it;
		for (it = m_map_CompoundResData.begin(); it != m_map_CompoundResData.end(); it++)
		{

			std::string strBookId = it->first;
			std::vector<COMPOUNDRES*> vc_AllResTemp =it->second;
			std::vector<COMPOUNDRES*>::iterator it2 =vc_AllResTemp.begin();
			for(it2 = vc_AllResTemp.begin(); it2 != vc_AllResTemp.end(); it2++)
			{
				COMPOUNDRES* p_CompoundResData= *it2;
				if((p_CompoundResData->strResID==strResID))
				{
					//需要删除的资源
					if(p_CompoundResData)
					{
						delete p_CompoundResData;
						p_CompoundResData=NULL;
					}
					vc_AllResTemp.erase(it2++);

					return;
				}

			}
		}
	}
}