Bug 517 - RandomVariable serialization is ugly
RandomVariable serialization is ugly
Status: RESOLVED WONTFIX
Product: ns-3
Classification: Unclassified
Component: core
ns-3-dev
All All
: P5 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-03 15:33 UTC by Rajib Bhattacharjea
Modified: 2009-06-03 03:50 UTC (History)
1 user (show)

See Also:


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

Note You need to log in before you can comment on or make changes to this bug.
Description Rajib Bhattacharjea 2009-03-03 15:33:00 UTC
Created attachment 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 Mathieu Lacage 2009-03-03 15:40:27 UTC
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.