• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PUSH函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PUSH函数的典型用法代码示例。如果您正苦于以下问题:C++ PUSH函数的具体用法?C++ PUSH怎么用?C++ PUSH使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: TContactViewPreferences

void CTestMachine::StepFindViewsL()
	{
	const TContactViewPreferences viewPrefs = TContactViewPreferences(EUnSortedAtEnd | EContactsOnly);
	_LIT(KMansell, 	"Mansell");	

	BEGIN_ASYNC_TEST
		
		/////////////////////////////////////////
		//Actions:	Create a local view with reverse sort plugin
		TESTTRAP(iLocalView = CContactLocalView::NewL(*this, *iDb, iSurnNameSortOrder, viewPrefs, KReverseSortPlugin));
	WAIT_EVENT(1)

		//Expected Result:	Check the order of entries in the view - it must be reverse.
		test.Printf(_L("Local View created:\n"));
		CheckViewOrderL(iLocalView);
		test.Printf(_L("\n\n"));

		/////////////////////////////////////////
		//Actions:	Create a remote view with reverse sort plugin
		TESTTRAP(iRemoteViewReverse = CContactRemoteView::NewL(*this, *iDb, iSurnNameSortOrder, viewPrefs, KReverseSortPlugin));
	WAIT_EVENT(2)

		//Expected Result:	Check the order of entries in the view - it must be reverse.
		test.Printf(_L("Remote View created:\n"));
		CheckViewOrderL(iRemoteViewReverse);
		test.Printf(_L("\n\n"));

		/////////////////////////////////////////
		//Actions:	Create a remote view with default sorting behaviour
		TESTTRAP(iRemoteViewForward = CContactRemoteView::NewL(*this, *iDb, iSurnNameSortOrder, viewPrefs));
	WAIT_EVENT(3)

		//Expected Result:	Check the order of entries in the view - it must be forward
		test.Printf(_L("Remote View created:\n"));
		CheckViewOrderL(iRemoteViewForward, EFalse, EFalse); //do not Print, forward order
		test.Printf(_L("\n\n"));

		/////////////////////////////////////////
		//Actions:	Create a Find view on top of the local view, using "Ma" search string 
		iFindDesArray =new(ELeave)CPtrC16Array(1);
		_LIT(KMa,"Ma");
		iFindDesArray->AppendL(TPtrC(KMa));

		iLocalFindView= CContactFindView::NewL(*iDb,*iLocalView,*this,iFindDesArray);
	WAIT_EVENT(4)

		//Expected Result:	Check the order of entries in the find view - it must be reverse
		test.Printf(_L("LocalFind View created:\n"));
		CheckViewOrderL(iLocalFindView);
		test.Printf(_L("\n\n"));

		/////////////////////////////////////////
		//Actions:	Create a Find view on top of the reverse remote view, using "el" search string 
		iFindDesArray->Reset();
		_LIT(Kel,"el");
		iFindDesArray->AppendL(TPtrC(Kel));
		iRemoteFindView = CContactFindView::NewL(*iDb,*iRemoteViewReverse,*this,iFindDesArray);
	WAIT_EVENT(5)
		
		//Expected Result:	Check the order of entries in the find view - it must be reverse
		test.Printf(_L("RemoteFind View created:\n"));
		CheckViewOrderL(iRemoteFindView);
		test.Printf(_L("\n\n"));

		/////////////////
		//Actions:	Add a new contact to the database, it must have "ma" and "el" substrings in it 
		//          to appear in either find view. Check the sorting in every view.		
		_LIT8(KIrvVCard, "BEGIN:VCARD\r\nVERSION:2.1\r\nN:Mansell;Nigel;11\r\nPensioner\r\nEND:VCARD");
		RDesReadStream stream(KIrvVCard);
		stream.PushL();
		  TBool success(EFalse);
		  CArrayPtr<CContactItem>* contactItems=iDb->ImportContactsL(TUid::Uid(KUidVCardConvDefaultImpl), stream, success, NULL);
		CleanupStack::PopAndDestroy(); // stream
		
		PUSH(contactItems);
		  TESTTRUE(success);
		  test.Printf(_L("%d entry was added created\n"), contactItems->Count());
		  contactItems->ResetAndDestroy(); //Potential memory leak - must be pushed onto the stack with ResetAndDestroy
		POPD(contactItems);

	WAIT_EVENTS(6,5) //Waiting for 5 events to arrive (one from each view) 
		//Note, that if all 5 events won't arrive the code will stuck here
		//It can be solved with another "timeout" active object, but not yet implemented
		
		//Expected Result:	Every view must send an event (5 events in total). 
		//Sort order for all the views except for RemoteForward view must be reverse. 
		//New entry must be inserted in every view.
		test.Printf(_L("Local View:\n"));
		CheckViewOrderL(iLocalView);
		test.Printf(_L("\n\n"));

		test.Printf(_L("Remote View Reverse:\n"));
		CheckViewOrderL(iRemoteViewReverse);
		test.Printf(_L("\n\n"));

		test.Printf(_L("Remote View Forward:\n"));
		CheckViewOrderL(iRemoteViewForward, EFalse, EFalse); //do not Print, forward order
		test.Printf(_L("\n\n"));

		test.Printf(_L("Local Find View:\n"));
//.........这里部分代码省略.........
开发者ID:bavanisp,项目名称:qtmobility-1.1.0,代码行数:101,代码来源:t_viewsortplugin.cpp


示例2: equality

static GLboolean equality (slang_assemble_ctx *A, slang_operation *op, GLboolean equal)
{
	slang_assembly_typeinfo ti;
	GLboolean result = GL_FALSE;
	slang_storage_aggregate agg;
	GLuint index, size;
	GLuint skip_jump, true_label, true_jump, false_label, false_jump;

	/* get type of operation */
	if (!slang_assembly_typeinfo_construct (&ti))
		return GL_FALSE;
	if (!_slang_typeof_operation (A, op, &ti))
		goto end1;

	/* convert it to an aggregate */
	if (!slang_storage_aggregate_construct (&agg))
		goto end1;
	if (!_slang_aggregate_variable (&agg, &ti.spec, 0, A->space.funcs, A->space.structs,
			A->space.vars, A->mach, A->file, A->atoms))
		goto end;

	/* compute the size of the agregate - there are two such aggregates on the stack */
	size = _slang_sizeof_aggregate (&agg);

	/* jump to the actual data-comparison code */
	skip_jump = A->file->count;
	if (!PUSH (A->file, slang_asm_jump))
		goto end;

	/* pop off the stack the compared data and push 1 */
	true_label = A->file->count;
	if (!PLAB (A->file, slang_asm_local_free, size * 2))
		goto end;
	if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 1))
		goto end;
	true_jump = A->file->count;
	if (!PUSH (A->file, slang_asm_jump))
		goto end;

	false_label = A->file->count;
	if (!PLAB (A->file, slang_asm_local_free, size * 2))
		goto end;
	if (!PLIT (A->file, slang_asm_bool_push, (GLfloat) 0))
		goto end;
	false_jump = A->file->count;
	if (!PUSH (A->file, slang_asm_jump))
		goto end;

	A->file->code[skip_jump].param[0] = A->file->count;

	/* compare the data on stack, it will eventually jump either to true or false label */
	index = 0;
	if (!equality_aggregate (A, &agg, &index, size, equal ? false_label : true_label))
		goto end;
	if (!PLAB (A->file, slang_asm_jump, equal ? true_label : false_label))
		goto end;

	A->file->code[true_jump].param[0] = A->file->count;
	A->file->code[false_jump].param[0] = A->file->count;

	result = GL_TRUE;
end:
	slang_storage_aggregate_destruct (&agg);
end1:
	slang_assembly_typeinfo_destruct (&ti);
	return result;
}
开发者ID:Magister,项目名称:x11rdp_xorg71,代码行数:67,代码来源:slang_assemble.c


示例3: handle_field

static GLboolean handle_field (slang_assemble_ctx *A, slang_assembly_typeinfo *tia,
	slang_assembly_typeinfo *tib, slang_operation *op, slang_ref_type ref)
{
	/* get type info of the result (field or swizzle) */
	if (!_slang_typeof_operation (A, op, tia))
		return GL_FALSE;

	/* get type info of the master expression being accessed (struct or vector) */
	if (!_slang_typeof_operation (A, &op->children[0], tib))
		return GL_FALSE;

	/* if swizzling a vector in-place, the swizzle temporary is needed */
	if (ref == slang_ref_forbid && tia->is_swizzled)
		if (!PLAB2 (A->file, slang_asm_local_addr, A->local.swizzle_tmp, 16))
			return GL_FALSE;

	/* assemble the master expression */
	if (!_slang_assemble_operation (A, &op->children[0], ref))
		return GL_FALSE;

	/* assemble the field expression */
	if (tia->is_swizzled)
	{
		if (ref == slang_ref_force)
		{
#if 0
			if (tia->swz.num_components == 1)
			{
				/* simple case - adjust the vector's address to point to the selected component */
				if (!PLAB (file, slang_asm_addr_push, tia->swz.swizzle[0] * 4))
					return 0;
				if (!PUSH (file, slang_asm_addr_add))
					return 0;
			}
			else
#endif
			{
				/* two or more vector components are being referenced - the so-called write mask
				 * must be passed to the upper operations and applied when assigning value
				 * to this swizzle */
				A->swz = tia->swz;
			}
		}
		else
		{
			/* swizzle the vector in-place using the swizzle temporary */
			if (!_slang_assemble_constructor_from_swizzle (A, &tia->swz, &tia->spec, &tib->spec))
				return GL_FALSE;
		}
	}
	else
	{
		GLuint i, struct_size = 0, field_offset = 0, field_size = 0;
		GLboolean relocate, shrink;

		/* calculate struct size, field offset and field size */
		for (i = 0; i < tib->spec._struct->fields->num_variables; i++)
		{
			slang_variable *field;
			slang_storage_aggregate agg;
			GLuint size;

			field = &tib->spec._struct->fields->variables[i];
			if (!slang_storage_aggregate_construct (&agg))
				return GL_FALSE;
			if (!_slang_aggregate_variable (&agg, &field->type.specifier, field->array_len,
					A->space.funcs, A->space.structs, A->space.vars, A->mach, A->file, A->atoms))
			{
				slang_storage_aggregate_destruct (&agg);
				return GL_FALSE;
			}
			size = _slang_sizeof_aggregate (&agg);
			slang_storage_aggregate_destruct (&agg);

			if (op->a_id == field->a_name)
			{
				field_size = size;
				struct_size = field_offset + size;
			}
			else if (struct_size != 0)
				struct_size += size;
			else
				field_offset += size;
		}

		/*
		 * OPTIMIZATION: If selecting the last field, no relocation is needed.
		 */
		relocate = field_offset != struct_size - field_size;

		/*
		 * OPTIMIZATION: If field and struct sizes are equal, no partial free is needed.
		 */
		shrink = field_size != struct_size;

		if (relocate)
		{
			if (!PLAB (A->file, slang_asm_addr_push, field_offset))
				return GL_FALSE;
		}
//.........这里部分代码省略.........
开发者ID:Magister,项目名称:x11rdp_xorg71,代码行数:101,代码来源:slang_assemble.c


示例4: _slang_assemble_operation

GLboolean _slang_assemble_operation (slang_assemble_ctx *A, slang_operation *op, slang_ref_type ref)
{
	/* set default results */
	A->ref = /*(ref == slang_ref_freelance) ? slang_ref_force : */ref;
	A->swz.num_components = 0;

	switch (op->type)
	{
	case slang_oper_block_no_new_scope:
	case slang_oper_block_new_scope:
		{
			GLuint i;

			for (i = 0; i < op->num_children; i++)
			{
				if (!_slang_assemble_operation (A, &op->children[i], slang_ref_forbid/*slang_ref_freelance*/))
					return GL_FALSE;
				if (!_slang_cleanup_stack (A, &op->children[i]))
					return GL_FALSE;
			}
		}
		break;
	case slang_oper_variable_decl:
		{
			GLuint i;
			slang_operation assign;
			GLboolean result;

			/* Construct assignment expression placeholder. */
			if (!slang_operation_construct (&assign))
				return GL_FALSE;
			assign.type = slang_oper_assign;
			assign.children = (slang_operation *) slang_alloc_malloc (2 * sizeof (slang_operation));
			if (assign.children == NULL)
			{
				slang_operation_destruct (&assign);
				return GL_FALSE;
			}
			for (assign.num_children = 0; assign.num_children < 2; assign.num_children++)
				if (!slang_operation_construct (&assign.children[assign.num_children]))
				{
					slang_operation_destruct (&assign);
					return GL_FALSE;
				}

			result = GL_TRUE;
			for (i = 0; i < op->num_children; i++)
			{
				slang_variable *var;

				var = _slang_locate_variable (op->children[i].locals, op->children[i].a_id, GL_TRUE);
				if (var == NULL)
				{
					result = GL_FALSE;
					break;
				}
				if (var->initializer == NULL)
					continue;

				if (!slang_operation_copy (&assign.children[0], &op->children[i]) ||
					!slang_operation_copy (&assign.children[1], var->initializer) ||
					!_slang_assemble_assign (A, &assign, "=", slang_ref_forbid) ||
					!_slang_cleanup_stack (A, &assign))
				{
					result = GL_FALSE;
					break;
				}
			}
			slang_operation_destruct (&assign);
			if (!result)
				return GL_FALSE;
		}
		break;
	case slang_oper_asm:
		{
			GLuint i;

			if (!_slang_assemble_operation (A, &op->children[0], slang_ref_force))
				return GL_FALSE;
			for (i = 1; i < op->num_children; i++)
				if (!_slang_assemble_operation (A, &op->children[i], slang_ref_forbid))
					return GL_FALSE;
			if (!call_asm_instruction (A, op->a_id))
				return GL_FALSE;
		}
		break;
	case slang_oper_break:
		if (!PLAB (A->file, slang_asm_jump, A->flow.loop_end))
			return GL_FALSE;
		break;
	case slang_oper_continue:
		if (!PLAB (A->file, slang_asm_jump, A->flow.loop_start))
			return GL_FALSE;
		break;
	case slang_oper_discard:
		if (!PUSH (A->file, slang_asm_discard))
			return GL_FALSE;
		if (!PUSH (A->file, slang_asm_exit))
			return GL_FALSE;
		break;
//.........这里部分代码省略.........
开发者ID:Magister,项目名称:x11rdp_xorg71,代码行数:101,代码来源:slang_assemble.c


示例5: dereference_aggregate

static GLboolean dereference_aggregate (slang_assemble_ctx *A, const slang_storage_aggregate *agg,
	GLuint *size, slang_swizzle *swz, GLboolean is_swizzled)
{
	GLuint i;

	for (i = agg->count; i > 0; i--)
	{
		const slang_storage_array *arr = &agg->arrays[i - 1];
		GLuint j;

		for (j = arr->length; j > 0; j--)
		{
			if (arr->type == slang_stor_aggregate)
			{
				if (!dereference_aggregate (A, arr->aggregate, size, swz, is_swizzled))
					return GL_FALSE;
			}
			else
			{
				GLuint src_offset;
				slang_assembly_type ty;

				*size -= 4;

				/* calculate the offset within source variable to read */
				if (is_swizzled)
				{
					/* swizzle the index to get the actual offset */
					src_offset = swz->swizzle[*size / 4] * 4;
				}
				else
				{
					/* no swizzling - read sequentially */
					src_offset = *size;
				}

				/* dereference data slot of a basic type */
				if (!PLAB2 (A->file, slang_asm_local_addr, A->local.addr_tmp, 4))
					return GL_FALSE;
				if (!PUSH (A->file, slang_asm_addr_deref))
					return GL_FALSE;
				if (!PLAB (A->file, slang_asm_addr_push, src_offset))
					return GL_FALSE;
				if (!PUSH (A->file, slang_asm_addr_add))
					return GL_FALSE;

				switch (arr->type)
				{
				case slang_stor_bool:
					ty = slang_asm_bool_deref;
					break;
				case slang_stor_int:
					ty = slang_asm_int_deref;
					break;
				case slang_stor_float:
					ty = slang_asm_float_deref;
					break;
				default:
					_mesa_problem(NULL, "Unexpected arr->type in dereference_aggregate");
					ty = slang_asm_none;
				}
				if (!PUSH (A->file, ty))
					return GL_FALSE;
			}
		}
	}

	return GL_TRUE;
}
开发者ID:Magister,项目名称:x11rdp_xorg71,代码行数:69,代码来源:slang_assemble.c


示例6: cardEffect


//.........这里部分代码省略.........
		}
					
	    }
				
	}				

      //discard played card from hand
      discardCard(handPos, currentPlayer, state, 0);			

      return 0;

		
    case embargo: 
      //+2 Coins
      state->coins = state->coins + 2;
			
      //see if selected pile is in play
      if ( state->supplyCount[choice1] == -1 )
	{
	  return -1;
	}
			
      //add embargo token to selected supply pile
      state->embargoTokens[choice1]++;
			
      //trash card
      discardCard(handPos, currentPlayer, state, 1);		
      return 0;
		
    case outpost:
      //set outpost flag
      state->outpostPlayed++;
			
      //discard card
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case salvager:
      //+1 buy
      state->numBuys++;
			
      if (choice1)
	{
	  //gain coins equal to trashed card
	  state->coins = state->coins + getCost( handCard(choice1, state) );
	  //trash card
	  discardCard(choice1, currentPlayer, state, 1);	
	}
			
      //discard card
      discardCard(handPos, currentPlayer, state, 0);
      return 0;
		
    case sea_hag:
      for(i = (currentPlayer+1)%state->numPlayers; i != currentPlayer; i = (i+1)%state->numPlayers)
		{
		if (drawCard(i, state) != 1){
		  PUSH(discard, i, POP_R(hand, i));
		}  
		  gainCard(curse, state, 1, i);
		
	}
	discardCard(handPos, currentPlayer, state, 0);

	return 0;
		
    case treasure_map:
      //search hand for another treasure_map
      index = -1;
      for (i = 0; i < state->handCount[currentPlayer]; i++)
	{
	  if (state->hand[currentPlayer][i] == treasure_map && i != handPos)
	    {
	      index = i;
	      break;
	    }
	}
      if (index > -1)
	{
	  //trash both treasure cards
	  discardCard(handPos, currentPlayer, state, 1);
	  discardCard(index, currentPlayer, state, 1);

	  //gain 4 Gold cards
	  for (i = 0; i < 4; i++)
	    {
	      gainCard(gold, state, 1, currentPlayer);
	    }
				
	  //return success
	  return 1;
	}
			
      //no second treasure_map found in hand
      return -1;
    }
	
  return -1;
	}
}
开发者ID:cs362sp16,项目名称:cs362sp16_fryta,代码行数:101,代码来源:mutatedDominion.c


示例7: xcoff_load

int 
xcoff_load(ihandle_t dev)
{
	COFF_filehdr_t fhdr;
	COFF_aouthdr_t ahdr;
	COFF_scnhdr_t shdr;
	uint32_t offset;
	size_t total_size = 0;
	int fd, i;
	int retval = -1;
	
	/* Mark the saved-program-state as invalid */
	feval("0 state-valid !");

	fd = open_ih(dev);
	if (fd == -1) {
		retval = LOADER_NOT_SUPPORT;
		goto out;
	}
	
	for (offset = 0; offset < 16 * 512; offset += 512) {
		seek_io(fd, offset);
		if (read_io(fd, &fhdr, sizeof fhdr) != sizeof fhdr) {
			DPRINTF("Can't read XCOFF header\n");
			retval = LOADER_NOT_SUPPORT;
			goto out;
		}
		
		if (is_xcoff(&fhdr))
			break;
	}
	
	/* Is it executable ? */
	if (fhdr.f_magic != 0x01DF &&
	    (fhdr.f_flags & COFF_F_EXEC) == 0) {
		DPRINTF("Not an executable XCOFF file %02x\n", fhdr.f_flags);
		return LOADER_NOT_SUPPORT;
	}

	/* Optional header is a.out ? */
	if (fhdr.f_opthdr != sizeof(COFF_aouthdr_t)) {
		DPRINTF("AOUT optional error size mismatch in XCOFF file\n");
		return LOADER_NOT_SUPPORT;
	}
	
	seek_io(fd, sizeof(COFF_filehdr_t));
	read_io(fd, &ahdr, sizeof(COFF_aouthdr_t));
	
	/* check a.out magic number */
	if (ahdr.magic != AOUT_MAGIC) {
		DPRINTF("Invalid AOUT optional header\n");
		return LOADER_NOT_SUPPORT;
	}

	offset = sizeof(COFF_filehdr_t) + sizeof(COFF_aouthdr_t);

	DPRINTF("XCOFF file with %d sections\n", fhdr.f_nscns);

	for (i = 0; i < fhdr.f_nscns; i++) {
		DPRINTF("Read header at offset %0x\n", offset);
		seek_io(fd, offset);
		read_io(fd, &shdr, sizeof(COFF_scnhdr_t));

		DPRINTF("Initializing '%s' section from %0x %0x to %0x (%0x)\n",
			shdr.s_name, offset, shdr.s_scnptr,
			shdr.s_vaddr, shdr.s_size);

		if (strcmp(shdr.s_name, ".text") == 0) {
			read_io(fd, (void *)shdr.s_vaddr, shdr.s_size);
			total_size += shdr.s_size;
#ifdef CONFIG_PPC
			flush_icache_range((char*)(uintptr_t)shdr.s_vaddr,
					 (char*)(uintptr_t)(shdr.s_vaddr + shdr.s_size));
#endif
		} else if (strcmp(shdr.s_name, ".data") == 0) {
			read_io(fd, (void *)shdr.s_vaddr, shdr.s_size);
			total_size += shdr.s_size;

		} else if (strcmp(shdr.s_name, ".bss") == 0) {
			memset((void *)(uintptr_t)shdr.s_vaddr, 0, shdr.s_size);
			total_size += shdr.s_size;
		} else {
			DPRINTF("    Skip '%s' section\n", shdr.s_name);
		}
		offset += sizeof(COFF_scnhdr_t);
	}

	DPRINTF("XCOFF entry point: %x\n", *(uint32_t*)ahdr.entry);

	// Initialise load-state
	PUSH(total_size);
	feval("load-state >ls.file-size !");
	feval("xcoff load-state >ls.file-type !");

out:
	close_io(fd);
	return retval;
}
开发者ID:openbios,项目名称:openbios,代码行数:98,代码来源:xcoff_load.c


示例8: floodFill

std::vector<QPoint>
floodFill(QImage *img, const QPoint &pos, const QRgb &newColor)
{
   QImage image = img->copy();
   std::vector<QPoint> modified;

   int x = pos.x(), y = pos.y();
   const QRgb oldColor = image.pixel(x, y);

   std::vector<fillpixelinfo> stack;

   int l, x1, x2, dy;

   if ((x >= 0) && (x < image.width()) && (y >= 0) && (y < image.height()))
   {
       if (oldColor == newColor)
       {
           return modified;
       }
       PUSH(y, x, x, 1);
       PUSH(y + 1, x, x, -1);
       while (!stack.empty())
       {
           POP(y, x1, x2, dy);
           for (x = x1; (x >= 0) && image.pixel(x, y) == oldColor; x--)
           {
               image.setPixel(x, y, newColor);
               modified.emplace_back(x, y);
           }
           if (x >= x1)
           {
               goto skip;
           }
           l = x + 1;
           if (l < x1)
           {
               PUSH(y, l, x1 - 1, -dy);
           }
           x = x1 + 1;
           do
           {
               for (; (x < image.width()) && image.pixel(x, y) == oldColor; x++)
               {
                   image.setPixel(x, y, newColor);
                   modified.emplace_back(x, y);
               }
               PUSH(y, l, x - 1, dy);
               if (x > x2 + 1)
               {
                   PUSH(y, x2 + 1, x - 1, -dy);
               }
skip:
               for (x++; x <= x2 && image.pixel(x, y) != oldColor; x++)
               {
                   /* empty */ ;
               }
               l = x;
           } while (x <= x2);
       }
   }

   return modified;
}
开发者ID:kanego,项目名称:Paint,代码行数:63,代码来源:floodfill.cpp


示例9: INTSORTNAME

void
INTSORTNAME (
void * const                pbase,                /*+ Array to sort             +*/
const PASTIX_INT                   total_elems)          /*+ Number of entries to sort +*/
{
  register char *base_ptr = (char *) pbase;

  if (total_elems == 0)
    /* Avoid lossage with unsigned arithmetic below.  */
    return;

  if (total_elems > MAX_THRESH)
    {
      char *lo = base_ptr;
      char *hi = &lo[INTSORTSIZE * (total_elems - 1)];
      stack_node stack[STACK_SIZE];
      stack_node *top = stack;

      PUSH (NULL, NULL);

      while (STACK_NOT_EMPTY)
        {
          char *left_ptr;
          char *right_ptr;

	  /* Select median value from among LO, MID, and HI. Rearrange
	     LO and HI so the three values are sorted. This lowers the
	     probability of picking a pathological pivot value and
	     skips a comparison for both the LEFT_PTR and RIGHT_PTR in
	     the while loops. */

	  char *mid = lo + INTSORTSIZE * ((hi - lo) / INTSORTSIZE >> 1);

	  if (INTSORTCMP ((void *) mid, (void *) lo))
	    INTSORTSWAP (mid, lo);
	  if (INTSORTCMP ((void *) hi, (void *) mid))
	    INTSORTSWAP (mid, hi);
	  else
	    goto jump_over;
	  if (INTSORTCMP ((void *) mid, (void *) lo))
	    INTSORTSWAP (mid, lo);
	jump_over:;

	  left_ptr  = lo + INTSORTSIZE;
	  right_ptr = hi - INTSORTSIZE;

	  /* Here's the famous ``collapse the walls'' section of quicksort.
	     Gotta like those tight inner loops!  They are the main reason
	     that this algorithm runs much faster than others. */
	  do
	    {
	      while (INTSORTCMP ((void *) left_ptr, (void *) mid))
		left_ptr += INTSORTSIZE;

	      while (INTSORTCMP ((void *) mid, (void *) right_ptr))
		right_ptr -= INTSORTSIZE;

	      if (left_ptr < right_ptr)
		{
		  INTSORTSWAP (left_ptr, right_ptr);
		  if (mid == left_ptr)
		    mid = right_ptr;
		  else if (mid == right_ptr)
		    mid = left_ptr;
		  left_ptr += INTSORTSIZE;
		  right_ptr -= INTSORTSIZE;
		}
	      else if (left_ptr == right_ptr)
		{
		  left_ptr += INTSORTSIZE;
		  right_ptr -= INTSORTSIZE;
		  break;
		}
	    }
	  while (left_ptr <= right_ptr);

          /* Set up pointers for next iteration.  First determine whether
             left and right partitions are below the threshold size.  If so,
             ignore one or both.  Otherwise, push the larger partition's
             bounds on the stack and continue sorting the smaller one. */

          if ((size_t) (right_ptr - lo) <= max_thresh)
            {
              if ((size_t) (hi - left_ptr) <= max_thresh)
		/* Ignore both small partitions. */
                POP (lo, hi);
              else
		/* Ignore small left partition. */
                lo = left_ptr;
            }
          else if ((size_t) (hi - left_ptr) <= max_thresh)
	    /* Ignore small right partition. */
            hi = right_ptr;
          else if ((right_ptr - lo) > (hi - left_ptr))
            {
	      /* Push larger left partition indices. */
              PUSH (lo, right_ptr);
              lo = left_ptr;
            }
          else
//.........这里部分代码省略.........
开发者ID:OpenCMISS-Dependencies,项目名称:pastix,代码行数:101,代码来源:common_sort.c


示例10: mrb_str_format

mrb_value
mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt)
{
    const char *p, *end;
    char *buf;
    mrb_int blen;
    mrb_int bsiz;
    mrb_int n;
    mrb_int width;
    mrb_int prec;
    int flags = FNONE;
    int nextarg = 1;
    int posarg = 0;
    mrb_value nextvalue;
    mrb_value tmp;
    mrb_value str;
    mrb_value hash = mrb_value::undef();

#define CHECK_FOR_WIDTH(f)                                                  \
    if ((f) & FWIDTH) {                                                       \
    mrb->mrb_raise(E_ARGUMENT_ERROR, "width given twice");         \
}                                                                         \
    if ((f) & FPREC0) {                                                       \
    mrb->mrb_raise(E_ARGUMENT_ERROR, "width after precision");     \
}
#define CHECK_FOR_FLAGS(f)                                                  \
    if ((f) & FWIDTH) {                                                       \
    mrb->mrb_raise(E_ARGUMENT_ERROR, "flag after width");          \
}                                                                         \
    if ((f) & FPREC0) {                                                       \
    mrb->mrb_raise(E_ARGUMENT_ERROR, "flag after precision");      \
}

    ++argc;
    --argv;
    fmt = mrb_str_to_str(mrb, fmt);
    p = RSTRING_PTR(fmt);
    end = p + RSTRING_LEN(fmt);
    blen = 0;
    bsiz = 120;
    RString *res_ptr= RString::create(mrb,bsiz);
    buf = res_ptr->m_ptr;
    memset(buf, 0, bsiz);

    for (; p < end; p++) {
        const char *t;
        mrb_sym id = 0;

        for (t = p; t < end && *t != '%'; t++) ;
        PUSH(p, t - p);
        if (t >= end)
            goto sprint_exit; /* end of fmt string */

        p = t + 1;    /* skip `%' */

        width = prec = -1;
        nextvalue = mrb_value::undef();

retry:
        switch (*p) {
        default:
            mrb->mrb_raisef(E_ARGUMENT_ERROR, "malformed format string - \\%%S", mrb_str_new(mrb, p, 1));
            break;

        case ' ':
            CHECK_FOR_FLAGS(flags);
            flags |= FSPACE;
            p++;
            goto retry;

        case '#':
            CHECK_FOR_FLAGS(flags);
            flags |= FSHARP;
            p++;
            goto retry;

        case '+':
            CHECK_FOR_FLAGS(flags);
            flags |= FPLUS;
            p++;
            goto retry;

        case '-':
            CHECK_FOR_FLAGS(flags);
            flags |= FMINUS;
            p++;
            goto retry;

        case '0':
            CHECK_FOR_FLAGS(flags);
            flags |= FZERO;
            p++;
            goto retry;

        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
//.........这里部分代码省略.........
开发者ID:Prashant-Jonny,项目名称:red_tint,代码行数:101,代码来源:sprintf.cpp


示例11: main

int main(int argc, char *argv[]) {
//sgenrand(time(NULL));
int k, curr_pos, check;
int chunk; /* Repeat experiment in chunks. */
srand(SEED);

printf("# Info: $Header: /home/ma/p/pruess/.cvsroot/manna_range/dmitry_20151021/manna_stack_clean_edited.c,v 1.2 2015/10/21 11:37:00 pruess Exp $\n");
preamble(argc, argv);

PRINT_PARAM(SEED, "%lu");
PRINT_PARAM(LENGTH, "%lu");
PRINT_PARAM(DROP_LOCATION, "%lu");
PRINT_PARAM(total_malloced, "%lli");


printf("# Info: Expected avalanche size: <s>(x) = 1+(1/2) (<s>(x+1)+<s>(x-1)), BC <s>(0)=0, <s>(L+1)=0, solved by <s>(x)=(L+1-x)x/2.\n");
printf("# Info: Here L=LENGTH=%lu and x=DROP_LOCATION+1=%lu, so expect %g\n", LENGTH, DROP_LOCATION+1, ((double)(DROP_LOCATION+1))*((double)(LENGTH-DROP_LOCATION))/2.);


for (chunk=1; ((chunk<=NUM_CHUNKS) || (NUM_CHUNKS<0)); chunk++) {
MOMENTS_INIT(size);
for (drop = 0; drop < N_ROLLS; drop++) {  // big droppping cycle

size=0;

#if (1-MODE_BSF)

#define PUSH(a) stack[stack_used++]=(a)
#define POP(a)  (a)=stack[--stack_used]

if(lattice[DROP_LOCATION] == 0) {
      lattice[DROP_LOCATION] = 1;
      }
 else {
      PUSH(DROP_LOCATION); 
      PUSH(DROP_LOCATION);
      lattice[DROP_LOCATION] = 0;
      size++;
 }

/* If validated, optimse by turning stack operations into macros, 
 * optime random number drawing (rather than having doubles in the tree
 * have integers there and draw an integer to compare against),
 * optimise the shuffling of particles. 
 *
 * I have added MOMENT macros for size. */

  while(stack_used != 0) {
    POP(curr_pos);
/* This code with the "check" looks clumsy. I suppose
 * you are "following through" topplings? I would think
 * there is no point doing this later. Anyway, we validate
 * this code and take it from there. */
    do {
      curr_pos = curr_pos+ ( (rand()>RAND_MAX/2) ? 1 : -1); //move_ball(curr_pos);
 
      if((curr_pos>=0) && (curr_pos<LENGTH)) {
        if(lattice[curr_pos] == 0)  {
          lattice[curr_pos] = 1;
          }
        else  {
          size++;
          lattice[curr_pos] = 0;
          PUSH(curr_pos);
        }
    } 
    else {break;}
  }while( (lattice[curr_pos] != 1));
}/* end of while(stack_used != 0) look */
#endif

#if (MODE_BSF)
{
int npos;

#define PUSH(a) stack[stack_used++]=(a)
#define POP(a)  (a)=stack[--stack_used]

if (lattice[DROP_LOCATION]++==1) {
  PUSH(DROP_LOCATION);
  //size++;
    while(stack_used) {
      size++;
      POP(curr_pos);
      do {

	lattice[curr_pos]-=2;
	npos=curr_pos+ ( (new_rand()!=(int)0) ? 1 : -1);
	if ((npos>=0) && (npos<LENGTH)) {
	  if (lattice[npos]++==1) {PUSH(npos);}
	}
//rand()>RAND_MAX/2
//new_rand()==0
        npos=curr_pos+ ( (new_rand()!=(int)0) ? 1 : -1);
	if ((npos>=0) && (npos<LENGTH)) {
	  if (lattice[npos]++==1) {PUSH(npos);}
	}


        
//.........这里部分代码省略.........
开发者ID:dv913,项目名称:manna,代码行数:101,代码来源:bsf_main.c


示例12: X6502_RunDebug

static void X6502_RunDebug(int32 cycles)
{
	#define RdMem RdMemHook
	#define WrMem WrMemHook
        #define ADDBT(to) NESDBG_AddBranchTrace(old_PC, to, 0)

        if(PAL)
         cycles*=15;          // 15*4=60
        else
         cycles*=16;          // 16*4=64

        _count+=cycles;

	PenguinPower:
        while(_count>0)
        {
	 const uint16 old_PC = _PC;
         int32 temp;
         uint8 b1;

         if(_IRQlow && !X.cpoint) // Don't run IRQ stuff if we weren't here in a save state
         { 
          if(_IRQlow&MDFN_IQRESET)
          {
           _PC=RdMem(0xFFFC);
           _PC|=RdMem(0xFFFD)<<8;
	   NESDBG_AddBranchTrace(old_PC, _PC, 0xFFFC); //	   ADDBT(_PC);
           _jammed=0;
           _PI=_P=I_FLAG;
           _IRQlow&=~MDFN_IQRESET;
          }
          else if(_IRQlow&MDFN_IQNMI2)
          {
           _IRQlow&=~MDFN_IQNMI2; 
           _IRQlow|=MDFN_IQNMI;
          }
          else if(_IRQlow&MDFN_IQNMI)
          {
           if(!_jammed)
           {
            ADDCYC(7);
            PUSH(_PC>>8);
            PUSH(_PC);
            PUSH((_P&~B_FLAG)|(U_FLAG));
            _P|=I_FLAG; 
            _PC=RdMem(0xFFFA); 
            _PC|=RdMem(0xFFFB)<<8;
	    NESDBG_AddBranchTrace(old_PC, _PC, 0xFFFA); //    ADDBT(_PC);
            _IRQlow&=~MDFN_IQNMI;
           }
          }
          else 
          { 
           if(!(_PI&I_FLAG) && !_jammed)
           {
            ADDCYC(7);
            PUSH(_PC>>8);
            PUSH(_PC);
            PUSH((_P&~B_FLAG)|(U_FLAG));
            _P|=I_FLAG;
            _PC=RdMem(0xFFFE);
            _PC|=RdMem(0xFFFF)<<8;
	    NESDBG_AddBranchTrace(old_PC, _PC, 0xFFFE);	//ADDBT(_PC);
           }
          }
开发者ID:XeresRazor,项目名称:Provenance,代码行数:65,代码来源:x6502.cpp


示例13: __config_next

/*
 * __config_next --
 *	Get the next config item in the string without processing the value.
 */
static int
__config_next(WT_CONFIG *conf, WT_CONFIG_ITEM *key, WT_CONFIG_ITEM *value)
{
	WT_CONFIG_ITEM *out;
	int utf8_remain;
	static const WT_CONFIG_ITEM true_value = {
		"", 0, 1, WT_CONFIG_ITEM_BOOL
	};

	/* Keys with no value default to true. */
	*value = true_value;

	out = key;
	utf8_remain = 0;
	key->len = 0;

	if (conf->go == NULL)
		conf->go = gostruct;

	while (conf->cur < conf->end) {
		switch (conf->go[*(const uint8_t *)conf->cur]) {
		case A_LOOP:
			break;

		case A_BAD:
			return (__config_err(
			    conf, "Unexpected character", EINVAL));

		case A_DOWN:
			if (conf->top == -1)
				return (__config_err(
				    conf, "Unbalanced brackets", EINVAL));
			--conf->depth;
			CAP(0);
			break;

		case A_UP:
			if (conf->top == -1)
				conf->top = 1;
			PUSH(0, WT_CONFIG_ITEM_STRUCT);
			++conf->depth;
			break;

		case A_VALUE:
			if (conf->depth == conf->top) {
				/*
				 * Special case: ':' is permitted in unquoted
				 * values.
				 */
				if (out == value && *conf->cur != ':')
					return (__config_err(conf,
					    "Value already complete", EINVAL));
				out = value;
			}
			break;

		case A_NEXT:
			/*
			 * If we're at the top level and we have a complete
			 * key (and optional value), we're done.
			 */
			if (conf->depth == conf->top && key->len > 0) {
				++conf->cur;
				return (0);
			} else
				break;

		case A_QDOWN:
			CAP(-1);
			conf->go = gostruct;
			break;

		case A_QUP:
			PUSH(1, WT_CONFIG_ITEM_STRING);
			conf->go = gostring;
			break;

		case A_ESC:
			conf->go = goesc;
			break;

		case A_UNESC:
			conf->go = gostring;
			break;

		case A_BARE:
			PUSH(0, WT_CONFIG_ITEM_ID);
			conf->go = gobare;
			break;

		case A_NUMBARE:
			PUSH(0, WT_CONFIG_ITEM_NUM);
			conf->go = gobare;
			break;

		case A_UNBARE:
//.........这里部分代码省略.........
开发者ID:ajdavis,项目名称:mongo,代码行数:101,代码来源:config.c


示例14: stack3

static void stack3(void)
{
    SP = S0;	// empty the stack

    PUSH(-1); PUSH(0); PUSH(237);
}
开发者ID:rrthomas,项目名称:beetle,代码行数:6,代码来源:comparison.c


示例15: _quicksort

void
_quicksort (void *const pbase, size_t total_elems, size_t size,
	    __compar_fn_t cmp)
{
  register char *base_ptr = (char *) pbase;

  /* Allocating SIZE bytes for a pivot buffer facilitates a better
     algorithm below since we can do comparisons directly on the pivot. */
  char *pivot_buffer = (char *) __alloca (size);
  const size_t max_thresh = MAX_THRESH * size;

  if (total_elems == 0)
    /* Avoid lossage with unsigned arithmetic below.  */
    return;

  if (total_elems > MAX_THRESH)
    {
      char *lo = base_ptr;
      char *hi = &lo[size * (total_elems - 1)];
      stack_node stack[STACK_SIZE];
      stack_node *top = stack + 1;

      while (STACK_NOT_EMPTY)
        {
          char *left_ptr;
          char *right_ptr;

	  char *pivot = pivot_buffer;

	  /* Select median value from among LO, MID, and HI. Rearrange
	     LO and HI so the three values are sorted. This lowers the
	     probability of picking a pathological pivot value and
	     skips a comparison for both the LEFT_PTR and RIGHT_PTR in
	     the while loops. */

	  char *mid = lo + size * ((hi - lo) / size >> 1);

	  if ((*cmp) ((void *) mid, (void *) lo) < 0)
	    SWAP (mid, lo, size);
	  if ((*cmp) ((void *) hi, (void *) mid) < 0)
	    SWAP (mid, hi, size);
	  else
	    goto jump_over;
	  if ((*cmp) ((void *) mid, (void *) lo) < 0)
	    SWAP (mid, lo, size);
	jump_over:;
	  memcpy (pivot, mid, size);
	  pivot = pivot_buffer;

	  left_ptr  = lo + size;
	  right_ptr = hi - size;

	  /* Here's the famous ``collapse the walls'' section of quicksort.
	     Gotta like those tight inner loops!  They are the main reason
	     that this algorithm runs much faster than others. */
	  do
	    {
	      while ((*cmp) ((void *) left_ptr, (void *) pivot) < 0)
		left_ptr += size;

	      while ((*cmp) ((void *) pivot, (void *) right_ptr) < 0)
		right_ptr -= size;

	      if (left_ptr < right_ptr)
		{
		  SWAP (left_ptr, right_ptr, size);
		  left_ptr += size;
		  right_ptr -= size;
		}
	      else if (left_ptr == right_ptr)
		{
		  left_ptr += size;
		  right_ptr -= size;
		  break;
		}
	    }
	  while (left_ptr <= right_ptr);

          /* Set up pointers for next iteration.  First determine whether
             left and right partitions are below the threshold size.  If so,
             ignore one or both.  Otherwise, push the larger partition's
             bounds on the stack and continue sorting the smaller one. */

          if ((size_t) (right_ptr - lo) <= max_thresh)
            {
              if ((size_t) (hi - left_ptr) <= max_thresh)
		/* Ignore both small partitions. */
                POP (lo, hi);
              else
		/* Ignore small left partition. */
                lo = left_ptr;
            }
          else if ((size_t) (hi - left_ptr) <= max_thresh)
	    /* Ignore small right partition. */
            hi = right_ptr;
          else if ((right_ptr - lo) > (hi - left_ptr))
            {
	      /* Push larger left partition indices. */
              PUSH (lo, right_ptr);
              lo = left_ptr;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:101,代码来源:qsort.c


示例16: elf_load

int
elf_load(struct sys_info *info, ihandle_t dev, const char *cmdline, void **boot_notes)
{
    Elf_ehdr ehdr;
    Elf_phdr *phdr = NULL;
    unsigned long checksum_offset, file_size;
    unsigned short checksum = 0;
    int retval = -1;
    unsigned int offset;

    image_name = image_version = NULL;

    /* Mark the saved-program-state as invalid */
    feval("0 state-valid !");

    fd = open_ih(dev);
    if (fd == -1) {
        goto out;
    }

    offset = find_elf(&ehdr);
    if (!offset) {
        retval = LOADER_NOT_SUPPORT;
        goto out;
    }

#if DEBUG
    printk("ELF header:\n");
    printk(" ehdr.e_type    = %d\n", (int)ehdr.e_type);
    printk(" ehdr.e_machine = %d\n", (int)ehdr.e_machine);
    printk(" ehdr.e_version = %d\n", (int)ehdr.e_version);
    printk(" ehdr.e_entry   = 0x%08x\n", (int)ehdr.e_entry);
    printk(" ehdr.e_phoff   = 0x%08x\n", (int)ehdr.e_phoff);
    printk(" ehdr.e_shoff   = 0x%08x\n", (int)ehdr.e_shoff);
    printk(" ehdr.e_flags   = %d\n", (int)ehdr.e_flags);
    printk(" ehdr.e_ehsize  = 0x%08x\n", (int)ehdr.e_ehsize);
    printk(" ehdr.e_phentsize = 0x%08x\n", (int)ehdr.e_phentsize);
    printk(" ehdr.e_phnum   = %d\n", (int)ehdr.e_phnum);
#endif

    if (ehdr.e_phnum > MAX_HEADERS) {
        printk ("elfload: too many program headers (MAX_HEADERS)\n");
        retval = 0;
        goto out;
    }

    phdr = elf_readhdrs(offset, &ehdr);
    if (!phdr)
        goto out;

    if (!check_mem_ranges(info, phdr, ehdr.e_phnum))
        goto out;

    checksum_offset = process_image_notes(phdr, ehdr.e_phnum, &checksum, offset);

    printf("Loading %s", image_name ? image_name : "image");
    if (image_version)
        printf(" version %s", image_version);
    printf("...\n");

    if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset, &file_size))
        goto out;

    if (checksum_offset) {
        if (!verify_image(&ehdr, phdr, ehdr.e_phnum, checksum))
            goto out;
    }

    /* If we are attempting an ELF boot image, we pass a non-NULL pointer
       into boot_notes and mark the image as elf-boot rather than standard
       ELF */
    if (boot_notes) {
        *boot_notes = (void *)virt_to_phys(build_boot_notes(info, cmdline));
        feval("elf-boot saved-program-state >sps.file-type !");
    } else {
        feval("elf saved-program-state >sps.file-type !");
    }

    //debug("current time: %lu\n", currticks());

    debug("entry point is " FMT_elf "\n", addr_fixup(ehdr.e_entry));

    // Initialise saved-program-state
    PUSH(addr_fixup(ehdr.e_entry));
    feval("saved-program-state >sps.entry !");
    PUSH(file_size);
    feval("saved-program-state >sps.file-size !");

    feval("-1 state-valid !");

out:
    close_io(fd);
    if (phdr)
        free(phdr);
    if (image_name)
        free(image_name);
    if (image_version)
        free(image_version);
    return retval;
}
开发者ID:hoyori,项目名称:panda,代码行数:100,代码来源:elf_load.c


示例17: _assert_msg_

LinearFunc SamplerJitCache::CompileLinear(const SamplerID &id) {
	_assert_msg_(G3D, id.linear, "Linear should be set on sampler id");
	BeginWrite();

	// We'll first write the nearest sampler, which we will CALL.
	// This may differ slightly based on the "linear" flag.
	const u8 *nearest = AlignCode16();

	if (!Jit_ReadTextureFormat(id)) {
		EndWrite();
		SetCodePtr(const_cast<u8 *>(nearest));
		return nullptr;
	}

	RET();

	// Now the actual linear func, which is exposed externally.
	const u8 *start = AlignCode16();

	// NOTE: This doesn't use the general register mapping.
	// POSIX: arg1=uptr, arg2=vptr 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PUSHWORD函数代码示例发布时间:2022-05-30
下一篇:
C++ PURPLE_CONV_CHAT函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap