Beispiel #1
0
int main()
{
    CMyList<int> lst;
//     
//     POSTION pos1 = lst.AddTail(10);
// 
//     lst.AddTail(7);
//     lst.AddTail(2);
//     POSTION pos2 = lst.AddTail(0);
//     
//     POSTION start = lst.Insert(pos1, 100);
//     lst.Insert(pos2, 20);
//     
//     lst.RemoveAt(pos1);
//     
//     lst.RemoveAt(lst.Find(20));
//     POSTION end = lst.AddTail(112233);
//     lst.RemoveAt(start);
//     lst.RemoveAt(end);


    POSTION pos4 = lst.AddTail(123);
    POSTION pos5 = lst.AddTail(456);
    POSTION pos6 = lst.AddTail(789);

    lst.ChangeNode(pos4, pos5);
    lst.ChangeNode(pos5, pos6);
    lst.ChangeNode(pos4, pos6);

    


    return 0;
}
Beispiel #2
0
int main()
{
	CMyList lst;
	CPlorg pl1("Plorg1", 100);
	CPlorg pl2("Plorg2", 200);
	CPlorg pl3("Plorg3", 300);
	lst + &pl1;
	lst + &pl2;
	lst + &pl3;
	lst.GetItem(2)->ShowData();
	lst.GetItem(2)->ChangeCI(500);
	lst.GetItem(2)->ShowData();
	lst.operator-();
	lst.GetItem(2);

	std::cin.get();
	return 0;
}
Beispiel #3
0
int main()
{
    CMyList<int> list;

    list.addFirst(5);
    list.addFirst(5);
    list.addFirst(5);
    list.addFirst(45);
    list.addFirst(3);
    list.addFirst(5);
    //list.remove(5);

    const uint64_t sizet = 10;
    int tab[sizet];
    list.getItems(tab,sizet);
    for(int i=0;i<sizet;i++)
        cout<<tab[i]<<endl;

    list.removeLast();
    list.removeFirst();
    list.clear();

    return 0;
}
Beispiel #4
0
void* SERVICE_send_bag(void* argv)
{
	tp_socket_info *socket_info = (tp_socket_info *)argv;
	int n_write;
	struct package_head bag_head;
	int func_num;
	int t;
	

	if (server_answer)
	{		
		memcpy((char *)&bag_head,(char *)socket_info->buffer+1,sizeof(struct package_head));
		AnswerList.addNode((void *)&bag_head);
	}

	n_write=write(socket_info->client_socket_fd,(char *)socket_info->buffer,socket_info->len);

	free(socket_info->buffer);
	free(socket_info);


}
Beispiel #5
0
int main(int argc, char* argv[])
{
  CMyList list;
  for (int i = 1; i < 2; i++)
     list.AddTail(i);
  list.RemoveAt(0);

  printf("%d:", list.Length());
  CNode *pNode = list.GetHead();
  while(pNode != NULL)
  {
    printf("%d ", pNode->m_Elem);
    pNode = pNode->m_pNext;
  }
  printf("\r\n");
  pNode = list.GetTail();
  while(pNode != NULL)
  {
    printf("%d ", pNode->m_Elem);
    pNode = pNode->m_pPrev;
  }
  printf("\r\n");
	return 0;
}
Beispiel #6
0
******************************/
void* SERVICE_read_event(void *argv)
{
	char buffer[MAX_SIZE]={0};
	int client_socket;
	int n_read;
	char head_get,back_get;
	struct package_head bag_head;
	struct package_head *test_head;
	int func_num;
	int t;
	bool isRight = true;

	//包体
	struct response_login func_0001;
	struct response_recharge func_1001;
	struct response_callsearch func_2001;
	struct response_historybill func_2002;
	struct response_billdetail func_2003;
	struct response_buycard func_3001;

	//获取套接字
	client_socket = ((tp_socket_info *)argv)->client_socket_fd ;

	//读取内容
	memset(buffer,0,MAX_SIZE);
	n_read = read(client_socket,buffer,sizeof(buffer));

	//前置标志和后置标志的判断
	head_get = buffer[0];
	//读取包头
	memcpy((void *)&bag_head,buffer+1,sizeof(struct package_head));
	//printf("前置标志 %c 设备ID %s 业务ID %s 包长度%d 交易流水号%s\n",head_get,bag_head.dev_id,bag_head.func_id,bag_head.packet_size,bag_head.trans_id);


	//判断前置标志 决定是否继续读取
	if (head_get != '~')
	{
		isRight = false;
	}
	
	//读取末尾标志
	back_get=buffer[n_read-1];
	
	//判断末尾标志
	if (back_get != '<')
	{
		isRight = false;
	}

	
	//判断功能号决定读取数据大小
	sscanf(bag_head.func_id,"%4d",&func_num);
	
	//如果是登陆包 就判断是否激活
	if (func_num == 1)
	{
		memcpy((void *)&func_0001,buffer+sizeof(struct package_head)+1,sizeof(struct response_login));
	}
	
	switch(func_num)
	{
	case 1:
		if (func_0001.dev_status != '0')
		{
			sscanf(stu_info->have_connect,"%d",&t);
			sprintf(stu_info->have_connect,"%d",t+1);
			
		}
		break;
		
	case 1001:
	case 2001:
	case 2002:
	case 2003:
	case 3001:
		
		pthread_mutex_lock(&mutex_shm);
		
		sscanf(stu_info->rec_bag,"%d",&t);
		sprintf(stu_info->rec_bag,"%d",t+1);
		
		pthread_mutex_unlock(&mutex_shm);
		
		break;
		
	default:
		break;
	}


	if (server_answer && isRight == true)
	{
	
		if (func_num != 1 )
		{
			//处理应答	
			for (t=1;t<=AnswerList.count();t++)
			{
				test_head = (struct package_head *)AnswerList[t];
				
				if (strcmp(test_head->func_id,bag_head.func_id) == 0)
				{
					sem_wait(&empty_list);
					
					pthread_mutex_lock(&mutex_list);
					
					AnswerList.delNode(t);
					
					pthread_mutex_unlock(&mutex_list);
					
					sem_post(&empty_list);
					
					pthread_mutex_lock(&mutex_shm);
					
					sscanf(stu_info->business_OK,"%d",&t);
					sprintf(stu_info->business_OK,"%d",t+1);
					
					pthread_mutex_unlock(&mutex_shm);
					
					return NULL;
				}
			}	
			isRight = false;
			
			
		}
			
	}


	if (isRight == false)
	{
		
		if (server_answer && func_num != 1)
		{
			pthread_mutex_lock(&mutex_shm);
			
			sscanf(stu_info->business_FAIL,"%d",&t);
			sprintf(stu_info->business_FAIL,"%d",t+1);
			
			pthread_mutex_unlock(&mutex_shm);
			
			//printf("错误包 前置标志 %c 后置标志 %c 设备ID %s 业务ID %s 包长度%d 交易流水号%s\n",head_get,back_get,bag_head.dev_id,bag_head.func_id,bag_head.packet_size,bag_head.trans_id);
		}
	}
	
}
void CMainDialog::OnClick( CControlUI* pSender)
{
	if (pSender->GetName() == TEXT ("btnExit")) {
		PostQuitMessage(0);
		return;
	}
	else if (pSender->GetName() == _T ("btnTip")) {
		CControlUI* pbtnTip = static_cast <CControlUI*> (m_pm.FindControl(_T ("btnTip")));
		if (pbtnTip) {
			pbtnTip->SetVisible(false);
		}

		CEditUI* peditSearch = static_cast <CEditUI*> (m_pm.FindControl(_T ("editSearch")));
		if (peditSearch != NULL) {
			peditSearch->SetFocus();
		}
	}

	else if (pSender->GetName() == _T ("lstDelButton")) {
		int iIndex = 0;
		CMyList* pParent = static_cast <CMyList*> (pSender->GetParent()->GetParent());
		if (pParent) {
			iIndex = pParent->GetItemIndex(pSender->GetParent());
		}
		CDuiString str;
		str.Format(_T ("您要删除 %d 项"), iIndex);
		if (IDNO == MessageBox (GetHWND (), str, NULL, MB_OK | MB_YESNO)) return;
		CMyList* pList = static_cast <CMyList*> (m_pm.FindControl(_T ("lstControl")));
		ASSERT(pList);
		if (pList) {
			pList->RemoveAt(iIndex);
			
			CControlUI* pItem = pList->GetItemAt(iIndex+5);
			if (pItem) {
				const RECT& rc = pItem->GetPos();
				SIZE sz = {0, rc.top};
				pList->SetScrollPos(sz);
			}
		}
	}
	else if (pSender->GetName() == _T ("btnAddComboItem")) {
		CComboUI* pcbx = static_cast <CComboUI*> (m_pm.FindControl(_T ("combo1")));
		assert (pcbx);
		if (pcbx) {
			CListLabelElementUI* pItem = new CListLabelElementUI ();
			pItem->SetText(_T ("{b}{i}新加项{/i}{/b}"));
			pcbx->Add(pItem);
		}

		AddComboboxItem();
		CComboUI* pcbx2 = static_cast <CComboUI*> (m_pm.FindControl(_T ("combo2")));
	}
	else if (pSender->GetName() == _T ("btnGoIe")) {
		CActiveXUI* pActiveXUI = static_cast<CActiveXUI*>(m_pm.FindControl(_T("ie")));
		if( pActiveXUI ) {
			IWebBrowser2* pWebBrowser = NULL;
			pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser);
			if( pWebBrowser != NULL ) {
				CEditUI* pEdit = static_cast <CEditUI*> (m_pm.FindControl(_T ("editIePath")));
				ASSERT (pEdit);
				CDuiString strIePath = _T ("www.baidu.com");
				if (pEdit) {
					strIePath = pEdit->GetText();
				}

				WCHAR szPath [1024] = {0};
#if defined(_UNICODE) || defined(UNICODE)
				lstrcpyW (szPath, strIePath);
#else
				::MultiByteToWideChar(CP_ACP, 0, strIePath, -1, szPath, 1023);
#endif
				pWebBrowser->Navigate(szPath,NULL,NULL,NULL,NULL);  
				pWebBrowser->Release();
			}
		}
	}
}
Beispiel #8
0
OSErr NetCDFStore::Capture(TModel* model, bool uncertain, map<string, int> *ncVarIDs, map<string, int> *ncDimIDs) {
    
	//if(!model->IsUncertain() && uncertain)	// this is checked on the outside...
		//return true;
	
    int c, i, j, n;
    //bool threeMovement;
	TLEList* thisLEList;
    CMyList* LESetsList;
    list<LERecP> tLEsContainer;
    NetCDFStore* netStore;
	char errStr[256];
	double halfLife;
	OSErr err = 0;
    
    netStore = new NetCDFStore(); // why do we need this?
    tLEsContainer = list<LERecP>();
    LESetsList = model->LESetsList;
	
 // Grab initial positions, and store them - may want to do this on the outside and pass in the tLEsContainer

    for (i = 0, n = LESetsList->GetItemCount(); i < n; i++) {
	    LESetsList -> GetListItem ((Ptr) &thisLEList, i);
		if(!thisLEList->IsActive()) continue;
		LETYPE type = thisLEList->GetLEType();
		halfLife = (*(dynamic_cast<TOLEList*>(thisLEList))).fSetSummary.halfLife;
					
        if(uncertain && type == UNCERTAINTY_LE /*&& model->IsUncertain()*/) {
			for (j = 0, c = thisLEList->numOfLEs; j < c; j++) {
				if(INDEXH(thisLEList->LEHandle, j).statusCode == OILSTAT_NOTRELEASED);
				else {
					try {
						(INDEXH(thisLEList->LEHandle, j)).leUnits = thisLEList->GetMassUnits();
						tLEsContainer.push_back(&(INDEXH(thisLEList->LEHandle, j)));
					}
					catch(...) {
						strcpy(errStr,"We are unable to allocate the memory required to perform this task.\n");
						//strcat(errStr,"The run will continue, notwithstanding.");
						printError(errStr);
						//cerr << "We are unable to allocate the memory required to perform this task.\n";
						//cerr << "The run will continue, notwithstanding.\n";
						//cerr << "(Timestep " << model->currentStep << ")\n";
						err = -1;
						return err;
					}
				}
			}
		}
        else if(!uncertain && type != UNCERTAINTY_LE) {
			for (j = 0, c = thisLEList->numOfLEs; j < c; j++) {
					if(INDEXH(thisLEList->LEHandle, j).statusCode == OILSTAT_NOTRELEASED);
					else {
						try {
							(INDEXH(thisLEList->LEHandle, j)).leUnits = thisLEList->GetMassUnits();
							tLEsContainer.push_back(&(INDEXH(thisLEList->LEHandle, j)));
						}
						catch(...) {
							strcpy(errStr,"We are unable to allocate the memory required to perform this task.\n");
							//strcat(errStr,"The run will continue, notwithstanding.");
							printError(errStr);
							//cerr << "We are unable to allocate the memory required to perform this task.\n";
							//cerr << "The run will continue, notwithstanding.\n";
							//cerr << "(Timestep " << model->currentStep << ")\n";
							err = -1;
							return err;
						}
					}
			}
		}
    }

    c = tLEsContainer.size();
    netStore->time = model->modelTime - model->GetStartTime();
    //netStore->time = model->modelTime;
	//netStore->time -= 2082816000L;
	
	float tFloat;
    netStore->pCount = c;
	
	try {	
		netStore->lon = new float[c];
		netStore->lat = new float[c];
		//if(threeMovement = model->ThereIsA3DMover(&tFloat))	// always output depth
			netStore->depth = new float[c];
		netStore->mass = new float[c];
		netStore->age = new long[c];
		//netStore->flag = new short[c];
		netStore->status_codes = new short[c];
		netStore->id = new long[c];	
	}
	catch(std::bad_alloc) {
		strcpy(errStr,"We are unable to allocate the memory required to perform this task.\n");
		//strcat(errStr,"The run will continue, notwithstanding.");
		printError(errStr);
		//cerr << "We are unable to allocate the memory required to perform this task.\n";
		//cerr << "The run will continue, notwithstanding.\n";
		//cerr << "(Timestep " << model->currentStep << ")\n";
		err = -1;
		return err;
	}

    list<LERecP>::iterator tIter = tLEsContainer.begin();

/*		enum { KILOGRAMS = 1, METRICTONS, SHORTTONS,
			GALLONS, BARRELS, CUBICMETERS, LES };		*/

    for(j = 0; j < c; j++) {
        LERecP tLE = *tIter;
        netStore->lon[j] = tLE->p.pLong;
		netStore->lon[j] /= 1000000;
        netStore->lat[j] = tLE->p.pLat;
		netStore->lat[j] /= 1000000;
        //if(threeMovement)
            netStore->depth[j] = tLE->z;
        netStore->mass[j] = GetLEMass(*tLE,halfLife);
		float tMass = netStore->mass[j];
		try {
			long tUnits = (*tLE).leUnits;
			if(tUnits == BARRELS || tUnits == GALLONS || tUnits == CUBICMETERS)
				netStore->mass[j] = VolumeMassToGrams(tMass, (*tLE).density, tUnits);
			else if(tUnits == KILOGRAMS || tUnits == METRICTONS || tUnits == SHORTTONS)
				netStore->mass[j] = ConvertMassToGrams(tMass, tUnits);
			else
				netStore->mass[j] = -tMass;
		}
		catch (...) {
			netStore->mass[j] = -tMass;
		}
        netStore->age[j] = tLE->ageInHrsWhenReleased*(3600);
		netStore->age[j] += model->modelTime - tLE->releaseTime;
		//netStore->flag[j] = 0;
		netStore->status_codes[j] = OILSTAT_INWATER;
		//if(threeMovement)
			//if(tLE->z > 0)
				//netStore->flag[j] += 16;

		switch(tLE->statusCode) {
			case OILSTAT_ONLAND:
				//netStore->flag[j] += 2;
				netStore->status_codes[j] = OILSTAT_ONLAND;
				break;
			case OILSTAT_OFFMAPS:
				//netStore->flag[j] += 4;
				netStore->status_codes[j] = OILSTAT_OFFMAPS;
				break;
			case OILSTAT_EVAPORATED:
				//netStore->flag[j] += 8;
				netStore->status_codes[j] = OILSTAT_EVAPORATED;
				break;
			default:
				break;
		}
		
        netStore->id[j] = tLE->leKey;
        tIter++;
		

    }

    tLEsContainer.clear();
	netStore->ncVarIDs = ncVarIDs;
	netStore->ncDimIDs = ncDimIDs;
   // netStore->Write(model, threeMovement, uncertain);
	err = netStore->Write(model, uncertain);
	if (err) return err;
	
	
	delete[] netStore->lat;
	delete[] netStore->lon;
	//if(threeMovement)
		delete[] netStore->depth;
	delete[] netStore->mass;
	//delete[] netStore->flag;
	delete[] netStore->status_codes;
	delete[] netStore->age;
	delete[] netStore->id;
    delete netStore;           
    return err;

}
void PushStrings(CMyList<std::string> &myStringList)
{
    myStringList.PushBack("test1");
    myStringList.PushBack("test2");
    myStringList.PushBack("test3");
}