Esempio n. 1
0
DataPtr Field::ShouldSerialize( void* instance ) const
{
    // never write discard fields
    if ( m_Flags & FieldFlags::Discard )
    {
        return NULL;
    }

    ObjectPtr object = Registry::GetInstance()->CreateInstance( m_DataClass );
    DataPtr data = ThrowCast< Data >( object );
    data->ConnectField( instance, this );

    // always write force fields
    if ( m_Flags & FieldFlags::Force )
    {
        return data;
    }

    // check for empty/null/invalid state
    if ( !data->ShouldSerialize() )
    {
        return NULL;
    }

    // don't write field at the default value
    DataPtr defaultData = CreateDefaultData();
    if ( defaultData.ReferencesObject() && defaultData->Equals(data) )
    {
        return NULL;
    }

    return data;
}
Esempio n. 2
0
bool Composite::Equals(void* a, void* b) const
{
    if (a == b)
    {
        return true;
    }

    if (!a || !b)
    {
        return false;
    }

    DynArray< Field >::ConstIterator itr = m_Fields.Begin();
    DynArray< Field >::ConstIterator end = m_Fields.End();
    for ( ; itr != end; ++itr )
    {
        const Field* field = &*itr;

        // create data objects
        DataPtr aData = field->CreateData();
        DataPtr bData = field->CreateData();

        // connnect
        aData->ConnectField(a, field);
        bData->ConnectField(b, field);

        bool equality = aData->Equals( bData );

        // disconnect
        aData->Disconnect();
        bData->Disconnect();

        if ( !equality )
        {
            return false;
        }
    }

    return true;
}