[Insight-developers] itk::TclStringStream

Brad King brad.king@kitware.com
Wed, 31 Oct 2001 13:51:41 -0500 (EST)


Hello, all:

Luis pointed out that there has been no way to call the itk
Print(std::ostream&) methods on objects from Tcl.  I have just added a
class that is built with the ITKCommonTcl package called
"itk::TclStringStream".  A temporary instance of this class can be passed
to any method taking a std::ostream argument, and the Tcl result after the
method invocation will be set to the string written to the ostream:

# Wrapper procedure to hide construction.  This can be added to an
# ITK Tcl utilities package when one is created.
proc itkTclResultStream {} {
  return [itk::TclStringStream [wrap::Interpreter]]
}

# We can call Print(std::ostream&) on an ITK object:
$obj Print [itkTclResultStream]

Now the Tcl result value has been set to the output from the Print method.  
The documentation for the class describes another way of using it in such
a way that an instance can be used multiple times.

-Brad