Exemplo n.º 1
0
bool
sd::core::AttributeKey::addNewKey(const std::string& name) {
  if(containsKey(name))
    return false;
  m_existingKeys.push_back(AttributeKey(name));
  return true;
}
Exemplo n.º 2
0
char*
XMLEntity::ToString(bool encoded, int level)
{
	string text = "";
	string indent = "";
	string character_data = EscapeText(CharacterData());

	for(int i=0; i<level; ++i) indent += "\t";
	
	text  = indent;
	text += "<";
	text += Name();

	for(int i=0; i < CountAttributes(); ++i) {
		text += " ";
		text += AttributeKey(i);
		text += "=";
		text += "\"";
		text += EscapeText(AttributeValue(i));
		text += "\"";
	}

	if (character_data.size() == 0 && CountChildren() == 0)	text += "/";
	text += ">";
	text += character_data;

	if (CountChildren() > 0)
	{
		text += "\n";

		for (int i=0; i < CountChildren(); ++i)
		{
			char *str = Child(i)->ToString(encoded, level + 1);
			if (str)
			{
				text += str;
				free(str);
			}
		}
		
		text += indent;
	}

	if (CountChildren() > 0 || character_data.size() > 0)
	{
		text += "</";
		text += Name();
		text += ">";
	}

	text += "\n";

	return strdup(text.c_str());	
}
Exemplo n.º 3
0
void Context::addAttributes( std::map<text::attributes::AttributeKey,text::attributes::AttributeValue> & attributes, const Alternative::BindingMap & bindings ) const {
	for ( Alternative::BindingMap::const_iterator it = bindings.begin(), e = bindings.end(); it != e; ++ it ) {
		Expression::ValueListPtr v = it->second->evaluate( 0, Variable(), *this );
		AttributeKey key = it->first;
		AttributeValue value = v->empty() ? AttributeValue::UNDEFINED : v->back();

		if ( key == AttributeKey::UNDEFINED ) {
			for ( uint attr = 0; attr < AttributeKey::count(); ++ attr ) {
				AttributeKey k = AttributeKey( attr );
				AttributeValue v = value.getContainer().getAttribute( k );

				if ( v != AttributeValue::UNDEFINED )
					attributes.insert( std::make_pair( k, v ) );
			}
		} else {
			attributes.insert( std::make_pair( key, value ) );
		}
	}
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
// Name : BuildAttributeTable ()
// Desc : Build a list of combined textures / materials etc. in addition to a
//        per-surface attribute ID.
//-----------------------------------------------------------------------------
bool iwfMesh::BuildAttributeTable()
{
    unsigned __int16 AttributeCapacity = 0;
    Attribute   ** ppTempAttributes = NULL, *pAttribute = NULL, TestAttribute;
    AttributeKey * pLookupRoot      = NULL, *pAttributeKey = NULL;

    // Release previous attribute details if already built
    if ( Attributes != NULL )
    {
        for ( unsigned __int16 i = 0; i < AttributeCount; ++i )
        {
            if ( Attributes[i].TexIndices )
                delete []Attributes[i].TexIndices;
            if ( Attributes[i].MatIndices )
                delete []Attributes[i].MatIndices;
            if ( Attributes[i].ShaderIndices )
                delete []Attributes[i].ShaderIndices;
            if ( Attributes[i].SamplerIndices )
                delete []Attributes[i].SamplerIndices;
            if ( Attributes[i].BlendModes )
                delete []Attributes[i].BlendModes;

        } // Next Attribute
        delete []Attributes;
    
    } // End if attributes
    
    if ( AttributeTable != NULL )
        delete []AttributeTable;
    
    // Reset variables
    Attributes     = NULL;
    AttributeTable = NULL;
    AttributeCount = 0;

    // If there are no surfaces, just return here.
    if ( SurfacePool.SurfaceCount == 0 )
        return true;

    // Allocate enough space in the attribute table for all surfaces
    AttributeTable = new unsigned __int16[ SurfacePool.SurfaceCount ];

    // Iterate through each surface in the mesh
    for ( unsigned int i = 0; i < SurfacePool.SurfaceCount; ++i )
    {
        iwfSurfacePool::Surface * pSurface = &SurfacePool.Surfaces[i];

        // Collect attribute details for this surface
        TestAttribute.ChannelCount = pSurface->ChannelCount;
        TestAttribute.RenderEffect = ( pSurface->Components & IWF_SCOMPONENT_EFFECT ) ? pSurface->RenderEffect : -1;

        // Temporarily "borrow" the pointers from the surface (saves allocation)
        TestAttribute.TexIndices     = pSurface->TexIndices;
        TestAttribute.MatIndices     = pSurface->MatIndices;
        TestAttribute.ShaderIndices  = pSurface->ShaderIndices;
        TestAttribute.SamplerIndices = pSurface->SamplerIndices;
        TestAttribute.BlendModes     = pSurface->BlendModes;

        // Has relevant styles?
        TestAttribute.AlphaBlended = false;
        TestAttribute.AlphaTested  = false;
        if ( pSurface->Components & IWF_SCOMPONENT_STYLE )
        {
            if ( pSurface->Style & IWF_SURFACE_ALPHA_BLENDED )
                TestAttribute.AlphaBlended = true;
            else if ( pSurface->Style & IWF_SURFACE_ALPHA_TESTED )
                TestAttribute.AlphaTested = true;

        } // End if styles set
        
        // Check to see if blend modes were specified. If they were
        // activate the alpha blended flag if they're anything other
        // than the default.
        if ( TestAttribute.BlendModes )
        {
            // Any that are other than the default?
            for ( unsigned int j = 0; j < TestAttribute.ChannelCount; ++j )
            {
                if ( TestAttribute.BlendModes[j].SrcBlendMode != 0x2 /* BLEND_ONE */ ||
                    TestAttribute.BlendModes[j].DestBlendMode != 0x1 /* BLEND_ZERO */ )
                {
                    // Enable alpha blending for this attribute as a whole.
                    TestAttribute.AlphaBlended = true;
                    break;

                } // End if !ONE->ZERO

            } // Next channel

        } // End if has blend modes

        // Does this exist in the lookup table?
        pAttribute    = NULL;
        pAttributeKey = NULL;
        if ( pLookupRoot != NULL )
            pAttributeKey = pLookupRoot->find( &AttributeKey( &TestAttribute ) );
        
        // No attribute found, create a new one
        if ( pAttributeKey == NULL )
        {
            // Allocate a new attribute
            pAttribute = new Attribute();
            pAttribute->RenderEffect = TestAttribute.RenderEffect;
            pAttribute->ChannelCount = TestAttribute.ChannelCount;
            pAttribute->AlphaBlended = TestAttribute.AlphaBlended;
            pAttribute->AlphaTested  = TestAttribute.AlphaTested;
            if ( pSurface->TexIndices != NULL )
            {
                pAttribute->TexIndices = new __int16[ pSurface->ChannelCount ];
                memcpy( pAttribute->TexIndices, pSurface->TexIndices, pSurface->ChannelCount * 2 );
            
            } // End if textures specified
            if ( pSurface->MatIndices != NULL )
            {
                pAttribute->MatIndices = new __int16[ pSurface->ChannelCount ];
                memcpy( pAttribute->MatIndices, pSurface->MatIndices, pSurface->ChannelCount * 2 );
            
            } // End if materials specified
            if ( pSurface->ShaderIndices != NULL )
            {
                pAttribute->ShaderIndices = new __int16[ pSurface->ChannelCount ];
                memcpy( pAttribute->ShaderIndices, pSurface->ShaderIndices, pSurface->ChannelCount * 2 );
            
            } // End if shaders specified
            if ( pSurface->SamplerIndices != NULL )
            {
                pAttribute->SamplerIndices = new __int16[ pSurface->ChannelCount ];
                memcpy( pAttribute->SamplerIndices, pSurface->SamplerIndices, pSurface->ChannelCount * 2 );

            } // End if samplers specified
            if ( pSurface->BlendModes != NULL )
            {
                pAttribute->BlendModes = new iwfBlendMode[ pSurface->ChannelCount ];
                memcpy( pAttribute->BlendModes, pSurface->BlendModes, pSurface->ChannelCount * sizeof(iwfBlendMode) );
            
            } // End if blend modes specified

            // Insert into the attribute lookup table
            pAttributeKey = new AttributeKey( pAttribute, AttributeCount );
            if ( pLookupRoot == NULL )
                pLookupRoot = pAttributeKey;
            else
                pLookupRoot->insert( pAttributeKey );

            // Insert into the temporary attribute pointer table
            if ( AttributeCount + 1 > AttributeCapacity )
            {
                Attribute ** pBuffer = new Attribute*[AttributeCapacity+50];
                if ( ppTempAttributes != NULL )
                {
                    memcpy( pBuffer, ppTempAttributes, AttributeCount * sizeof(Attribute*) );
                    delete []ppTempAttributes;
                } // End if old data
                ppTempAttributes   = pBuffer;
                AttributeCapacity += 50;

            } // End if grow buffer
            ppTempAttributes[AttributeCount++] = pAttribute;

        } // End if not already inserted

        // Store the attribute ID for this surface
        AttributeTable[i] = pAttributeKey->nIndex;

    } // Next Surface

    // Build the final combined attribute table
    if ( AttributeCount > 0 )
    {
        Attributes = new Attribute[ AttributeCount ];
        for ( unsigned __int16 i = 0; i < AttributeCount; ++i )
            Attributes[i] = *ppTempAttributes[i];

    } // End if any attributes

    // Clean up
    if ( ppTempAttributes != NULL )
        delete []ppTempAttributes;
    if ( pLookupRoot != NULL )
        delete pLookupRoot;

    // Success!
    return true;
}