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


C++ ensure函数代码示例

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


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

示例1: while

/* Render an object to text. */
static char *print_object(cJSON * item, int depth, int fmt,
			  printbuffer * p)
{
    char **entries = 0, **names = 0;
    char *out = 0, *ptr, *ret, *str;
    int len = 7, i = 0, j;
    cJSON *child = item->child;
    int numentries = 0, fail = 0;
    size_t tmplen = 0;

    /* Count the number of entries. */
    while (child)
	numentries++, child = child->next;
    /* Explicitly handle empty object case */
    if (!numentries) {
	if (p)
	    out = ensure(p, fmt ? depth + 4 : 3);
	else
	    out = (char *) cJSON_malloc(fmt ? depth + 4 : 3);
	if (!out)
	    return 0;
	ptr = out;
	*ptr++ = '{';
	if (fmt) {
	    *ptr++ = '\n';
	    for (i = 0; i < depth - 1; i++)
		*ptr++ = '\t';
	}
	*ptr++ = '}';
	*ptr++ = 0;
	return out;
    }
    if (p) {
	/* Compose the output: */
	i = p->offset;
	len = fmt ? 2 : 1;
	ptr = ensure(p, len + 1);
	if (!ptr)
	    return 0;
	*ptr++ = '{';
	if (fmt)
	    *ptr++ = '\n';
	*ptr = 0;
	p->offset += len;
	child = item->child;
	depth++;
	while (child) {
	    if (fmt) {
		ptr = ensure(p, depth);
		if (!ptr)
		    return 0;
		for (j = 0; j < depth; j++)
		    *ptr++ = '\t';
		p->offset += depth;
	    }
	    print_string_ptr(child->string, p);
	    p->offset = update(p);

	    len = fmt ? 2 : 1;
	    ptr = ensure(p, len);
	    if (!ptr)
		return 0;
	    *ptr++ = ':';
	    if (fmt)
		*ptr++ = '\t';
	    p->offset += len;

	    print_value(child, depth, fmt, p);
	    p->offset = update(p);

	    len = (fmt ? 1 : 0) + (child->next ? 1 : 0);
	    ptr = ensure(p, len + 1);
	    if (!ptr)
		return 0;
	    if (child->next)
		*ptr++ = ',';
	    if (fmt)
		*ptr++ = '\n';
	    *ptr = 0;
	    p->offset += len;
	    child = child->next;
	}
	ptr = ensure(p, fmt ? (depth + 1) : 2);
	if (!ptr)
	    return 0;
	if (fmt)
	    for (i = 0; i < depth - 1; i++)
		*ptr++ = '\t';
	*ptr++ = '}';
	*ptr = 0;
	out = (p->buffer) + i;
    } else {
	/* Allocate space for the names and the objects */
	entries = (char **) cJSON_malloc(numentries * sizeof(char *));
	if (!entries)
	    return 0;
	names = (char **) cJSON_malloc(numentries * sizeof(char *));
	if (!names) {
	    cJSON_free(entries);
//.........这里部分代码省略.........
开发者ID:hurley25,项目名称:ttms,代码行数:101,代码来源:cJSON.c

示例2: mbrpipe_set_volume

static void mbrpipe_set_volume(signed int volume)
{
	mbrpipe_volume = ensure(volume,-100,100);
}
开发者ID:razr,项目名称:opentts,代码行数:4,代码来源:mbrpipe.c

示例3: mbrpipe_set_pitch

static void mbrpipe_set_pitch(signed int pitch)
{
	mbrpipe_pitch = ensure(pitch,-100,100);
}
开发者ID:razr,项目名称:opentts,代码行数:4,代码来源:mbrpipe.c

示例4: gt_bitPackStringInt64_unit_test

int
gt_bitPackStringInt64_unit_test(GtError *err)
{
  BitString bitStore = NULL;
  BitString bitStoreCopy = NULL;
  uint64_t *randSrc = NULL; /*< create random ints here for input as bit
                                *  store */
  uint64_t *randCmp = NULL; /*< used for random ints read back */
  unsigned *numBitsList = NULL;
  size_t i, numRnd;
  BitOffset offsetStart, offset;
  int had_err = 0;
  offset = offsetStart = random()%(sizeof (uint64_t) * CHAR_BIT);
  numRnd = random() % (MAX_RND_NUMS_uint64_t + 1);
  gt_log_log("offset=%lu, numRnd=%lu\n",
          (long unsigned)offsetStart, (long unsigned)numRnd);
  {
    BitOffset numBits = sizeof (uint64_t) * CHAR_BIT * numRnd + offsetStart;
    randSrc = gt_malloc(sizeof (uint64_t)*numRnd);
    bitStore = gt_malloc(bitElemsAllocSize(numBits) * sizeof (BitElem));
    bitStoreCopy = gt_calloc(bitElemsAllocSize(numBits), sizeof (BitElem));
    randCmp = gt_malloc(sizeof (uint64_t)*numRnd);
  }
  /* first test unsigned types */
  gt_log_log("gt_bsStoreUInt64/gt_bsGetUInt64: ");
  for (i = 0; i < numRnd; ++i)
  {
#if 64 > 32 && LONG_BIT < 64
    uint64_t v = randSrc[i] = (uint64_t)random() << 32 | random();
#else /* 64 > 32 && LONG_BIT < 64 */
    uint64_t v = randSrc[i] = random();
#endif /* 64 > 32 && LONG_BIT < 64 */
    int bits = gt_requiredUInt64Bits(v);
    gt_bsStoreUInt64(bitStore, offset, bits, v);
    offset += bits;
  }
  offset = offsetStart;
  for (i = 0; i < numRnd; ++i)
  {
    uint64_t v = randSrc[i];
    int bits = gt_requiredUInt64Bits(v);
    uint64_t r = gt_bsGetUInt64(bitStore, offset, bits);
    ensure(had_err, r == v);
    if (had_err)
    {
      gt_log_log("Expected %"PRIu64", got %"PRIu64", i = %lu\n",
              v, r, (unsigned long)i);
      freeResourcesAndReturn(had_err);
    }
    offset += bits;
  }
  gt_log_log("passed\n");
  if (numRnd > 0)
  {
    uint64_t v = randSrc[0], r = 0;
    unsigned numBits = gt_requiredUInt64Bits(v);
    BitOffset i = offsetStart + numBits;
    uint64_t mask = ~(uint64_t)0;
    if (numBits < 64)
      mask = ~(mask << numBits);
    gt_log_log("bsSetBit, gt_bsClearBit, bsToggleBit, gt_bsGetBit: ");
    while (v)
    {
      int lowBit = v & 1;
      v >>= 1;
      ensure(had_err, lowBit == (r = gt_bsGetBit(bitStore, --i)));
      if (had_err)
      {
        gt_log_log("Expected %d, got %d, i = %llu\n",
                lowBit, (int)r, (unsigned long long)i);
        freeResourcesAndReturn(had_err);
      }
    }
    i = offsetStart + numBits;
    gt_bsClear(bitStoreCopy, offsetStart, numBits, random()&1);
    v = randSrc[0];
    while (i)
    {
      int lowBit = v & 1;
      v >>= 1;
      if (lowBit)
        bsSetBit(bitStoreCopy, --i);
      else
        gt_bsClearBit(bitStoreCopy, --i);
    }
    v = randSrc[0];
    r = gt_bsGetUInt64(bitStoreCopy, offsetStart, numBits);
    ensure(had_err, r == v);
    if (had_err)
    {
      gt_log_log("Expected %"PRIu64", got %"PRIu64"\n", v, r);
      freeResourcesAndReturn(had_err);
    }
    for (i = 0; i < numBits; ++i)
      bsToggleBit(bitStoreCopy, offsetStart + i);
    r = gt_bsGetUInt64(bitStoreCopy, offsetStart, numBits);
    ensure(had_err, r == (v = (~v & mask)));
    if (had_err)
    {
      gt_log_log("Expected %"PRIu64", got %"PRIu64"\n", v, r);
//.........这里部分代码省略.........
开发者ID:jamescasbon,项目名称:genometools,代码行数:101,代码来源:checkbitpackstring64.c

示例5: GetFocusedMovieScene

FGuid FSequencer::AddSpawnableForAssetOrClass( UObject* Object, UObject* CounterpartGamePreviewObject )
{
	FGuid NewSpawnableGuid;
	
	if( ObjectBindingManager->AllowsSpawnableObjects() )
	{
		// Grab the MovieScene that is currently focused.  We'll add our Blueprint as an inner of the
		// MovieScene asset.
		UMovieScene* OwnerMovieScene = GetFocusedMovieScene();

		// @todo sequencer: Undo doesn't seem to be working at all
		const FScopedTransaction Transaction( LOCTEXT("UndoAddingObject", "Add Object to MovieScene") );

		// Use the class as the spawnable's name if this is an actor class, otherwise just use the object name (asset)
		const bool bIsActorClass = Object->IsA( AActor::StaticClass() ) && !Object->HasAnyFlags( RF_ArchetypeObject );
		const FName AssetName = bIsActorClass ? Object->GetClass()->GetFName() : Object->GetFName();

		// Inner objects don't need a name (it will be auto-generated by the UObject system), but we want one in this case
		// because the class of any actors that are created from this Blueprint may end up being user-facing.
		const FName BlueprintName = MakeUniqueObjectName( OwnerMovieScene, UBlueprint::StaticClass(), AssetName );

		// Use the asset name as the initial spawnable name
		const FString NewSpawnableName = AssetName.ToString();		// @todo sequencer: Need UI to allow user to rename these slots

		// Create our new blueprint!
		UBlueprint* NewBlueprint = NULL;
		{
			// @todo sequencer: Add support for forcing specific factories for an asset
			UActorFactory* FactoryToUse = NULL;
			if( bIsActorClass )
			{
				// Placing an actor class directly::
				FactoryToUse = GEditor->FindActorFactoryForActorClass( Object->GetClass() );
			}
			else
			{
				// Placing an asset
				FactoryToUse = FActorFactoryAssetProxy::GetFactoryForAssetObject( Object );
			}

			if( FactoryToUse != NULL )
			{
				// Create the blueprint
				NewBlueprint = FactoryToUse->CreateBlueprint( Object, OwnerMovieScene, BlueprintName );
			}
			else if( bIsActorClass )
			{
				// We don't have a factory, but we can still try to create a blueprint for this actor class
				NewBlueprint = FKismetEditorUtilities::CreateBlueprint( Object->GetClass(), OwnerMovieScene, BlueprintName, EBlueprintType::BPTYPE_Normal, UBlueprint::StaticClass(), UBlueprintGeneratedClass::StaticClass() );
			}
		}

		if( ensure( NewBlueprint != NULL ) )
		{
			if( NewBlueprint->GeneratedClass != NULL && FBlueprintEditorUtils::IsActorBased( NewBlueprint ) )
			{
				AActor* ActorCDO = CastChecked< AActor >( NewBlueprint->GeneratedClass->ClassDefaultObject );

				// If we have a counterpart object, then copy the properties from that object back into our blueprint's CDO
				// @todo sequencer livecapture: This isn't really good enough to handle complex actors.  The dynamically-spawned actor could have components that
				// were created in its construction script or via straight-up C++ code.  Instead what we should probably do is duplicate the PIE actor and generate
				// our CDO from that duplicate.  It could get pretty complex though.
				if( CounterpartGamePreviewObject != NULL )
				{
					AActor* CounterpartGamePreviewActor = CastChecked< AActor >( CounterpartGamePreviewObject );
					CopyActorProperties( CounterpartGamePreviewActor, ActorCDO );
				}
				else
				{
					// Place the new spawnable in front of the camera (unless we were automatically created from a PIE actor)
					PlaceActorInFrontOfCamera( ActorCDO );
				}
			}

			NewSpawnableGuid = OwnerMovieScene->AddSpawnable( NewSpawnableName, NewBlueprint, CounterpartGamePreviewObject );

			if (IsShotFilteringOn())
			{
				AddUnfilterableObject(NewSpawnableGuid);
			}
		}
	
	}

	return NewSpawnableGuid;
}
开发者ID:johndpope,项目名称:UE4,代码行数:86,代码来源:Sequencer.cpp

示例6: ensure

void FSlateFileDialogsStyle::Shutdown()
{
	FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
	ensure(StyleInstance.IsUnique());
	StyleInstance.Reset();
}
开发者ID:PickUpSU,项目名称:UnrealEngine4,代码行数:6,代码来源:SlateFileDialogsStyles.cpp

示例7: w

void testObj::test<1>(void)
{
  const FormatterConfig::Wrapper w(value_);
  ensure("invalid value type", w.isValue() );
}
开发者ID:el-bart,项目名称:ACARM-ng,代码行数:5,代码来源:FormatterConfig.t.cpp

示例8: re

void testObj::test<11>(void)
{
  const RegExp re("ab+", false);
  ensure("case-insensitive regexp does not match valid string", re.check("AB") );
}
开发者ID:el-bart,项目名称:ACARM-ng,代码行数:5,代码来源:RegExp.t.cpp

示例9: ensure

void FPLUGIN_NAMEStyle::Shutdown()
{
	FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
	ensure(StyleInstance.IsUnique());
	StyleInstance.Reset();
}
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:6,代码来源:PLUGIN_NAMEStyle.cpp

示例10: set_test_name

void lllogininstance_object::test<2>()
{
    set_test_name("Test User TOS/Critical message Interaction");

    const std::string test_uri = "testing-uri";

    // Test default connect.
    logininstance->connect(test_uri, agentCredential);

    // connect should call LLLogin::connect to init gLoginURI and gLoginCreds.
    ensure_equals("Default connect uri", gLoginURI, "testing-uri");
    ensure_equals("Default for agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), false);
    ensure_equals("Default for read critical", gLoginCreds["params"]["read_critical"].asBoolean(), false);

    // TOS failure response.
    LLSD response;
    response["state"] = "offline";
    response["change"] = "fail.login";
    response["progress"] = 0.0;
    response["transfer_rate"] = 7;
    response["data"]["reason"] = "tos";
    gTestPump.post(response);

    ensure_equals("TOS Dialog type", gTOSType, "message_tos");
    ensure("TOS callback given", gTOSReplyPump != 0);
    gTOSReplyPump->post(false); // Call callback denying TOS.
    ensure("No TOS, failed auth", logininstance->authFailure());

    // Start again.
    logininstance->connect(test_uri, agentCredential);
    gTestPump.post(response); // Fail for tos again.
    gTOSReplyPump->post(true); // Accept tos, should reconnect w/ agree_to_tos.
    ensure_equals("Accepted agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), true);
    ensure("Incomplete login status", !logininstance->authFailure() && !logininstance->authSuccess());

    // Fail connection, attempt connect again.
    // The new request should have reset agree to tos to default.
    response["data"]["reason"] = "key"; // bad creds.
    gTestPump.post(response);
    ensure("TOS auth failure", logininstance->authFailure());

    logininstance->connect(test_uri, agentCredential);
    ensure_equals("Reset to default for agree to tos", gLoginCreds["params"]["agree_to_tos"].asBoolean(), false);

    // Critical Message failure response.
    logininstance->connect(test_uri, agentCredential);
    response["data"]["reason"] = "critical"; // Change response to "critical message"
    gTestPump.post(response);

    ensure_equals("TOS Dialog type", gTOSType, "message_critical");
    ensure("TOS callback given", gTOSReplyPump != 0);
    gTOSReplyPump->post(true);
    ensure_equals("Accepted read critical message", gLoginCreds["params"]["read_critical"].asBoolean(), true);
    ensure("Incomplete login status", !logininstance->authFailure() && !logininstance->authSuccess());

    // Fail then attempt new connection
    response["data"]["reason"] = "key"; // bad creds.
    gTestPump.post(response);
    ensure("TOS auth failure", logininstance->authFailure());
    logininstance->connect(test_uri, agentCredential);
    ensure_equals("Default for agree to tos", gLoginCreds["params"]["read_critical"].asBoolean(), false);
}
开发者ID:CaseyraeStarfinder,项目名称:Firestorm-Viewer,代码行数:62,代码来源:lllogininstance_test.cpp

示例11: ls

void testObj::test<2>(void)
{
  const LimitedNULLString<10> ls(NULL);
  ensure("unable to stroe NULL", ls.get()==NULL);
}
开发者ID:el-bart,项目名称:ACARM-ng,代码行数:5,代码来源:LimitedNULLString.t.cpp

示例12: ls1

void testObj::test<13>(void)
{
  const LimitedNULLString<10> ls1(NULL);
  const LimitedNULLString<10> ls2(NULL);
  ensure("NULL stirngs differ", ls1==ls2);
}
开发者ID:el-bart,项目名称:ACARM-ng,代码行数:6,代码来源:LimitedNULLString.t.cpp

示例13: ensure

 void object::test<1>()
 {
     // TODO - mloskot - discuss about adding default constructor
     ensure("NOTE: Coordinate has no default constructor.", true);
 }
开发者ID:AvlWx2014,项目名称:basemap,代码行数:5,代码来源:CoordinateTest.cpp

示例14: ensure

void UK2Node_Composite::PostPasteNode()
{
	Super::PostPasteNode();

	//@TODO: Should verify that each node in the composite can be pasted into this new graph successfully (CanPasteHere)

	if (BoundGraph != NULL)
	{
		UEdGraph* ParentGraph = CastChecked<UEdGraph>(GetOuter());
		ensure(BoundGraph != ParentGraph);

		// Update the InputSinkNode / OutputSourceNode pointers to point to the new graph
		TSet<UEdGraphNode*> BoundaryNodes;
		for (int32 NodeIndex = 0; NodeIndex < BoundGraph->Nodes.Num(); ++NodeIndex)
		{
			UEdGraphNode* Node = BoundGraph->Nodes[NodeIndex];
			
			//Remove this node if it should not exist more then one in blueprint
			if(UK2Node_Event* Event = Cast<UK2Node_Event>(Node))
			{
				UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForGraphChecked(BoundGraph);
				if(FBlueprintEditorUtils::FindOverrideForFunction(BP, Event->EventReference.GetMemberParentClass(Event), Event->EventReference.GetMemberName()))
				{
					FBlueprintEditorUtils::RemoveNode(BP, Node, true);
					NodeIndex--;
					continue;
				}
			}
			
			BoundaryNodes.Add(Node);

			if (Node->GetClass() == UK2Node_Tunnel::StaticClass())
			{
				// Exactly a tunnel node, should be the entrance or exit node
				UK2Node_Tunnel* Tunnel = CastChecked<UK2Node_Tunnel>(Node);

				if (Tunnel->bCanHaveInputs && !Tunnel->bCanHaveOutputs)
				{
					OutputSourceNode = Tunnel;
					Tunnel->InputSinkNode = this;
				}
				else if (Tunnel->bCanHaveOutputs && !Tunnel->bCanHaveInputs)
				{
					InputSinkNode = Tunnel;
					Tunnel->OutputSourceNode = this;
				}
				else
				{
					ensureMsgf(false, *LOCTEXT("UnexpectedTunnelNode", "Unexpected tunnel node '%s' in cloned graph '%s' (both I/O or neither)").ToString(), *Tunnel->GetName(), *GetName());
				}
			}
		}

		RenameBoundGraphCloseToName(BoundGraph->GetName());
		ensure(BoundGraph->SubGraphs.Find(ParentGraph) == INDEX_NONE);

		//Nested composites will already be in the SubGraph array
		if(ParentGraph->SubGraphs.Find(BoundGraph) == INDEX_NONE)
		{
			ParentGraph->SubGraphs.Add(BoundGraph);
		}

		FEdGraphUtilities::PostProcessPastedNodes(BoundaryNodes);
	}
}
开发者ID:Codermay,项目名称:Unreal4,代码行数:65,代码来源:K2Node_Composite.cpp

示例15: ensure

void SGameplayTagQueryWidget::Construct(const FArguments& InArgs, const TArray<FEditableGameplayTagQueryDatum>& EditableTagQueries)
{
	ensure(EditableTagQueries.Num() > 0);
	TagQueries = EditableTagQueries;

	bReadOnly = InArgs._ReadOnly;
	OnSaveAndClose = InArgs._OnSaveAndClose;
	OnCancel = InArgs._OnCancel;

	// Tag the assets as transactional so they can support undo/redo
	for (int32 AssetIdx = 0; AssetIdx < TagQueries.Num(); ++AssetIdx)
	{
		UObject* TagQueryOwner = TagQueries[AssetIdx].TagQueryOwner.Get();
		if (TagQueryOwner)
		{
			TagQueryOwner->SetFlags(RF_Transactional);
		}
	}

	// build editable query object tree from the runtime query data
	UEditableGameplayTagQuery* const EQ = CreateEditableQuery(*TagQueries[0].TagQuery);
	EditableQuery = EQ;

	// create details view for the editable query object
	FDetailsViewArgs ViewArgs;
	ViewArgs.bAllowSearch = false;
	ViewArgs.bHideSelectionTip = true;
	ViewArgs.bShowActorLabel = false;
	
	FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
	Details = PropertyModule.CreateDetailView(ViewArgs);
	Details->SetObject(EQ);

	ChildSlot
	[
		SNew(SScaleBox)
		.HAlign(EHorizontalAlignment::HAlign_Left)
		.VAlign(EVerticalAlignment::VAlign_Top)
		.StretchDirection(EStretchDirection::DownOnly)
		.Stretch(EStretch::ScaleToFit)
		.Content()
		[
			SNew(SBorder)
			.BorderImage(FEditorStyle::GetBrush("ToolPanel.GroupBorder"))
			[
				SNew(SVerticalBox)
				+ SVerticalBox::Slot()
				.AutoHeight()
				.VAlign(VAlign_Top)
				[
					SNew(SHorizontalBox)
					+ SHorizontalBox::Slot()
					.AutoWidth()
					[
						SNew(SButton)
						.IsEnabled(!bReadOnly)
						.OnClicked(this, &SGameplayTagQueryWidget::OnSaveAndCloseClicked)
						.Text(LOCTEXT("GameplayTagQueryWidget_SaveAndClose", "Save and Close"))
					]
					+ SHorizontalBox::Slot()
					.AutoWidth()
					[
						SNew(SButton)
						.OnClicked(this, &SGameplayTagQueryWidget::OnCancelClicked)
						.Text(LOCTEXT("GameplayTagQueryWidget_Cancel", "Close Without Saving"))
					]
				]
				// to delete!
				+ SVerticalBox::Slot()
				[
					Details.ToSharedRef()
				]
			]
		]
	];
}
开发者ID:didixp,项目名称:Ark-Dev-Kit,代码行数:76,代码来源:SGameplayTagQueryWidget.cpp


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