View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005265VTK(No Category)public2007-07-02 14:072016-08-12 09:54
ReporterGoodwin Lawlor 
Assigned ToBrad King 
PrioritylowSeverityfeatureReproducibilityalways
StatusclosedResolutionmoved 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0005265: XML Reader/Writer with user streams
DescriptionA new class vtkStringStream allows the xml readers and writer to write to a stream. You can then send the data off to a VFS or sql database etc.
TagsNo tags attached.
Project
Type
Attached Filespatch file icon XMLReaderWriter.patch [^] (6,246 bytes) 1969-12-31 19:00 [Show Content]
cxx file icon vtkStringStream.cxx [^] (2,814 bytes) 1969-12-31 19:00
? file icon vtkStringStream.h [^] (1,966 bytes) 1969-12-31 19:00
? file icon TestXMLStringStream.tcl [^] (4,747 bytes) 1969-12-31 19:00
patch file icon XMLReaderWriter2.patch [^] (6,906 bytes) 1969-12-31 19:00 [Show Content]
cxx file icon vtkStringStream2.cxx [^] (3,220 bytes) 1969-12-31 19:00
? file icon vtkStringStream2.h [^] (2,324 bytes) 1969-12-31 19:00

 Relationships

  Notes
(0007976)
Brad King (developer)
2007-07-02 15:03

I'm assigning this to myself since I asked the reporter to submit it.
(0007977)

2007-07-02 15:40

Okay I investigated a bit more history of this feature. It looks like I added support for this feature in 2003:

http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLWriter.h?rev=1.8&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLWriter.cxx?rev=1.21&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLReader.h?rev=1.8&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLReader.cxx?rev=1.15&view=markup [^]

and then removed it soon after:

http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLReader.h?rev=1.9&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLWriter.h?rev=1.9&view=markup [^]

(0007978)
Brad King (developer)
2007-07-02 15:43

I just investigated the history of this feature. It looks like I implemented it in 2003:

http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLReader.h?rev=1.8&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLReader.cxx?rev=1.15&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLWriter.h?rev=1.8&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLWriter.cxx?rev=1.21&view=markup [^]

and removed it soon after:

http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLReader.h?rev=1.9&view=markup [^]
http://www.vtk.org/cgi-bin/viewcvs.cgi/IO/vtkXMLWriter.h?rev=1.9&view=markup [^]

Note the log message for the removal. There were problems with strstream implementations.
(0007979)
Brad King (developer)
2007-07-02 15:45

The old interface was simply:

  //BTX
  // Description:
  // Get/Set the input stream from which to read the data. This
  // overrides use of FileName.
  vtkGetMacro(Stream, istream*);
  vtkSetMacro(Stream, istream*);
  //ETX
(0007980)
Brad King (developer)
2007-07-02 15:45

The old writer interface was simply

  //BTX
  // Description:
  // Get/Set the output stream to which to write the data. This
  // overrides use of FileName.
  vtkGetMacro(Stream, ostream*);
  vtkSetMacro(Stream, ostream*);
  //ETX
(0007981)
Brad King (developer)
2007-07-02 15:50

Clearly the old interface will not work with Tcl wrappers. Something like your vtkStringStream class is needed. The implementation provided in the attached patch has some problems though.

First, the vtkStringStream code does not define ownership of the stringstream. If a user does SetStream and then deletes the vtkStringStream his/her stream will be deleted.

Second, the dynamic_cast added in vtkXMLWriter::OpenFile introduces use of C++ RTTI, which is disallowed by VTK convention. Whether it is time to allow such constructs is beyond the scope of this bug entry.
(0007982)
Brad King (developer)
2007-07-02 15:54

The SetStringStream/GetStringStream interface for vtkXMLReader and vtkXMLWriter is very specific to string streams. Perhaps instead we should create a SetUserStream/GetUserStream interface that accepts an abstract class of a type like vtkXMLUserStream. Then we can define an implementation named something like vtkXMLStringStream as a derived class. The user stream interface would have virtual methods for things like re-setting the stream which would take care of the dynamic_cast problem too.
(0007984)
Goodwin Lawlor (reporter)
2007-07-03 10:18

I think the vtkStringStream should own the stream, so if vtkStringStream is deleted then "Stream" in vtkXMLReader/vtkXMLWriter is set to NULL, and the stringstream is freed. Then vtkXMLReader/vtkXMLWriter just default to reading/writing to file.

I'm not sure this behavour can be obtained with ref counting. I've tried out vtkStringStream keeping a pointer to the writer or reader using it. vtkStringStream's destructor then frees up the Stream in the reader/writer.

I should have used static_cast in vtkXMLWriter::OpenFile() instead of dynamic_cast. It's used throughout the VTK source but it's stil RTTI. Either way its better to have a vtkStringStream::Reset() method which I've implemented in vtkStringStream2 above.

SetStringStream is very specific but what other streams would you use other than ofstream and stringstream with vtkXMLWriter or ifstream and stringstream with vtkXMLReader?

Maybe, make vtkXMLWriter::Set/GetDataStream() a public method taking an abstract class vtkStream as an argument (as you suggest) and have vtkOutputStream, vtkInputStream, and vtkStringStream subclasses of it.
(0008016)
Brad King (developer)
2007-07-09 10:43

For vtkStringStream's ownership of the stringstream, I was just saying that the Set/Get methods for the stream did not provide a well-defined ownership. The simplest solution is to just remove them (or at least the Set) and just have vtkStringStream always create and own the stringstream.

Actually static_cast is not RTTI...dynamic_cast is the only casting operator that produces any runtime checking. Of course having vtkStringStream::Reset() is better anyway as you say.

I need to speak with another co-worker that has asked about stringstream support in the xml files readers/writers before proceeding with integrating these changes. Unfortunately he is on vacation for another 10 days or so. I'll get back to you when he gets back.
(0008025)
Goodwin Lawlor (reporter)
2007-07-11 10:45

I agree that vtkStringStream creates and owns the stringstream... when you mentioned it I noticed that a crash can occur if you set a vtkStringStream in a XML reader/writer and then delete the vtkStringStream before the reader/writer fires. That's why I added a pointer in vtkStringStream to point to the reader/writer using it - when the vtkStreamString's decontructor is called it sets the reader's/writer's pointer to the vtkStreamString to NULL (and then they read/write with a file).

I should have actually read my C++ book on RTTI ;-)

It would be great to have this in the VTK source, since I couldn't easily keep it in a local library.

Thanks!
(0008330)
Brad King (developer)
2007-08-01 16:06

Okay, Berk and I discussed this and have decided that doing this interface the "right way" will open a can of worms with which we do not have time to deal right now. I'm going to defer this for now. Sorry.
(0036917)
Kitware Robot (administrator)
2016-08-12 09:54

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2011-06-16 13:11 Zack Galbreath Category => (No Category)
2016-08-12 09:54 Kitware Robot Note Added: 0036917
2016-08-12 09:54 Kitware Robot Status expired => closed
2016-08-12 09:54 Kitware Robot Resolution suspended => moved


Copyright © 2000 - 2018 MantisBT Team