Esempio n. 1
0
void SimpleSetSerializer<DataT, DataSer>::Serialize(Archive& archive) const
{
    int i = 0;
    V_Element components;
    components.resize( m_Data->size() );

    {
        DataType::const_iterator itr = m_Data->begin();
        DataType::const_iterator end = m_Data->end();
        for ( ; itr != end; ++itr )
        {
            ElementPtr dataElem;

            // query cache for a serializer of this type
            archive.GetCache().Create( Reflect::GetType<DataSer>(), dataElem );

            // downcast to serializer type
            DataSer* dataSer = DangerousCast<DataSer>(dataElem);

            // connect to our map data memory address
            dataSer->ConnectData(const_cast<DataT*>(&(*itr)));

            // serialize to the archive stream
            components[i++] = dataSer;
        }
    }

    archive.Serialize(components);

    V_Element::iterator itr = components.begin();
    V_Element::iterator end = components.end();
    for ( ; itr != end; ++itr )
    {
        // downcast to serializer type
        Serializer* ser = DangerousCast<Serializer>(*itr);

        // disconnect from memory
        ser->Disconnect();

        // restore serializer to the cache
        archive.GetCache().Free( ser );
    }
}
void SimpleElementMapSerializer<KeyT>::Serialize(Archive& archive) const
{
    V_Element components;
    components.resize(m_Data->size() * 2);

    {
        DataType::const_iterator itr = m_Data->begin();
        DataType::const_iterator end = m_Data->end();
        for ( int i = 0; itr != end; ++itr )
        {
            if (!itr->second.ReferencesObject())
            {
                continue;
            }

            ElementPtr elem;
            archive.GetCache().Create( Reflect::GetType<KeyT>(), elem );

            Serializer* ser = AssertCast<Serializer>(elem.Ptr());
            ser->ConnectData((void*)&(itr->first));

            components[i++] = ser;
            components[i++] = itr->second;
        }
    }

    archive.Serialize(components);

    {
        V_Element::iterator itr = components.begin();
        V_Element::iterator end = components.end();
        for ( ; itr != end; ++itr )
        {
            Serializer* ser = AssertCast<Serializer>(*itr);
            ser->Disconnect();
            archive.GetCache().Free(ser);
            ++itr;
        }
    }
}
Esempio n. 3
0
void ElementArraySerializer::Serialize(Archive& archive) const
{
    archive.Serialize(m_Data.Get());
}