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


C++ DynamicArray::Reserve方法代码示例

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


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

示例1: PrintArrayInfo

TEST(DataStructures, DynamicArray)
{
    {
        DynamicArray< int > intArray;
        intArray.Reserve( 3 );
        intArray.Add( 4 );
        //intArray.Add( 2 );
        HELIUM_VERIFY( intArray.New( 2 ) );
        intArray.Add( 8 );
        intArray.Add( 9 );
        intArray.Trim();

        PrintArrayInfo( TXT( "intArray" ), intArray );
    }

    {
        DynamicArray< NonTrivialClass > objectArray;
        objectArray.Reserve( 3 );
        objectArray.Add( NonTrivialClass( 4.3f ) );
        objectArray.Add( NonTrivialClass( 12.4f ) );
        objectArray.Add( NonTrivialClass( -3.9f ) );
        objectArray.Add( NonTrivialClass( 0.5f ) );
        objectArray.Add( NonTrivialClass( 2.9f ) );
        objectArray.Add( NonTrivialClass( -15.8f ) );
        objectArray.RemoveSwap( 1, 2 );
        objectArray.Trim();

        PrintArrayInfo( TXT( "objectArray" ), objectArray );
    }
}
开发者ID:KETMGaming,项目名称:Helium,代码行数:30,代码来源:GTest_Misc.cpp

示例2: Initialize

/// @copydoc CommandLineInitializer::Initialize()
bool CommandLineInitializationWin::Initialize( String& rModuleName, DynamicArray< String >& rArguments )
{
    rModuleName.Clear();
    rArguments.Clear();

    // Get the module file name and full command-line string (must use the wide-character versions, as there is only
    // a CommandLineToArgvW() and not a CommandLineToArgvA() to parse the command-line string).
    LPWSTR pCommandLine = GetCommandLineW();
    HELIUM_ASSERT( pCommandLine );
    if( !pCommandLine )
    {
        HELIUM_TRACE(
            TraceLevels::Error,
            TXT( "CommandLineInitializationWin::Initialize(): Failed to retrieve command-line string.\n" ) );

        return false;
    }

    WCHAR moduleFileName[ MAX_PATH ];
    DWORD moduleFileNameLength = GetModuleFileNameW( NULL, moduleFileName, MAX_PATH );
    if( moduleFileNameLength == 0 )
    {
        HELIUM_TRACE(
            TraceLevels::Error,
            TXT( "CommandLineInitializationWin::Initialize(): Failed to retrieve module file name string.\n" ) );

        return false;
    }

    moduleFileName[ MAX_PATH - 1 ] = L'\0';
    moduleFileNameLength = Min< DWORD >( moduleFileNameLength, MAX_PATH - 1 );

    // If the command line contains just the module file name, don't parse it and simply store the module name
    // (if no command-line arguments are specified, GetCommandLine() may return a string containing just the module
    // name without quoting it, which would in turn cause CommandLineToArgvW() to split the module path if it
    // contains any spaces).
    if( CompareString( pCommandLine, moduleFileName ) == 0 )
    {
        StringConverter< wchar_t, tchar_t >::Convert( rModuleName, moduleFileName );

        return true;
    }

    // Parse the command-line string.
    int argumentCount = 0;
    LPWSTR* ppArguments = CommandLineToArgvW( pCommandLine, &argumentCount );
    HELIUM_ASSERT( ppArguments );
    if( !ppArguments )
    {
        HELIUM_TRACE(
            TraceLevels::Error,
            TXT( "CommandLineInitializationWin::Initialize(): Failed to parse command-line arguments.\n" ) );

        return false;
    }

    StringConverter< wchar_t, tchar_t >::Convert( rModuleName, moduleFileName );

    if( argumentCount > 1 )
    {
        rArguments.Reserve( argumentCount - 1 );

        for( int argumentIndex = 1; argumentIndex < argumentCount; ++argumentIndex )
        {
            LPWSTR pArgument = ppArguments[ argumentIndex ];
            HELIUM_ASSERT( pArgument );
            String* pConvertedArgument = rArguments.New();
            HELIUM_ASSERT( pConvertedArgument );
            StringConverter< wchar_t, tchar_t >::Convert( *pConvertedArgument, pArgument );
        }
    }

    LocalFree( ppArguments );

    return true;
}
开发者ID:foolhuang,项目名称:Helium,代码行数:77,代码来源:CommandLineInitializerWin.cpp

示例3: TryFinishLoadObject

/// @copydoc PackageLoader::TryFinishLoadObject()
bool CachePackageLoader::TryFinishLoadObject(
    size_t requestId,
    GameObjectPtr& rspObject,
    DynamicArray< GameObjectLoader::LinkEntry >& rLinkTable )
{
    HELIUM_ASSERT( requestId < m_loadRequests.GetSize() );
    HELIUM_ASSERT( m_loadRequests.IsElementValid( requestId ) );

    LoadRequest* pRequest = m_loadRequests[ requestId ];
    HELIUM_ASSERT( pRequest );
    if( !( pRequest->flags & LOAD_FLAG_PRELOADED ) )
    {
        return false;
    }

    // Sync on template and owner dependencies.
    GameObjectLoader* pObjectLoader = GameObjectLoader::GetStaticInstance();
    HELIUM_ASSERT( pObjectLoader );

    DynamicArray< size_t >& rInternalLinkTable = pRequest->objectLinkTable;

    if( IsValid( pRequest->templateLinkIndex ) )
    {
        size_t linkLoadId = rInternalLinkTable[ pRequest->templateLinkIndex ];
        if( IsValid( linkLoadId ) && !pObjectLoader->TryFinishLoad( linkLoadId, pRequest->spTemplate ) )
        {
            return false;
        }

        SetInvalid( pRequest->templateLinkIndex );
    }

    if( IsValid( pRequest->ownerLinkIndex ) )
    {
        size_t linkLoadId = rInternalLinkTable[ pRequest->ownerLinkIndex ];
        if( IsValid( linkLoadId ) && !pObjectLoader->TryFinishLoad( linkLoadId, pRequest->spOwner ) )
        {
            return false;
        }

        SetInvalid( pRequest->ownerLinkIndex );
    }

    rspObject = pRequest->spObject;
    GameObject* pObject = rspObject;
    if( pObject && ( pRequest->flags & LOAD_FLAG_ERROR ) )
    {
        pObject->SetFlags( GameObject::FLAG_BROKEN );
    }

    pRequest->spObject.Release();

    size_t linkTableSize = rInternalLinkTable.GetSize();
    rLinkTable.Resize( 0 );
    rLinkTable.Reserve( linkTableSize );
    for( size_t linkIndex = 0; linkIndex < linkTableSize; ++linkIndex )
    {
        GameObjectLoader::LinkEntry* pEntry = rLinkTable.New();
        HELIUM_ASSERT( pEntry );
        pEntry->loadId = rInternalLinkTable[ linkIndex ];
        pEntry->spObject.Release();
    }

    rInternalLinkTable.Resize( 0 );

    HELIUM_ASSERT( IsInvalid( pRequest->asyncLoadId ) );
    HELIUM_ASSERT( !pRequest->pAsyncLoadBuffer );

    pRequest->spType.Release();
    pRequest->spTemplate.Release();
    pRequest->spOwner.Release();
    pRequest->typeLinkTable.Resize( 0 );

    HELIUM_ASSERT( pObject || pRequest->pEntry );
    HELIUM_TRACE(
        TraceLevels::Debug,
        ( TXT( "CachePackageLoader::TryFinishLoadObject(): Load request for \"%s\" (ID: %" ) TPRIuSZ TXT( ") " )
        TXT( "synced.\n" ) ),
        *( pObject ? pObject->GetPath() : pRequest->pEntry->path ).ToString(),
        requestId );

    m_loadRequests.Remove( requestId );
    m_loadRequestPool.Release( pRequest );

    return true;
}
开发者ID:foolhuang,项目名称:Helium,代码行数:87,代码来源:CachePackageLoader.cpp


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