$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Miguel Silvestre (msilvestre_at_[hidden])
Date: 2007-01-16 06:20:47
And here is my Serializer class:
class Serializer : public Object
{
        //RTTI_DECLARE;
        typedef Object Parent;
public:		
        virtual void Serialize(IArchive& ar, const unsigned int version) { };
        template<class Archive>
        void serialize(Archive & ar, const unsigned int version)
        {		
                Serialize((IArchive&)ar, version);
        }
};
On 1/16/07, Miguel Silvestre <msilvestre_at_[hidden]> wrote:
> I can't do that.
>
> It gives me a compilation error. My IArchive class is pure virtual and
> without templates..
>
> I just don't now how to turn around this mess :P.
>
> Running out of ideas. Recapitulating:
>
> I have a pure virtual class IArchive with the funtions:
> virtual void Serialize(int & t) = 0;
> ...
> virtual void Serialize(Serializer& t) = 0;
> virtual void Serialize(Serializer* t) = 0;
>
> And my BinaryOArchive extends the IArchive Class and the
> binary_oarchive_impl like:
>
> class BinaryArchiveO : public IArchive,
>         // don't derive from binary_oarchive !!!
>         public boost::archive::binary_oarchive_impl<BinaryArchiveO>
> {
> public:
>         BinaryArchiveO(std::ostream & os, unsigned flags = 0) :
>           boost::archive::binary_oarchive_impl<BinaryArchiveO>(os, flags)
>           {}
>
>           FE_SERIALIZATION_SERIALIZE;
>
>           virtual void Serialize(void * data, size_t size)
>           {
>                   save_binary(data, size);
>           }
> };
>
> the macro FE_SERIALIZATION_SERIALIZE; is the implementation of the
> Serialize basic type functions:
> virtual void Serialize(Quaternion& t) { *this & BOOST_SERIALIZATION_NVP(t.q); }\
> virtual void Serialize(Serializer* t){*this & BOOST_SERIALIZATION_NVP(t);}
> ...
>
> And I have the classes I want to serialize derived by the Serializer class:
> like:
>
> class C : public Serializer
> {
>         typedef Serializer Parent;
> public:
>         std::string text;
>         A* m_owner;
>         int32 dasse;
>         Vector<float> vector_test;
>
>         C():m_owner(0)
>         {
>                 text = "Ola sua puta rabeta!";
>                 dasse = 69;
>                 vector_test.push_back(1);
>                 vector_test.push_back(1.2f);
>                 vector_test.push_back(1.3f);
>                 vector_test.push_back(1.4f);
>         }
>
>         void Serialize(IArchive& ar, const unsigned int version)
>         {
>                 //ar.template register_type<C>();
>                 ar.Serialize(dasse);
>                 ar.Serialize(text);
>                 //ar.Serialize(m_owner);
>                 //ar.Serialize(vector_test);
>         }
> };
>
> but if I do something like:
>
> int SilvTask::WriteObject()
> {
>         Serializer* testC = new C();
>
>         std::ofstream ofs(m_filename.c_str());
>         TextArchiveO oa(ofs);
>
>         oa & BOOST_SERIALIZATION_NVP(testC);
>
>         return FE_OK;
> }
>
> It gives me a cast_exception or a class_exception as I said.
>
> :S
>
>
>
>
>
>
> On 1/15/07, Robert Ramey <ramey_at_[hidden]> wrote:
> > Try the following:
> >
> > >>>>> class A : public Serializer
> > >>>>> {
> > >>>>>         typedef Serializer Parent;
> > >>>>> public:
> > >>>>>
> > >>>>>          void Serialize(IArchive& ar, const unsigned int version)
> > >>>>>         {
> >                             ar.template register_type<C>();
> > >>>>>                 ar.Serialize(dumbi);
> > >>>>>                 ar.Serialize(vectorTest);
> > >>>>>                 ar.Serialize(matrix);
> > >>>>>                 ar.Serialize(testing);
> > >>>>>                 ar.Serialize((void*)test_void, sizeof(Vector3f));
> > >>>>>         }
> > >>>>>
> >
> >
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://listarchives.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>
> --
> Miguel Silvestre
>
-- Miguel Silvestre