Exemple #1
0
//-----------------------------------------------------------------------------
// Purpose: extracts the value of the xml attrib "attribName"
//-----------------------------------------------------------------------------
CUtlSymbol CVCProjConvert::GetXMLAttribValue( IXMLDOMElement *p, const char *attribName )
{
	if (!p) 
	{
		return CUtlSymbol();
	}

#ifdef _WIN32
	VARIANT vtValue;
	p->getAttribute( _bstr_t(attribName), &vtValue);
	if ( vtValue.vt == VT_NULL )
	{
		return CUtlSymbol(); // element not found
	}

	Assert( vtValue.vt == VT_BSTR );
	CUtlSymbol name( static_cast<char *>( _bstr_t( vtValue.bstrVal ) ) );
	::SysFreeString(vtValue.bstrVal);
#elif _LINUX
	const XMLCh *xAttrib = XMLString::transcode( attribName );
	const XMLCh *value = p->getAttribute( xAttrib );
	if ( value == NULL )
	{
		return CUtlSymbol(); // element not found
        }
	char *transValue = XMLString::transcode(value);
	CUtlSymbol name( transValue );
	XMLString::release( &xAttrib );
	XMLString::release( &transValue );
#endif
	return name;

}
CUtlSymbol CUtlSymbolTable::Find( char const* pString )
{	
	if (!pString)
		return CUtlSymbol();
	
	// Store a special context used to help with insertion
	g_LessCtx.m_pUserString = pString;
	g_LessCtx.m_pTable = this;
	
	// Passing this special invalid symbol makes the comparison function
	// use the string passed in the context
	UtlSymId_t idx = m_Lookup.Find( INVALID_STRING_INDEX );
	return CUtlSymbol( idx );
}
Exemple #3
0
CUtlSymbol CUtlSymbolTable::AddString( char const* pString )
{
    if (!pString)
        return CUtlSymbol( UTL_INVAL_SYMBOL );

    CUtlSymbol id = Find( pString );

    //g_SymbolCS.Lock( );

    if (id.IsValid())
    {
        //g_SymbolCS.Unlock( );
        return id;
    }

    // Store a special context used to help with insertion
    g_LessCtx.m_pUserString = pString;
    g_LessCtx.m_pTable = this;

    // didn't find, insert the string into the vector.
    int len = strlen(pString) + 1;
    int stridx = m_Strings.AddMultipleToTail( len );
    memcpy( &m_Strings[stridx], pString, len * sizeof(char) );
    UtlSymId_t idx = m_Lookup.Insert( stridx );
    CUtlSymbol syRet( idx );

    //g_SymbolCS.Unlock( );

    return syRet;
}
Exemple #4
0
CUtlSymbol CUtlSymbolTable::Find( const char* pString ) const
{	
	if (!pString)
		return CUtlSymbol();
	
	// Store a special context used to help with insertion
	m_pUserSearchString = pString;
	
	// Passing this special invalid symbol makes the comparison function
	// use the string passed in the context
	UtlSymId_t idx = m_Lookup.Find( INVALID_STRING_INDEX );

#ifdef _DEBUG
	m_pUserSearchString = NULL;
#endif

	return CUtlSymbol( idx );
}
Exemple #5
0
CUtlSymbol CUtlSymbolTable::AddString( const char* pString )
{
	if (!pString) 
		return CUtlSymbol( UTL_INVAL_SYMBOL );

	CUtlSymbol id = Find( pString );
	
	if (id.IsValid())
		return id;

	int len = strlen(pString) + 1;

	// Find a pool with space for this string, or allocate a new one.
	int iPool = FindPoolWithSpace( len );
	if ( iPool == -1 )
	{
		// Add a new pool.
		int newPoolSize = max( len, MIN_STRING_POOL_SIZE );
		StringPool_t *pPool = (StringPool_t*)malloc( sizeof( StringPool_t ) + newPoolSize - 1 );
		pPool->m_TotalLen = newPoolSize;
		pPool->m_SpaceUsed = 0;
		iPool = m_StringPools.AddToTail( pPool );
	}

	// Copy the string in.
	StringPool_t *pPool = m_StringPools[iPool];
	Assert( pPool->m_SpaceUsed < 0xFFFF );	// This should never happen, because if we had a string > 64k, it
											// would have been given its entire own pool.
	
	unsigned short iStringOffset = pPool->m_SpaceUsed;

	memcpy( &pPool->m_Data[pPool->m_SpaceUsed], pString, len );
	pPool->m_SpaceUsed += len;

	// didn't find, insert the string into the vector.
	CStringPoolIndex index;
	index.m_iPool = iPool;
	index.m_iOffset = iStringOffset;

	UtlSymId_t idx = m_Lookup.Insert( index );
	return CUtlSymbol( idx );
}