Boost logo

Boost Users :

From: Miguel Silvestre (msilvestre_at_[hidden])
Date: 2007-01-16 05:52:00


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://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Miguel Silvestre

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net