Logo Search packages:      
Sourcecode: ardour version File versions  Download package

IOStatus Glib::IOChannel::set_encoding ( const std::string &  encoding = std::string()  )  [inherited]

Sets the encoding for the input/output of the channel. The internal encoding is always UTF-8. The default encoding for the external file is UTF-8. The encoding "" is safe to use with binary data.

The encoding can only be set if one of the following conditions is true:

  1. The channel was just created, and has not been written to or read from yet.
  2. The channel is write-only.
  3. The channel is a file, and the file pointer was just repositioned by a call to seek_position(). (This flushes all the internal buffers.)
  4. The current encoding is "" or UTF-8.
  5. One of the read methods has just returned Glib::IO_STATUS_EOF (or, in the case of read_to_end(), Glib::IO_STATUS_NORMAL).
  6. The read() method has returned Glib::IO_STATUS_AGAIN or thrown a Glib::Error exception. This may be useful in the case of ConvertError::ILLEGAL_SEQUENCE. Returning one of these statuses from read_line() or read_to_end() does not guarantee that the encoding can be changed.

Channels which do not meet one of the above conditions cannot call seek_position() with a seek type of Glib::SEEK_TYPE_CUR and, if they are "seekable", cannot call write() after calling one of the API "read" methods.

Parameters:
encoding The encoding name, or "" for binary.
Returns:
Glib::IO_STATUS_NORMAL if the encoding was successfully set.
Exceptions:
Glib::IOChannelError 

Definition at line 272 of file iochannel.cc.

{
  GError* error = 0;

  const GIOStatus status = g_io_channel_set_encoding(
      gobj(), (encoding.empty()) ? 0 : encoding.c_str(), &error);

  if(error)
    Glib::Error::throw_exception(error);

  return (IOStatus) status;
}


Generated by  Doxygen 1.6.0   Back to index