Bug 517 - RandomVariable serialization is ugly
: RandomVariable serialization is ugly
Status: RESOLVED WONTFIX
: ns-3
simulation core
: ns-3-dev
: All All
: P5 normal
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2009-03-03 15:33 EDT by
Modified: 2009-06-03 03:50 EDT (History)


Attachments
make random variable serialize cleaner (7.99 KB, patch)
2009-03-03 15:33 EDT, Rajib Bhattacharjea
Details | Diff


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2009-03-03 15:33:00 EDT
Created an attachment (id=396) [details]
make random variable serialize cleaner

The code for serializing RandomVariables to an ostream (ostream&
operator<<(ostream&, const RandomVariable&)) is a series of downcasts testing
for which subclass is being serialized, with some per-type code to actually
perform the serialization.  Each writer of a new variable type will at some
point have to go in to this code and write another downcast, and another chunk
of type specific code.

The attached patch inverts the responsibility of serialization to a method in
each subclass, adds a pure virtual method in the base class to enforce the
existence of this method, and has the serialization code call the virtual
method.  This eliminates the downcasts and the need to change the serialization
code for each RandomVariable type added to ns-3.
------- Comment #1 From 2009-03-03 15:40:27 EDT -------
The problem is that deserialization still needs a global function and it's much
easier to check for code correctness when the serialization function is close
to the deserialization function which is not the case if you move serialization
to a per-class method and leave deserialization to a global function.

So, yes, it's ugly but the alternatives don't look really any better.