예제 #1
0
ObjectPtr ArchiveXML::FromString( const tstring& xml, const Class* searchClass )
{
    if ( searchClass == NULL )
    {
        searchClass = Reflect::GetClass<Object>();
    }

    ArchiveXML archive;
    archive.m_SearchClass = searchClass;

    tstringstream strStream;
    strStream << xml;
    archive.m_Stream = new Reflect::TCharStream(&strStream, false); 
    archive.Read();

    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;
}
예제 #2
0
void ArchiveXML::FromString( const tstring& xml, std::vector< ObjectPtr >& objects )
{
    ArchiveXML archive;
    tstringstream strStream;
    strStream << xml;

    archive.m_Stream = new Reflect::TCharStream( &strStream, false );
    archive.Read();

    objects = archive.m_Objects;
}
예제 #3
0
void ArchiveXML::ToString( const std::vector< ObjectPtr >& objects, tstring& xml )
{
    ArchiveXML archive;
    tstringstream strStream;

    archive.m_Stream = new Reflect::TCharStream( &strStream, false ); 
    archive.m_Objects = objects;
    archive.Write();

    xml = strStream.str();
}
예제 #4
0
void TypeIDData::Deserialize(ArchiveXML& archive)
{
    std::streamsize size = archive.GetStream().ElementsAvailable(); 
    tstring str;
    str.resize( (size_t)size );
    archive.GetStream().ReadBuffer(const_cast<tchar_t*>(str.c_str()), size);

    const Type* type = Registry::GetInstance()->GetType( str.c_str() );
    if ( type )
    {
        *m_Data = type;
    }
}
예제 #5
0
void BitfieldData::Deserialize(ArchiveXML& archive)
{
    const Enumeration* enumeration = NULL;
    
    if ( m_Field )
    {
        enumeration = ReflectionCast< Enumeration >( m_Field->m_Type );
    }
    else
    {
        HELIUM_BREAK(); // not really supported yet
    }

    tstring buf;
    archive.GetStream() >> buf;

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

    if (enumeration == NULL)
    {
        throw Reflect::TypeInformationException( TXT( "Missing type information" ) );
    }
}
예제 #6
0
void BitfieldData::Serialize(ArchiveXML& archive)
{
    const Enumeration* enumeration = NULL;
    
    if ( m_Field )
    {
        enumeration = ReflectionCast< Enumeration >( m_Field->m_Type );
    }
    else
    {
        HELIUM_BREAK(); // not really supported yet
    }

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

    archive.GetStream() << str;

    if (enumeration == NULL)
    {
        throw Reflect::TypeInformationException( TXT( "Missing type information" ) );
    }
}
예제 #7
0
void TypeIDData::Serialize(ArchiveXML& archive)
{
    const Type* type = *m_Data;
    if ( type )
    {
        archive.GetStream() << "<![CDATA[" << type->m_Name << "]]>";
    }
}
예제 #8
0
void SimpleStlVectorData<T>::Deserialize(ArchiveXML& archive)
{
    // if we are referring to a real field, clear its contents
    m_Data->clear();

    T value;
    archive.GetStream().SkipWhitespace(); 

    while (!archive.GetStream().Done())
    {
        // read data
        archive.GetStream() >> value;

        // copy onto vector
        m_Data->push_back(value);

        // read to next non-whitespace char
        archive.GetStream().SkipWhitespace(); 
    }
}
예제 #9
0
void StlStringStlVectorData::Deserialize(ArchiveXML& archive)
{
    m_Data->clear();

    archive.GetStream().SkipWhitespace(); 
    tstring value;

    while (!archive.GetStream().Done())
    {
        std::getline( archive.GetStream().GetInternal(), value ); 

        size_t start = value.find_first_of('\"');
        size_t end = value.find_last_of('\"');

        // if we found a pair of quotes
        if (start != std::string::npos && end != std::string::npos && start != end)
        {
            // if all we have are open/close quotes, push a blank string
            if (start == end-1)
            {
                m_Data->push_back(tstring ());
            }
            // else we have some non-null string data
            else
            {
                m_Data->push_back(value.substr(start + 1, end - start - 1));
            }
        }
        else
        {
            start = value.find_first_not_of( TXT( " \t\n" ) );

            if (start != std::string::npos)
                m_Data->push_back(value.substr(start));
        }

        archive.GetStream().SkipWhitespace(); 
    }
}
예제 #10
0
void SimpleStlVectorData<T>::Serialize(ArchiveXML& archive)
{
    archive.GetIndent().Push();

    // foreach datum
    for (size_t i=0; i<m_Data->size(); i++)
    {
        // indent
        archive.GetIndent().Get(archive.GetStream());

        // write
        archive.GetStream() << m_Data->at( i );

        // newline
        archive.GetStream() << "\n";
    }

    archive.GetIndent().Pop();
}
예제 #11
0
void SimpleData<T>::Serialize(ArchiveXML& archive)
{
    archive.GetStream() << *m_Data;
}
예제 #12
0
void StlStringStlVectorData::Serialize(ArchiveXML& archive)
{
    archive.GetIndent().Push();
    archive.GetIndent().Get(archive.GetStream());

    // start our CDATA section, this prevents XML from parsing its escapes in this cdata section
    archive.GetStream() << TXT("<![CDATA[\n");

    for (size_t i=0; i<m_Data->size(); i++)
    {
        archive.GetIndent().Get(archive.GetStream());

        // output the escape-code free character sequence between double qutoes
        archive.GetStream() << TXT('\"') << m_Data->at( i ) << TXT('\"') << s_ContainerItemDelimiter;
    }

    // end our CDATA escape section
    archive.GetIndent().Get(archive.GetStream());
    archive.GetStream() << TXT("]]>\n");

    archive.GetIndent().Pop();
}