From: quendezus (quendez_at_[hidden])
Date: 2002-02-15 05:05:46
--- In boost_at_y..., Matthias Troyer <troyer_at_i...> wrote:
> On Wednesday, February 13, 2002, at 06:19 PM, quendezus wrote:
> >> No, I need at least three different types of streams at runtime.
> >> That's why I think I need some type of polymorphism (templates or
> >> virtual functions) on the stream.
> >> Matthias
> > Ok, I think you are right: the person who calls the serialization
> > function should be able to transmit some info to the serialization
> > code (in your case, the stream to format the output). I realize
> > is necessary.
> > Therefore the type of the stream (or the type of a context class)
> > should be a template parameter :
> > template < class T, class Context >
> > void serialize( std::streambuf& dest, const T& t, Context& t )
> > or:
> > template < class T, class Stream >
> > void serialize( Stream& dest, const T& t )
> > I have already tried a solution like that and it seems to work
> > is complicated. I will think about how to simplify it.
> Jen's library already does this in a very elegant way using
> templates. My concern was that it seems in some cases I need
> runtime-polymorphism using virtual functions.
Jen's design is elegant but does not deal with types unknown at
compile time. When dealing with types only known at runtime, it is
necessary, I think, to pass the Reader and Writer template parameters
during the registration process. It adds complexity.
Can you explain some more why you need runtime-polymorphism? For
example, using Jen's code, why is the following not sufficient in
std::map<std::string, person> database;
// Using one type of stream
// Using another type of stream
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk