Beispiel #1
0
  retptr
  BoundaryCondition::getClass(const magnet::xml::Node& XML, dynamo::Simulation* tmp)
  {
    if (!XML.getAttribute("Type").getValue().compare("None")
	|| !XML.getAttribute("Type").getValue().compare("Null"))
      return retptr(new BCNone(tmp));
    else if (!XML.getAttribute("Type").getValue().compare("PBC"))
      return retptr(new BCPeriodic(tmp));
    else if (!XML.getAttribute("Type").getValue().compare("NoXPBC"))
      return retptr(new BCPeriodicExceptX(tmp));
    else if (!XML.getAttribute("Type").getValue().compare("OnlyXPBC"))
      return retptr(new BCPeriodicXOnly(tmp));
    else if (!XML.getAttribute("Type").getValue().compare("LE"))
      return retptr(new BCLeesEdwards(XML,tmp));
    else 
      M_throw() << XML.getAttribute("Type").getValue()
		<< ", Unknown type of boundary encountered";
  }
buf_share_ptr 
h264MediaStream::GetNode()
{
	if (bufferlist.size())
	{
		Buffer* ret = bufferlist.front();
		bufferlist.pop();
		buf_share_ptr retptr(ret);
		return retptr;
	}
    buf_share_ptr ret(new Buffer(0));
    return ret;
}
/**
Finds the keystring from the source string and replaces it with the
replacement string.
*/
HBufC* CResourceLoader::FormatStringL(const TDesC& aSource, const TDesC& aKey, const TDesC& aSubs, TBidiText::TDirectionality aDirectionality,
    TInt& aParamCount, TInt aSubCount)
    {
    if (aParamCount == KUnknownCount)
        aParamCount = GetParamCount(aSource);

    if (aSubCount == KUnknownCount)
        aSubCount = GetSubStringCount(aSource);

    // determine lenght of needed buffer 
    TInt sourcelength(aSource.Length()); 
    TInt keylength(aKey.Length());
    TInt subslength(aSubs.Length());
    TInt destlength = 0;
    if (subslength >= keylength)
        {
        destlength = sourcelength + ((subslength - keylength) * aParamCount);
        }
    else
        {
        destlength = sourcelength;
        }

    destlength += KExtraSpaceForMainStringDirMarker * aSubCount;
    destlength += KExtraSpaceForSubStringDirMarkers * aParamCount;
    //
    // Allocating heap buffer for return string.
    //

    HBufC* retbuf = HBufC::NewL(destlength);
    TPtr retptr(retbuf->Des());

    // Formating the resource string. Don't bother with format, 
    // if parameter count is not above zero
    if (aParamCount > 0)
        {
        aParamCount -= Formater(retptr, aSource, aKey, aSubs, aDirectionality);
        __ASSERT_DEBUG(aParamCount >= 0, User::Invariant());
        }

    //
    // If the key string wasn't found, retbuf is empty.
    //
    return retbuf; 
    }
EXPORT_C HBufC* CResourceLoader::Load2L( TInt aResourceId, const TDesC& aString )
    {
    HBufC* resbuf = Load2LC( aResourceId );
    TPtr retptr(resbuf->Des());
        
    // Get number of sub strings
    TInt count = GetSubStringCount( retptr ); 
    TBool marker(EFalse); 
    
    if (count >= 1)
        {
        HBufC* buffer = ResolveSubStringDirsL( retptr, count, &marker );
        CleanupStack::PushL(buffer);
        
        TBool found(EFalse);
        TBidiText::TDirectionality mainDir = DirectionalityL(*buffer , &found);
        
        //Formating the return string with FormatStringL.
        HBufC* retbuf = FormatStringL(*buffer, KStringKeyBuf, aString, mainDir);
        
        CleanupStack::PopAndDestroy(buffer);
        CleanupStack::PopAndDestroy(resbuf);
                        
        if (marker && retbuf->Length())
            {
            TPtr ptr = retbuf->Des();
            RemoveNoDirMarkers(ptr);
            } 
            
        __ASSERT_DEBUG(retbuf->Length(), 
                    User::Panic(KPanicCategory, EKeyStringNotFound));    
        return retbuf;
        }
     else
        {
        CleanupStack::PopAndDestroy(resbuf);
        HBufC* retbuf = HBufC::NewL(0); // return empty buffer
        __ASSERT_DEBUG(retbuf->Length(), 
                    User::Panic(KPanicCategory, EKeyStringNotFound));
        return retbuf;
        }
    }
HBufC* CResourceLoader::ResolveSubStringDirsL(TDes& aText, TInt aCount, TBool* aMarker)
    {   
    // Allocating heap buffer for return string.
    TInt destlength(aText.Length());
    destlength = destlength + (KExtraSpaceForMainStringDirMarker) * aCount;
    HBufC* retbuf = HBufC::NewLC(destlength);
    TPtr retptr(retbuf->Des());
    TInt freeSpace(destlength); 
    TInt i(0);
    TInt j(0);
    TBuf<1> subsMarker;
    subsMarker.Append(KSubStringSeparator);
    TInt count(aCount - 1);

    while (i  < aCount)
        {
        // Resolve sub string
        HBufC* buffer = ResolveSubStringL(aText, aMarker);
        TPtr ptr = buffer->Des();
        CleanupStack::PushL(buffer); 
        
        // Restore sub string separators
        if (freeSpace >= ptr.Length()) 
            {
            retptr.Insert(j, ptr);
            freeSpace -= ptr.Length();
            j += ptr.Length();
            if (freeSpace > KExtraSpaceForMainStringDirMarker && i < count)
                {
                retptr.Append(subsMarker);
                j ++;
                }
            }    
        CleanupStack::PopAndDestroy(buffer);  
        i++;                       
        } 
    
    retbuf = retbuf->ReAllocL(retptr.Length());
    CleanupStack::Pop(); //retbuf  
    return retbuf;
    }
/**
Resolves sub string and directionality of the sub string.
Adds no dir marker if directionality of the string not found.
*/
HBufC* CResourceLoader::ResolveSubStringL(TDes& aText, TBool* aMarker)
    {
    // Allocating heap buffer for return string.
    TInt destlength(aText.Length());
    HBufC* retbuf = HBufC::NewLC(destlength + 1); // no dir marker
    TPtr retptr(retbuf->Des());
    
    TBuf<1> marker;
    marker.Append(KDirNotFound);
        
    TPtrC remainder = aText.Right(aText.Length());
    TInt nextKey = remainder.Locate(KSubStringSeparator);
    
    if (nextKey == 0)
        {
        remainder.Set(remainder.Mid(1));
        nextKey = remainder.Locate(KSubStringSeparator);
        if (nextKey != KErrNotFound)
            {
            retptr.Insert(0, aText.Mid(1, nextKey));           
            // Remove string from aText
            aText.Delete(0, nextKey + 1);
            }
        else
            {
            TInt length = aText.Length();
            retptr.Insert(0, aText.Mid(1, length - 1));
            // Remove string from aText
            aText.Delete(0, length);
            }
        }
    else if (nextKey == KErrNotFound)
        {
        retptr.Insert(0, aText); 
        // Remove string from aText
        aText.Delete(0, aText.Length());
        }
    else
        {
        retptr.Insert(0, aText.Mid(0, nextKey));
        // Remove string from aText
        aText.Delete(0, nextKey);
        }
     
    // Resolve directionality of sub string
    HBufC* dirbuf = retbuf->AllocL();
    TPtr dirptr = dirbuf->Des();
    TBool found(EFalse);
    TBidiText::TDirectionality mainDir = ResolveDirectionality(dirptr, &found);
    delete dirbuf;
    
    if (!found)
        {
        retptr.Insert(0, marker);
        *aMarker = ETrue;
        }
    else
        {
        *aMarker = EFalse;
        }
        
    retbuf = retbuf->ReAllocL(retptr.Length());
    CleanupStack::Pop(); //retbuf
    // If the key string wasn't found, retbuf is empty.
    return retbuf;     
    }