[Ns-bugs] [Bug 155] "std::ostream & os" parameters not Python friendly
bugzilla-daemon@nsnam-www.ece.gatech.edu
bugzilla-daemon at nsnam-www.ece.gatech.edu
Sun Mar 30 10:02:55 PDT 2008
http://www.nsnam.org/bugzilla/show_bug.cgi?id=155
------- Comment #2 from gjcarneiro at gmail.com 2008-03-30 13:02 -------
(In reply to comment #1)
[...]
> > If these NS-3 APIs operated on a reference counted object instead (e.g.
> > Ptr<OStream>) things would be vastly safer to Python bindings... this
> > Ptr<OStream> could have "std::ostream& GetStdOStream ()" method. That would be
> > fine as long as the std::ostream object life cycle management responsibility
> > shifts away from the Python bindings into the NS-3 core itself.
>
> Adding such a Ptr<Ostream> class in the public API looks horribly painful from
> c++ and would kill the whole purpose of these helper methods which is to make
> life easy to c++ programmers, so, I would be really annoyed to have to do this.
True, it would be kind of ugly for C++. But if the API is an additional API,
beside the existing one, with documentation stating it is only used for
language bindings, it should be ok.
>
> It would be nice to find a good solution for python though: how does python
> handle formatted io to stdout and files ? Can you point me to a not-too-painful
> introduction ? How does boost::python handle this case ?
In Python, formatted output (the print statement) works with file-like (using
the so called "duck typing") objects:
http://docs.python.org/lib/bltin-file-objects.html
It's not so much about formatted output; the issue is more about stream output
here. I could provide a std::ostream subclass to ns-3, which used
std::ostringstream internally, and then flushed the string on every newline to
the a python file-like object, and things would work fine (though not very
efficient). The thing I'm worried about is safe life cycle management.
I think a reasonable compromise would be to provide an API that received a file
name and created a file itself. It would not support stdin/stdout tracing, but
other than that would be pretty good, and would not have to go through any
python code, so would be more efficient.
--
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the Ns-bugs
mailing list