当前位置: 首页>>代码示例>>C++>>正文


C++ deque::empty方法代码示例

本文整理汇总了C++中deque::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ deque::empty方法的具体用法?C++ deque::empty怎么用?C++ deque::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在deque的用法示例。


在下文中一共展示了deque::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processColorCube

/*! @note very important: color cubes of the children must already exist, otherwise there will be a segmentation fault  */
void ColorCubeGenerator::processColorCube(FrameContext& context, Node * node, deque<Node*>& children) {

	const Geometry::Box box = node->getWorldBB();
	ColorCube cc;

	// 1. case: current node's color cube should be processed by drawing Geometry < see processColorCubes(...) >
	if (children.empty()) {
		context.getRenderingContext().pushAndSetLighting(Rendering::LightingParameters(true));
		context.getRenderingContext().applyChanges();

		// render the six sides
		context.getRenderingContext().pushAndSetFBO(fbo.get());
		for (uint8_t _side = 0; _side < 6; ++_side) { // determine the color for each of the 6 faces
			const Geometry::side_t side = static_cast<Geometry::side_t> (_side);
			if (!prepareCamera(context, box, side))
				continue;

			context.getRenderingContext().clearScreen(Util::Color4f(0.0f, 0.0f, 0.0f, 0.0f));
			context.displayNode(node, USE_WORLD_MATRIX);
		}
		context.getRenderingContext().popFBO();
		colorTexture->downloadGLTexture(context.getRenderingContext());

		//////////// debug
// 		static uint32_t counter=0;
// 		stringstream ss;
// 		ss << "screens/colorcube_" << counter++ << ".png";
// 		Util::FileName filename(ss.str());
// 		Rendering::Serialization::saveTexture(context.getRenderingContext(), colorTexture.get(), filename);
		//////////// end debug



		// determine the color for each of the 6 faces
		for (uint8_t _side = 0; _side < 6; ++_side) {
			const Geometry::side_t side = static_cast<Geometry::side_t> (_side);
			if (prepareCamera(context, box, side)){
				const Color4ub c = calculateColor(colorTexture.get(), camera->getViewport()); //calculate color from texture
				cc.colors[static_cast<uint8_t> (side)] = c;
			} else {
				cc.colors[static_cast<uint8_t> (side)] = Color4ub(0, 0, 0, 0);
			}
		}

		context.getRenderingContext().popLighting();
	}
	else{
		context.getRenderingContext().pushAndSetFBO(fbo.get()); // enable the fbo

		// 2. case:  the node is not a closed GroupNode  (inner node)
		for (uint8_t _side = 0; _side < 6; ++_side) { // for each of the six faces
			Geometry::side_t side = static_cast<Geometry::side_t> (_side);
			if (!prepareCamera(context, box, side))
				continue;

			context.getRenderingContext().clearScreen(Util::Color4f(0.0f, 0.0f, 0.0f, 0.0f));
			context.getRenderingContext().pushAndSetMatrix_modelToCamera( context.getRenderingContext().getMatrix_worldToCamera() );


			// draw faces using blending
			context.getRenderingContext().pushAndSetBlending(Rendering::BlendingParameters(Rendering::BlendingParameters::ONE, Rendering::BlendingParameters::ONE_MINUS_SRC_ALPHA));
			context.getRenderingContext().pushAndSetCullFace(Rendering::CullFaceParameters(Rendering::CullFaceParameters::CULL_BACK));
			context.getRenderingContext().pushAndSetDepthBuffer(Rendering::DepthBufferParameters(true, false, Rendering::Comparison::LESS));
			context.getRenderingContext().pushAndSetLighting(Rendering::LightingParameters(false));
			context.getRenderingContext().applyChanges();

			distanceQueue_t nodes(side); // distance queue used for sorting the children with color cubes

			// sort (back-to-front order) the children according to distance of current side to the camera
			for(const auto & child : children) {
				nodes.push(child);
			}

			// draw the faces in back-to-front order
			while (!nodes.empty()) {
				Node* child = nodes.top();
				nodes.pop();
				const ColorCube & childsColorCube = ColorCube::getColorCube(child);
				//cerr << "before drawing colored box " << endl;
				childsColorCube.drawColoredBox(context, child->getWorldBB());
				//cerr << "after drawing colored box" << endl;
			}

			context.getRenderingContext().popLighting();
			context.getRenderingContext().popDepthBuffer();
			context.getRenderingContext().popCullFace();
			context.getRenderingContext().popBlending();
			context.getRenderingContext().popMatrix_modelToCamera();
		}
		context.getRenderingContext().popFBO();
		colorTexture->downloadGLTexture(context.getRenderingContext());
		// determine the color for each of the 6 faces
		for (uint8_t _side = 0; _side < 6; ++_side) {
			Geometry::side_t side = static_cast<Geometry::side_t> (_side);
			if (!prepareCamera(context, box, side))
				continue;
			//calculate color from texture
			cc.colors[static_cast<uint8_t> (side)] = calculateColor(colorTexture.get(), camera->getViewport());
		}
//.........这里部分代码省略.........
开发者ID:MeisterYeti,项目名称:MinSG,代码行数:101,代码来源:ColorCubeGenerator.cpp

示例2: waypointsFlightLoop

/*
 *	flightLoop
 *		1) Initialise copter systems
 *		2) Wait for user allowance to fly.
 *		3) Read in list of waypoints
 *		4) Fly to first waypoint, wait, fly to next, etc..
 *		5) If the end is reached, stop.
 *		
 *		The user may stop the flight at any time. It will continue if the user resumes. At any
 *		point, the user may stop the current flight path and change the waypoint configuration. Upon
 *		resuming flight, the copter will read in the new list of waypoints and start at the
 *		beginning.
 */
void waypointsFlightLoop(FlightBoard &fb, GPS &gps, IMU &imu, Buzzer &buzzer, Logger &logs, deque<coord> &waypoints_list) {	
	cout << "\033[1;32m[WAYPTS]\033[0m Waypoints thread initiated, travelling to the following waypoints:" << endl;
	
	char str_buf[BUFSIZ];
	bool useimu = false;	// Manual setting for debug
	double yaw = 0;	
	GPS_Data gps_data;
	
	for(size_t i = 0; i != waypoints_list.size(); i++) {
		cout << '         ' << i+1 << ": (" << waypoints_list[i].lat << ", " << waypoints_list[i].lon << ")" << endl;
	}
	
	state = 6;
	while ( !gpio::isAutoMode() ) usleep(1000000);
	
	/*if (!useimu) {
		buzzer.playBuzzer(0.25, 100, 100);
		state = 5;
		yaw = inferBearing(&fb, &gps, &logs);
	}*/
	
	coord		currentCoord = {-1, -1};
	double		distanceToNextWaypoint;
	double		bearingToNextWaypoint;
	FB_Data		course = {0, 0, 0, 0};
	int			pastState = -1;

	try {	// Check for any errors, and stop the copter.
		while(!exitProgram) {
			gps.getGPS_Data(&gps_data);
			currentCoord.lat = gps_data.latitude;
			currentCoord.lon = gps_data.longitude;
			
			if (wp_it == waypoints_list.size()) {
				wp_it = 0;
				userState = 0;
			}

			distanceToNextWaypoint = calculate_distance(currentCoord, waypoints_list[wp_it]);
			bearingToNextWaypoint = calculate_bearing(currentCoord, waypoints_list[wp_it]);
			//if (useimu) yaw = getYaw(&imu);
			yaw = gps_data.heading;			

			/* State 4: Manual mode. */
			if (!gpio::isAutoMode()) {
				state = 4;
				wp_it = 0;
				exitProgram = true;
			/* State 0: All stop */
			} else if (waypoints_list.empty() || userState == 0 ) {
				state = 11;
				wp_it = 0;
				exitProgram = true;
			/* State 3: Error. */
			} else if (state == 3 || !checkInPerth(&currentCoord)) {
				state = 3;
				exitProgram = true;
			/* State 2: At waypoint. */
			} else if (distanceToNextWaypoint < WAYPOINT_RADIUS) {
				state = 2;
			/* State 1: Travelling to waypoint. */
			} else {
				state = 1;
			}
			
			/* Only give output if the state changes. Less spamey.. */
			if (pastState != state) {
				switch (state) {
					case 0:
						cout << "\033[1;32m[WAYPTS]\033[0m All stop." << endl;
						break;
					case 1:
						cout << "\033[1;32m[WAYPTS]\033[0m Travelling to waypoint " << wp_it << ", at (" << waypoints_list[wp_it].lat << "," << waypoints_list[wp_it].lon << ")" << endl;
						break;
					case 2:
						cout << "\033[1;32m[WAYPTS]\033[0m At waypoint" << wp_it << "." << endl;
						break;
					case 3:
						cout << "\033[31m[WAYPTS]\033[0m Error reading GPS." << endl;
					case 4:
						cout << "\033[31m[WAYPTS]\033[0m Manual mode engaged." << endl;
					break;
				}
				cout << "\033[1;33m[WAYPTS]\033[0m In state "		<< state << "."	<< endl;
				cout << "\033[1;33m[WAYPTS]\033[0m Facing " << setprecision(6) << yaw << ", at coordinates (" << currentCoord.lat << ", " <<	currentCoord.lon << ")" << endl;

				cout << "\033[1;33m[WAYPTS]\033[0m The next waypoint is at (" << setprecision(6) << waypoints_list[wp_it].lat << ", " << waypoints_list[wp_it].lon << ")"	<< endl;
//.........这里部分代码省略.........
开发者ID:picopter,项目名称:picopter,代码行数:101,代码来源:waypoints.cpp

示例3: pop

void pop(int x) {
	while (!dq.empty() && dq.front() <= x)
		dq.pop_front();
}
开发者ID:thucdx,项目名称:algorithm-solution,代码行数:4,代码来源:KMIN.cpp

示例4: main


//.........这里部分代码省略.........
			if(str[i][j+lc]!=str[sl[v].idx][sl[v].os+lc]){
			    break;
			}
			lc++;
		    }
		    lcp[i][j]=lc;
		}
	    }
	}

	for(i=0;i<n;i++){
	    lmap[i]=0;
	}
	for(i=0;i<u;i++){
	    hemap[i]=0;
	}
	he.clear();
	de.clear();
	v=0;
	flag=0;

	out.clear();
	ma=0;

	for(i=0;i<u;i++){
	    if(lmap[sl[i].idx]==0){
		v++;
	    }
	    lmap[sl[i].idx]++;
	    if(i>0){
		he.push_back(i);
		push_heap(he.begin(),he.end(),cmpc);
	    }
	    de.push_back(i);

	    while(!de.empty()){
		if(lmap[sl[de.front()].idx]>1){
		    hemap[de.front()]=1;
		    lmap[sl[de.front()].idx]--;
		    de.pop_front();
		}else if(lmap[sl[de.front()].idx]==1 && (v-1)*2>n && v>2){
		    v--;
		    hemap[de.front()]=1;
		    lmap[sl[de.front()].idx]--;
		    de.pop_front();
		}else{
		    break;
		}
	    }
	    hemap[de.front()]=1;

	    while(!he.empty()){
		if(hemap[he.front()]==1){
		    pop_heap(he.begin(),he.end(),cmpc);
		    he.pop_back();
		}else{
		    break;
		}
	    }

	    if(v*2>n && v>=2){
		cn=sl[he.front()];
		lim=lcp[cn.idx][cn.os];
		if(lim>ma){
		    out.clear();
		    out.push_back(cn);
		    flag=1;
		    ma=lim;
		}else if(lim==ma){
		    if(flag==0){
		        out.push_back(cn);
		        flag=1;
		    }
		}else{
		    flag=0;
		}
	    }else{
		flag=0;
	    }
	}

	/*for(i=0;i<u;i++){
	    printf("  %d %s  %d\n",sl[i].idx,&str[sl[i].idx][sl[i].os],lcp[sl[i].idx][sl[i].os]);
	}*/

	if(ma==0){
	    printf("?\n");
	}else{
	    u=out.size();
	    for(i=0;i<u;i++){
		c=str[out[i].idx][out[i].os+ma];
		str[out[i].idx][out[i].os+ma]=0;
		printf("%s\n",&str[out[i].idx][out[i].os]);
		str[out[i].idx][out[i].os+ma]=c;
	    }
	}
    }

    return 0;
}
开发者ID:fredwhite,项目名称:Backup,代码行数:101,代码来源:11107.cpp

示例5: empty

 bool empty() {
     return q.empty();
 }
开发者ID:emmettwu,项目名称:emmettLeetCode,代码行数:3,代码来源:implement.cpp

示例6: gen_moves

void AI::gen_moves( const backgammon_state& s, deque<backgammon_state>& r )
{    
  //The die value we're currently using
  int dieVal = 0;
  
  //How many points to loop through to generate moves
  int LSVal = 0;
  int LEVal = 26;
  
  //Generation of half-state flags. True = need to use this die.
  bool use_0 = true;
  bool use_1 = true;
  
  //For jumping forward spaces in times of bearing off and needing to
  int advance = 0;
  
  //The current state we're using to generate moves from
  backgammon_state curr_state = s;
  
  //Keep going until we generate all the states necessary
  while ( true )
  {
    cout << "\n---------------------------------------------------" << endl;
    
    if ( curr_state.m_dice.size() == 2 )
    {
      cout << "-Singles mode-" << endl;

      //If we need to generate half states using 0 or 1
      if ( (use_0 == true) || (use_1 == true) )
      {
        //generate half-states using die 0
        if ( use_0 == true )
        {
          cout << "  Generation using only 0" << endl;
          dieVal = curr_state.m_dice[0];
          use_0 = false;
          curr_state.m_dice_used[0] = true;
          //curr_state.m_dice_used[1] = false;
        }
        
        //generate half-states using die 1
        else
        {
          //Means we tried to generated using the smaller die first and couldn't
          //Which means we may have a situation in which we need to use 
          //only the largest die
          //if ( r.empty() && (largest_only == false) )
          //{
            //largest_only = true;
          //}
          
          cout << "  Generation using only 1" << endl;
          dieVal = curr_state.m_dice[1];
          use_1 = false;
          curr_state.m_dice_used[0] = false;
          curr_state.m_dice_used[1] = true;
        }
        
      } //End if choosing which die to use first
      
      //use_0 == false and use_1 == false, so we've used both of them
      //but were unable to generate any moves, sucks for us
      else if ( r.empty() )
      {
        cout << "  tried to gen full states, but failed" << endl;
        
        if ( !curr_state.m_move.empty() )
        {
          cout << "falling back to previous state because it still has moves" << endl;
          r.push_back( curr_state );
        }
        
        return;
      }
      
      //Or if we've generated half-states already, and we need to now
      //generate full-states from the half-states
      //else if ( !r.empty() && continue_generation( r.front() ) )
      else if ( continue_generation( r.front() ) )
      {
        //Turn the first half-state into a full-state
        
        //if (used_both)
        //  r.pop_front();
          
        curr_state = r.front();
        r.pop_front();
        
        //check to see if we can only use 1 die from this state, and make it
        //be the larger of the two die
        // if we were able to generate a state, we need to make sure thatit's using
        //   either both die or just the higher one
        
        //If this state requires generation using die 0 to become full
        if ( curr_state.m_dice_used[0] == false )
        {
          cout << "  Generation using 0, already did 1" << endl;
          dieVal = curr_state.m_dice[0];
          curr_state.m_dice_used[0] = true;
//.........这里部分代码省略.........
开发者ID:gsteelman,项目名称:mst,代码行数:101,代码来源:AI.cpp

示例7: print_ls

void print_ls(bool flags[], deque<string> paths, string mainPath){
    if(paths.empty()){
        return;
    }
    wcout.imbue(locale(""));
    int cnt = 0;
    struct stat buf;
    string tmp = mainPath;
    string ftmp;
    DIR *dirp = opendir(tmp.c_str());
    if(dirp == NULL){
        perror("opendir");
        exit(0);
    }
    dirent *direntp;
    vector<string> fileObj;
    unordered_map<string, string> filehash;
    if(flags[2]){
        cout << tmp  << ":" << endl;
    }
    errno = 0;
    direntp = readdir(dirp);
    if(errno !=  0){
            perror("readdir");
            exit(0);
        }
    while(direntp){
        if(direntp == NULL){
            perror("readdir");
            exit(0);
        }
        ftmp = direntp->d_name;
        string tmpPath = mainPath;
        tmpPath.append("/");
        tmpPath.append(ftmp);
        if(lstat(tmpPath.c_str(), &buf) == -1){
            perror("lstat");
            exit(0);
        }
        if(flags[0]){
            fileObj.push_back(direntp->d_name);
            filehash[direntp->d_name] = tmpPath;
            cnt++;
        }
        else if(!flags[0] && ftmp.at(0) != '.'){
            fileObj.push_back(direntp->d_name);
            filehash[direntp->d_name] = tmpPath;
            cnt++;
        }
        if(S_ISDIR(buf.st_mode) && ftmp != "." && ftmp != ".."
            && flags[2]){
            if(flags[0]){
                paths.push_back(tmpPath);
            }
            else if(!flags[0] && ftmp.at(0) != '.'){
                paths.push_back(tmpPath);
            }
        }
        errno = 0;
        direntp = readdir(dirp);
        if(errno != 0){
            perror("readdir");
            exit(0);
        }
    }
    total_block_size += getBlk(filehash, fileObj);
    if(flags[1]){
        cout << "total " << total_block_size / 2 << endl;
    }
    total_block_size = 0;
    sort(fileObj.begin(), fileObj.end(), locale("en_US.UTF-8"));
    //int l = get_total_len(fileObj);
    //cout << endl << l << endl;
    unsigned int count = 0;
    unsigned int c_count = 0;
        for(unsigned int i = 0; i < fileObj.size(); i++){
            if(flags[1]){
                //total_block_size += getBlk(filehash, fileObj);
                cout << getInfo(filehash[fileObj.at(i)]);
                if(isDir(filehash[fileObj.at(i)])){
                    if(isHide(fileObj.at(i))){
                        cout << "\033[34;100m";
                        cout << fileObj.at(i);
                        cout << "\033[0m";
                        cout << endl;
                    }
                    else{
                        cout << "\033[34m" << fileObj.at(i)
                            << "\033[0m" << endl;
                    }
                }
                else if(isEx(filehash[fileObj.at(i)])){
                    if(isHide(fileObj.at(i))){
                        cout << "\033[32;100m";
                        cout << fileObj.at(i);
                        cout << "\033[0m";
                        cout << endl;
                    }
                    else{
                        cout << "\033[32m" << fileObj.at(i)
//.........这里部分代码省略.........
开发者ID:aorti017,项目名称:rshell,代码行数:101,代码来源:ls.cpp

示例8: readSingleAssociation

void readSingleAssociation(ifstream &fin, deque<dtdclass *>&d_class){
   
    bool associationFinish=false;
    bool firstclass = true;
    string base_name, to_name;/*save the name and two class name of the association*/
    int baseLevel, toLevel;/*to save the level of both class of the association*/
    deque<attribute * > baseQualification, toQualification; /*save the list of qualification*/
    attribute basequali, toquali;/*save the name of the qualification*/
    associate basAsso, toAsso;
    bool haveBasequali = false;/*check if there have qualification in first class*/
    bool haveToquali = false;/*check if there have qualification in second class*/
    bool haveLink=false;/*check the association have link or not*/
    char filedetail[256];/*record the each line of file from the compiler*/
    char linker_name[64];
    string Slinker_name;
    char * tempChar;
    string temp;
    deque<dtdclass*>::iterator first;/*recond the first position of the deque*/
    deque<dtdclass*>::iterator last;/*recond the last position of the deque*/
    do{
        fin.getline(filedetail,255);
        if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
        tempChar = strtok(filedetail,"<>");//cut front of "<"
        temp = tempChar;
        if(temp=="/association"){//check if is end of one association
            associationFinish=true;//is control while loop
        }
        else {
            tempChar = strtok(NULL, ">");//get detail between < >
            temp = tempChar;
            if(temp=="/association"){//check if is end of one association
                associationFinish=true;//is control while loop
            }
            else if(temp == "nameOfAssociation"){
                tempChar = strtok(NULL,"<>");//get the name of the association
                strcpy(basAsso.ass_name, tempChar);
                strcpy(toAsso.ass_name , tempChar);
            }
            else if(temp =="class_name"){/*find the class name of the association of the class*/
                tempChar = strtok(NULL, "<>");/*get the class name*/
                if(firstclass ==true){
                    /*call function to read detail of the association of the first class*/
                    readAssoClass(fin, basAsso, toAsso, baseLevel,haveToquali,toQualification);
                    
                    firstclass = !firstclass;
                    strcpy(toAsso.tclass_name, tempChar);/*record the relation class*/
                    base_name = tempChar;
                    Slinker_name = base_name;/*record the name of first class*/
                    }
                else{
                    /*call function to read detail of the association of the second class*/
                    readAssoClass(fin, toAsso, basAsso, toLevel,haveBasequali, baseQualification );
                    
                    strcpy(basAsso.tclass_name , tempChar);/*record the relation class name */
                    to_name = tempChar;
                    Slinker_name = Slinker_name + to_name;/*record the name of the second class*/
                }
            }
            else if(temp =="Link"){
                fin.getline(filedetail,255);
                if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
                tempChar = strtok(filedetail,"<>");//cut front of "<"
                tempChar = strtok(NULL,"<>");/*get the detail in "<>" */
                temp = tempChar;
                if(temp=="/association"|| temp =="/Link"){//check if is end of one association
                    associationFinish=true;//is control while loop
                }
                else if(temp == "link_attribute"){
                    fin.getline(filedetail, 255);
                    if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
                    tempChar = strtok(filedetail,"<>");//cut front of "<"
                    tempChar = strtok(NULL, ">");//get detail between < >
                    tempChar = strtok(NULL, "<>");
                    temp = tempChar;
                    if(strcmp(toAsso.tclass_name, basAsso.tclass_name)!=0){//the two class name is not the same
                        haveLink = true;/*record the two class have link class*/
                        if(temp !="<"){
                            dtdclass * linkClass = new dtdclass();/*creast a linker class*/
                            linkClass->setname(Slinker_name);
                            linkClass->setlevel(1);
                            int tempMulti;
                            tempMulti = basAsso.to_multi;/*change the multi link of the association*/
                            basAsso.to_multi =1;
                            linkClass->setassociation(basAsso);/*set the association of the link class*/
                            /*get back the original multi link number of the association*/
                            basAsso.to_multi = tempMulti;
                            tempMulti = toAsso.to_multi;
                            toAsso.to_multi = 1;
                            linkClass->setassociation(toAsso);
                            toAsso.to_multi = tempMulti;

                            readLinkAttribute(tempChar, linkClass, fin);/*call the read attribute name*/
                            strcpy(linker_name, Slinker_name.c_str());
                            strcpy(basAsso.tclass_name, linker_name);/*change the relation class name*/
                            basAsso.base_multi =1;
                            strcpy(toAsso.tclass_name, linker_name);
                            toAsso.base_multi =1;
                            d_class.push_back(linkClass);//add link class into deque
                        }
                    }
//.........这里部分代码省略.........
开发者ID:vitawebsitedesign,项目名称:321,代码行数:101,代码来源:main.cpp

示例9: readAssoQua

bool readAssoQua(ifstream & fin, deque<dtdclass *>&d_class, char * name, associate & basAsso, associate& toAsso){
    char filedetail[256];/*record the each line of file from the compiler*/
    char * tempChar;
    string temp, qualiClass;
    bool finishQualiAssoClass = false;
    bool haveQualification = false;
    bool haveAssociation = false;/*check the association have detail or not*/
    attribute tempattribute;
    deque<attribute *> tempQualification;
    
    deque<dtdclass*>::iterator first;/*recond the first position of the deque*/
    deque<dtdclass*>::iterator last;/*recond the last position of the deque*/
    do{
        fin.getline(filedetail,255);
        if(strcmp(filedetail, "")==0){continue;}/*if the line is empty, continue*/
        tempChar = strtok(filedetail,"<>");//cut front of "<"
        tempChar = strtok(NULL, "<>");/*get the detail between <> */
        temp = tempChar;
        if(temp=="/association_class" || temp =="/Link"){//check if is end of one association class
            finishQualiAssoClass=true;//is control while loop
        }
        else if(temp == "nameOfAssociationClass"){
            haveAssociation=true;
            tempChar = strtok(NULL, "<>");
            strcpy(name, tempChar);
            qualiClass = tempChar;
            if(!d_class.empty()){//check the deque is not empty
                    first = d_class.begin();//get the begin of the deque
                    last = d_class.end();//get the end of the deque
                    for (deque<dtdclass *>::iterator i=first; i !=last;i++){
                        if(qualiClass ==(*i)->getname()){//add association into class
                            (*i)->setlevel(1);
                            int tempMulti;
                            tempMulti = basAsso.to_multi;
                            basAsso.to_multi = 1;/*change the multi link of the association*/
                            (*i)->setassociation(basAsso);//add association
                            basAsso.to_multi = tempMulti;;/*get back the original multi link number of the association*/
                            tempMulti = toAsso.to_multi;
                            toAsso.to_multi =1;/*change the multi link of the association*/
                            (*i)->setassociation(toAsso);//add association
                            toAsso.to_multi = tempMulti;/*get back the original multi link number of the association*/
                            if(haveQualification == true){
                                if(!tempQualification.empty()){/*get the qualification attribute from the deque and add it into the class*/
                                    deque<attribute *>::iterator firstAttribute = tempQualification.begin();
                                    deque<attribute *>::iterator lastAttribute =  tempQualification.end();
                                    for(deque<attribute * >::iterator attributeI = firstAttribute; attributeI != lastAttribute; attributeI++){
                                        strcpy(tempattribute.att_name, (*attributeI)->att_name);
                                        tempattribute.isId = (*attributeI)->isId;
                                        tempattribute.ismulti= (*attributeI)->ismulti;
                                        (*i)->setattribute(tempattribute);//add the attribute into the class
                                    }
                                }
                            }/*finish add all qualification into the class*/
                        }
                    }
                }
        }
        else if(temp == "qualification"){
            haveAssociation = true;
            tempChar = strtok(NULL, "/<");
            temp = tempChar;
            if(temp !="<"){
                attribute * tempAttri = new attribute;
                strcpy(tempAttri->att_name,tempChar);
                tempAttri->isId = true;
                tempAttri->ismulti = false;
                haveQualification =true;
                tempQualification.push_back(tempAttri);
            }
        }
        
    }while(finishQualiAssoClass !=true);
    return haveAssociation;
}
开发者ID:vitawebsitedesign,项目名称:321,代码行数:74,代码来源:main.cpp

示例10: handleClientThread

unsigned long handleClientThread(void*)
{
    int pth_id=MThread::GetCurrentThreadID();

    MSocket *pclient=NULL;
    while(true){

	MutexClient.Lock();
	if(!clientDeque.empty()){
	    pclient=clientDeque.front();
	    clientDeque.pop_front();
	    MutexClient.Unlock();

	    cout<<"In thread: "<<pth_id<<endl;
	    struct timeval testtime;
	    testtime.tv_sec=400;
	    testtime.tv_usec=0;
	    if(pclient->Setsockopt(SOL_SOCKET,SO_RCVTIMEO,
				   (char*)&testtime,sizeof(testtime))==-1)
	    {
		pclient->Shutdown(2);
		pclient->Close();
		delete pclient;
	    }
	    //pclient->SetNonblock(false);//block, return 0
	    int rt;
	    int len=0;
	    cout<<"now begin Recv..."<<endl;

	    Data *mydata=new Data;
	    rt=pclient->SafeRecv(mydata,sizeof(Data));
	    if(rt==-1){//if rt!=-1,then rt==sizeof(Data)
		cout<<"recv error"<<endl;
		pclient->Shutdown(2);
		pclient->Close();
		delete pclient;
		pclient=NULL;
		break;
	    }

	    cout<<"Received data: "<<endl;

	    //´¦ÀíÊý¾Ý
	    
	    cout<<"key: "<<mydata->key<<endl
		<<"value: "<<mydata->value<<endl;

	    char result[]="success";
	    len=strlen(result);
	    rt=pclient->SafeSend(&len,sizeof(int));
	    if(rt==-1){
		cout<<"send error"<<endl;
		pclient->Shutdown(2);
		pclient->Close();
		delete pclient;
		pclient=NULL;
		break;
	    }
	    
	    rt=pclient->SafeSend(result,len);
	    if(rt==-1){
		cout<<"send error"<<endl;
		pclient->Shutdown(2);
		pclient->Close();
		delete pclient;
		pclient=NULL;
		break;
	    }
	    cout<<"send back sucess"<<endl;
	    cout<<"doing sth ..."<<endl;
	    MThread::Sleep(1000);
	    
	}else
	{
	    MutexClient.Unlock();
	    cout<<"deque empty,now sleep(100)..."<<endl;
	    MThread::Sleep(100);
	}
    }
    return 1;

}
开发者ID:IthacaDream,项目名称:Networking,代码行数:82,代码来源:server.cpp

示例11: init

void init() {
    while(!order.empty()) order.pop_front();
    while(!moon.empty()) moon.pop_front();
}
开发者ID:xuziye0327,项目名称:acm,代码行数:4,代码来源:main.cpp

示例12: enqueue

inline void enqueue(ll x) {
	q.push(x);
	while(!dq.empty() && x < dq.back()) dq.pop_back();
	dq.push_back(x);
}
开发者ID:yancouto,项目名称:maratona-sua-mae,代码行数:5,代码来源:372C.cpp

示例13: u

bool iCub::optimization::minVolumeEllipsoid(const deque<Vector> &points,
                                            const double tol,
                                            Matrix &A, Vector &c)
{
    // This code is a C++ version of the MATLAB script written by:
    // Nima Moshtagh ([email protected]), University of Pennsylvania
    //
    // It makes use of the Khachiyan algorithm and aims at minimizing
    // iteratively the following problem:
    //
    // min log(det(A))
    // s.t. (points[i]-c)'*A*(points[i]-c)<=1

    if (points.empty())
        return false;

    // initialization
    int d=points.front().length();
    int N=(int)points.size();
    Vector u(N,1.0/N);
    Matrix U(N,N); U.diagonal(u);
    Matrix Q(d+1,N);
    for (int row=0; row<Q.rows(); row++)
        for (int col=0; col<Q.cols(); col++)
            Q(row,col)=points[col][row];
    for (int col=0; col<Q.cols(); col++)
        Q(Q.rows()-1,col)=1.0;
    Matrix Qt=Q.transposed();

    // run the Khachiyan algorithm
    Matrix M;
    while (true)
    {
        M=Qt*pinv(Q*U*Qt)*Q;
        int j=0; double max=M(j,j);
        for (int row=1; row<M.rows(); row++)
        {
            if (M(row,row)>max)
            {
                max=M(row,row);
                j=row;
            }
        }
        double step_size=(max-d-1.0)/((d+1.0)*(max-1.0));
        Vector new_u=(1.0-step_size)*u;
        new_u[j]+=step_size;
        if (norm(new_u-u)<tol)
            break;
        u=new_u;
        U.diagonal(u);
    }

    // compute the ellipsoid parameters
    Matrix P=Q.removeRows(Q.rows()-1,1);
    c=P*u;
    Matrix C(c.length(),c.length());
    for (int col=0; col<C.cols(); col++)
        C.setCol(col,c[col]*c);
    A=(1.0/d)*pinv(P*U*P.transposed()-C);

    return true;
}
开发者ID:AbuMussabRaja,项目名称:icub-main,代码行数:62,代码来源:algorithms.cpp

示例14: push

void push(deque<pair<int, int>> &Q, pair<int, int> v) {
    while (!Q.empty() && Q.back() > v) {
        Q.pop_back();
    }
    Q.push_back(v);
}
开发者ID:roosephu,项目名称:project-euler,代码行数:6,代码来源:328.cpp

示例15: lexer

//===========================================================================
// Description: Function pops the top  element of an stl queue. An FSM with
// 8 states is implimented through the form of a looped switch. First
// character is analyzed, and states  are transitioned accordingly. In the
// case of a compound opperator, the second character is looked at. If it
// matches /the pattern of those opperators, a second character is popped
// and the opperator is returned as two characters. This loop repeats until
// the stack is empty.
//====== lexer() ============================================================
string lexer(deque<char> & queue)
{
    STATES state = STARTING;
    string tempIdentifier, tempInteger, tempReal;
    char token, tokenNext;
    while(!queue.empty())
    {
        token = queue.front();
        queue.pop_front();
        if(!queue.empty())
            tokenNext = queue.front();
        do {
            switch(state)
            {
            /*
            STARTING STATE
            */
            case STARTING:
                //First character of identifier must be alphabetic
                if(isalpha(token) || token=='_')
                {
                    tempIdentifier+=token;
                    state = IDENTIFIER;
                }
                else if(isdigit(token))
                {
                    tempInteger+=token;
                    state = INTEGER;
                }
                else if(token =='.') state = ERROR;
                else if(token == ' ') state = STARTING;
                else if(token == '$' && queue.empty()) return "$";
                else if(token == '(') {
                    state = STARTING;
                    return "(";
                }
                else if(token == ')') {
                    state = STARTING;
                    return ")";
                }
                else if(token == ',') {
                    state = STARTING;
                    return ",";
                }
                else if(token == '{') {
                    state = STARTING;
                    return "{";
                }
                else if(token == '}') {
                    state = STARTING;
                    return "}";
                }
                else if(token == ';') {
                    state = STARTING;
                    return ";";
                }
                else if(token == '+') {
                    state = STARTING;
                    return "+";
                }
                else if(token == '*') {
                    state = STARTING;
                    return "*";
                }
                else if(token == '-') {
                    state = STARTING;
                    return "-";
                }
                else if(token == '=') {
                    state = STARTING;
                    return "=";
                }
                else if(token == '$')
                {
                    if(tokenNext == '$')
                    {
                        queue.pop_front();
                        return "$$";
                    }
                    else
                        return "$";
                    state = STARTING;
                }
                else if(token == '<')
                {
                    state = STARTING;
                    if(tokenNext == '=')
                    {
                        queue.pop_front();
                        return "<=";
                    }
//.........这里部分代码省略.........
开发者ID:Daniel3832,项目名称:CPSC323,代码行数:101,代码来源:CPSC323_Project_3_Source_Daniel_Jordan.cpp


注:本文中的deque::empty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。