Boost logo

Boost :

From: Beman Dawes (bdawes_at_[hidden])
Date: 2004-11-08 11:07:16


At 04:13 AM 11/8/2004, Francis ANDRE wrote:
>Hi
>
>In order to serialize a derivative class of boost/filesystem/path, one
>cannot access the base class member m_path without changing its
>visibility
>from private to protected:
>
>I would suggest to change the visibility of this m_path member from
>private: to protected, or to add an implicit definition of the serialize
>method into the class boost::filesystem::path.
>
>#include <boost/filesystem/path.hpp>
>namespace boost { namespace serialization { class access; }}
>
>class OSD : public boost::filesystem::path {
>private:
> friend class boost::serialization::access;
> friend std::ostream & operator<<(std::ostream &os, const OSD&);
> template<class Archive>
> void serialize(Archive &ar, const unsigned int version) {
> ar & m_path;
> }
>};

I don't particularly like either of those solutions.

* Changing m_path from private to protected effectively adds m_path to the
class interface, yet m_path is an implementation artifact that might not be
present at all in a different implementation.

* Adding a dependency to the serialization library isn't a good idea
either. No matter how nice boost.serialization is, some boost.filesystem
users will not wish to use it, and will not want the dependency.

Class path already has a member, path::string(), which in the current
implementation returns a reference to m_path, and in any implementation
must return the equivalent of a const reference to m_path. Going the other
way, the append function can be used to import a serialized string. I'm not
familiar with how boost.serialization works, but wouldn't you be better off
to use those already public functions for serialization?

If not, I'm willing to make m_path protected, but would like to explore
other approaches to the serialization problem first.

Thanks,

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk