template<class TS, class TD> void unwrapCollection(const ::google::protobuf::RepeatedPtrField<TS> src,
    std::vector<TD>& dst) {
    std::back_insert_iterator<std::vector<TD> > backInsertIter(dst);

    dst.clear();

    std::copy(src.begin(), src.end(), backInsertIter);
}
Пример #2
0
bool CUserShopStrategy::Init( CUser* pUser, 
							 const ::google::protobuf::RepeatedPtrField< ::db_user_shop >& shop_data, 
							 const ::google::protobuf::RepeatedPtrField< ::db_user_shop_buy >& shop_buy_data)
{
	ASSERT(pUser);
	ASSERT(m_mapWeightFactor.empty());
	m_mapWeightFactor.clear();

	m_pUser = pUser;

	for (::google::protobuf::RepeatedPtrField< ::db_user_shop >::const_iterator it = shop_data.begin() ; it != shop_data.end() ; ++it){
		ASSERT(m_userShopType2Shop.find((CShop::ESHOPTYPE)it->shop_type()) == m_userShopType2Shop.end());
		CShop* pShop = new CShop((CShop::ESHOPTYPE)it->shop_type());
		ASSERT(pShop);
		//pShop->eShopType = (CShop::ESHOPTYPE)it->shop_type();					//商店类型
		pShop->iLastAutoRefreshTime = it->last_auto_refresh_time();				//上一次的自动刷新时间
		pShop->iLastManualRefreshTime = it->last_manual_refresh_time();			//上一次的手动刷新时间
		pShop->iLastDayManualRefreshNum = it->last_day_manual_refresh_num();	//最后时间当日手动刷新的次数 
		pShop->iRandomOpenStartTimestamp = it->random_open_start_timestamp();
		pShop->iRandomOpenEndTimestamp = it->random_open_end_timestamp();

		//pShop->iTotalManualRefreshNum = it->total_manual_refresh_num();		//总共的手动刷新次数

		m_userShopType2Shop[pShop->eShopType] = pShop;

		//初始化商店信息
		for (::google::protobuf::RepeatedPtrField< ::db_user_shop_item >::const_iterator itIn = it->items().begin() ; itIn != it->items().end() ; ++itIn){
			stShopItem* pItem = new stShopItem(*itIn);
			bool r = pShop->Append(pItem);
			ASSERT(r && "商店添加道具失败!");
			if (!r){
				delete pItem;
				return false;
			}
		}
	}

	//初始化购买信息
	for (::google::protobuf::RepeatedPtrField< ::db_user_shop_buy >::const_iterator it = shop_buy_data.begin() ; it != shop_buy_data.end() ; ++it){
		std::pair<EELEMENTTYPE, UINT32> key = std::make_pair((EELEMENTTYPE)it->element_type(), it->element_id());
		//ASSERT(m_mapWeightFactor.find(key) == m_mapWeightFactor.end());
		if (m_mapWeightFactor.find(key) != m_mapWeightFactor.end()){
			return false;
		}

		bool isNeed = pUser->IsUserHeroEquipEvolutionNeed((EELEMENTTYPE)it->element_type(), it->element_id());
		CShopItemWeightFactor* factor = new CShopItemWeightFactor(it->last_day_buy_num(), it->last_buy_time(), isNeed);
		m_mapWeightFactor[key] = factor;
	}

	return true;
}
void unwrapCollection(const ::google::protobuf::RepeatedPtrField<ObjectWrapper>& src, std::vector<TD>& dst) {
    dst.clear();

    for (auto it = src.begin(); it != src.end(); ++it) {
        const ObjectWrapper& el = (*it);

        TD result;

        unwrap(el, result);

        dst.push_back(result);
    }
}
Пример #4
0
std::vector<T> convert(const google::protobuf::RepeatedPtrField<T>& items)
{
  return std::vector<T>(items.begin(), items.end());
}