Exemplo n.º 1
0
ObjectPtr ArchiveBinary::FromStream( std::iostream& stream, const Class* searchClass )
{
    if ( searchClass == NULL )
    {
        searchClass = Reflect::GetClass<Object>();
    }

    ArchiveBinary archive;
    archive.m_SearchClass = searchClass;

    Reflect::CharStreamPtr charStream = new CharStream( &stream, false ); 
    archive.OpenStream( charStream, false );
    archive.Read();
    archive.Close(); 

    std::vector< ObjectPtr >::iterator itr = archive.m_Objects.begin();
    std::vector< ObjectPtr >::iterator end = archive.m_Objects.end();
    for ( ; itr != end; ++itr )
    {
        if ((*itr)->IsClass(searchClass))
        {
            return *itr;
        }
    }

    return NULL;
}
Exemplo n.º 2
0
void StlStringStlVectorData::Serialize(ArchiveBinary& archive)
{
    uint32_t count = (uint32_t)m_Data->size();
    archive.GetStream().Write( &count ); 

    for (size_t i=0; i<m_Data->size(); i++)
    {
        archive.GetStream().WriteString( m_Data->at( i ) ); 
    }
}
Exemplo n.º 3
0
void ArchiveBinary::FromStream( std::iostream& stream, std::vector< ObjectPtr >& objects )
{
    ArchiveBinary archive;

    Reflect::CharStreamPtr charStream = new CharStream( &stream, false ); 
    archive.OpenStream( charStream, false );
    archive.Read();
    archive.Close(); 

    objects = archive.m_Objects;
}
Exemplo n.º 4
0
void ArchiveBinary::ToStream( const std::vector< ObjectPtr >& objects, std::iostream& stream )
{
    ArchiveBinary archive;

    // fix the spool
    archive.m_Objects = objects;

    Reflect::CharStreamPtr charStream = new CharStream( &stream, false ); 
    archive.OpenStream( charStream, true );
    archive.Write();   
    archive.Close(); 
}
Exemplo n.º 5
0
void BitfieldData::Deserialize(ArchiveBinary& archive)
{
    const Enumeration* enumeration = NULL;
    
    if ( m_Field )
    {
        enumeration = ReflectionCast< Enumeration >( m_Field->m_Type );
    }
    else
    {
        HELIUM_BREAK(); // not really supported yet
    }

    uint32_t count = 0;
    archive.GetStream().Read(&count); 

    std::vector< tstring > strs;
    strs.reserve( count );
    while ( count-- > 0 )
    {
        tstring str;
        archive.GetStream().ReadString( str );
        strs.push_back( str );
    }

    tstring str;
    std::vector< tstring >::const_iterator itr = strs.begin();
    std::vector< tstring >::const_iterator end = strs.end();
    for ( ; itr != end; ++itr )
    {
        if (itr != strs.begin())
        {
            str += TXT("|");
        }

        str += *itr;
    }

    if (enumeration && !enumeration->GetBitfieldValue(strs, *m_Data))
    {
        Log::Debug( TXT( "Unable to deserialize bitfield %s values '%s'\n" ), enumeration->m_Name, str.c_str() );
    }
    else
    {
        m_String = str;
    }

    if (enumeration == NULL)
    {
        throw Reflect::TypeInformationException( TXT( "Missing type information" ) );
    }
}
Exemplo n.º 6
0
void StlStringStlVectorData::Deserialize(ArchiveBinary& archive)
{
    m_Data->clear();

    uint32_t count = (uint32_t)m_Data->size();
    archive.GetStream().Read( &count ); 

    m_Data->resize(count);
    for ( uint32_t i=0; i<count; i++ )
    {
        archive.GetStream().ReadString( m_Data->at( i ) ); 
    }
}
Exemplo n.º 7
0
void TypeIDData::Deserialize(ArchiveBinary& archive)
{
    uint32_t crc;
    archive.GetStream().Read(&crc);

    const Type* type = Registry::GetInstance()->GetType( crc );
    if ( type )
    {
        *m_Data = type;
    }
}
Exemplo n.º 8
0
void BitfieldData::Serialize(ArchiveBinary& archive)
{
    const Enumeration* enumeration = NULL;
    
    if ( m_Field )
    {
        enumeration = ReflectionCast< Enumeration >( m_Field->m_Type );
    }
    else
    {
        HELIUM_BREAK(); // not really supported yet
    }

    if (enumeration)
    {
        std::vector< tstring > strs;
        if (!enumeration->GetBitfieldStrings( *m_Data, strs ))
        {
            throw Reflect::TypeInformationException( TXT( "Unable to serialize bitfield '%s', value %d" ), enumeration->m_Name, *m_Data );
        }

        uint32_t count = (uint32_t)strs.size();
        archive.GetStream().Write(&count); 

        std::vector< tstring >::const_iterator itr = strs.begin();
        std::vector< tstring >::const_iterator end = strs.end();
        for ( ; itr != end; ++itr )
        {
            archive.GetStream().WriteString( *itr );
        }
    }

    if (enumeration == NULL)
    {
        throw Reflect::TypeInformationException( TXT( "Missing type information" ) );
    }
}
Exemplo n.º 9
0
void TypeIDData::Serialize(ArchiveBinary& archive)
{
    const Type* type = *m_Data;
    uint32_t crc = type ? Crc32( type->m_Name ) : BeginCrc32();
    archive.GetStream().Write(&crc); 
}
Exemplo n.º 10
0
void SimpleData<T>::Deserialize(ArchiveBinary& archive)
{
    T* data = m_Data;
    archive.GetStream().Read( data ); 
}
Exemplo n.º 11
0
void SimpleData<T>::Serialize(ArchiveBinary& archive)
{
    const T* data = m_Data;
    archive.GetStream().Write( data ); 
}
Exemplo n.º 12
0
void SimpleStlVectorData<T>::Deserialize(ArchiveBinary& archive)
{
    // if we are referring to a real field, clear its contents
    m_Data->clear();
    ReadVector( *m_Data, archive.GetStream() );
}
Exemplo n.º 13
0
void SimpleStlVectorData<T>::Serialize(ArchiveBinary& archive)
{
    WriteVector( *m_Data, archive.GetStream() );
}