.. oe:namespace:: OEChem



.. meta::
   :keywords: oemolstreambase, molstreambase


.. _OEChem_oemolstreambase:

.. oe:class:: oemolstreambase

   .. oe:api::


      class oemolstreambase

   The :ref:`oemolstreambase <OEChem_oemolstreambase>` is the abstract base class for
   reading and writing molecules.

   The following classes derive from this class:
    * :ref:`oemolistream <OEChem_oemolistream>`
    * :ref:`oemolithread <OEChem_oemolithread>`
    * :ref:`oemolostream <OEChem_oemolostream>`
    * :ref:`oemolothread <OEChem_oemolothread>`
    * :ref:`oemolthreadbase <OEChem_oemolthreadbase>`

   .. oe:method:: operator=
      :language: c++

      .. oe:api::

         oemolstreambase & operator=(const oemolstreambase & rhs)

      Assignment operator.


   .. oe:method:: ClearCSVHeader

      .. oe:language:: c++ java csharp

         .. oe:api::

            void ClearCSVHeader()

      .. oe:language:: python

         .. oe:api:: python

            ClearCSVHeader() -> None

      Clears out the :ref:`OECSVHeader <OEChem_OECSVHeader>` object owned by this
      stream allowing an alternative set of column names to be
      initialized.

   .. oe:method:: GetBinaryIOHandler

      .. oe:language:: c++ java csharp

         .. oe:api::

            OESystem::OEBinaryIOHandlerBase& GetBinaryIOHandler() const

      .. oe:language:: python

         .. oe:api:: python

            GetBinaryIOHandler() -> OEBinaryIOHandlerBase

   .. oe:method:: GetCSVHeader

      .. oe:language:: c++ java csharp

         .. oe:api::

            OECSVHeader& GetCSVHeader()

      .. oe:language:: python

         .. oe:api:: python

            GetCSVHeader() -> OECSVHeader

      Returns a reference to the :ref:`OECSVHeader <OEChem_OECSVHeader>` object
      owned by this stream. The first molecule read or written to this
      stream will initialize the :ref:`OECSVHeader <OEChem_OECSVHeader>` object
      to the set of SD data tags and the order in which to read or
      write them.

   .. oe:method:: GetFileName

      .. oe:language:: c++ java csharp

         .. oe:api::

            const std::string& GetFileName() const

      .. oe:language:: python

         .. oe:api:: python

            GetFileName() -> str

      Returns the file name used in the previous call to
      :oe:meth:`OEChem::oemolstreambase::open`. An empty string is
      returned if :oe:meth:`OEChem::oemolstreambase::open` has not been
      called yet or :oe:meth:`OEChem::oemolstreambase::close` has been
      called.

   .. oe:method:: GetFlavor

      .. oe:language:: c++ java csharp

         .. oe:api::

            unsigned int GetFlavor(unsigned int format)

      .. oe:language:: python

         .. oe:api:: python

            GetFlavor(format: int) -> int

      Returns the file flavor associated with the format for the
      :ref:`oemolstreambase <OEChem_oemolstreambase>` object.
      The set of valid formats are defined in the
      :ref:`the OEFormat namespace <OEChem_OEFormat>`.
      The set of valid bitmasks flavors of input streams are defined in the
      :oe:constns:`OEChem::OEIFlavor` namespace.
      The set of valid bitmasks flavors of output streams are defined in the
      :oe:constns:`OEChem::OEOFlavor` namespace.

      The flavor for any format can be set using the
      :oe:meth:`OEChem::oemolstreambase::SetFlavor` method.
      The default flavors are automatically set by the
      :ref:`oemolstreambase <OEChem_oemolstreambase>` constructors.

   .. oe:method:: GetFormat

      .. oe:language:: c++ java csharp

         .. oe:api::

            unsigned int GetFormat() const

      .. oe:language:: python

         .. oe:api:: python

            GetFormat() -> int

      Returns the file format associated with the output
      :ref:`oemolstreambase <OEChem_oemolstreambase>` object.
      The set of valid formats are defined in the
      :ref:`the OEFormat namespace <OEChem_OEFormat>`.

      By default, when writing to standard output or when reading from
      standard input the associated file format is
      :oe:const:`OEChem::OEFormat::SMI`.

      The file format property can be set using the
      :oe:meth:`OEChem::oemolstreambase::SetFormat` method.

      .. note::

         The file format property is also set automatically by
         :oe:meth:`OEChem::oemolstreambase::open` based upon the file
         extension of the specified filename.


   .. oe:method:: Getgz

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool Getgz()

      .. oe:language:: python

         .. oe:api:: python

            Getgz() -> bool

      Returns whether the stream is writing to or reading from a gzip
      compressed :ref:`oemolstreambase <OEChem_oemolstreambase>`.

   .. oe:method:: SetFlavor

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool SetFlavor(unsigned int format, unsigned int flavor)=0

      .. oe:language:: python

         .. oe:api:: python

            SetFlavor(format: int, flavor: int) -> bool

      This pure virtual method is designed to set the flavor for a given format
      associated with an input/output molstream.

      .. seealso::

         * :oe:meth:`OEChem::oemolistream::SetFlavor`
         * :oe:meth:`OEChem::oemolithread::SetFlavor`
         * :oe:meth:`OEChem::oemolostream::SetFlavor`
         * :oe:meth:`OEChem::oemolothread::SetFlavor`

   .. oe:method:: SetFormat

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool SetFormat(unsigned int format)=0

      .. oe:language:: python

         .. oe:api:: python

            SetFormat(format: int) -> bool

      This pure virtual method is designed to set the format
      associated with an input/output molstream.

      .. seealso::

         * :oe:meth:`OEChem::oemolistream::SetFormat`
         * :oe:meth:`OEChem::oemolithread::SetFormat`
         * :oe:meth:`OEChem::oemolostream::SetFormat`
         * :oe:meth:`OEChem::oemolothread::SetFormat`

      .. note::

         Setting the molstream format to .gz or .oez when it was previously a different (or default) 
         format re-initializes the OEB handlers in the molstream. This means, any explicit changes 
         to the OEB handlers for the stream should be made after setting the format.

   .. oe:method:: close

      .. oe:language:: c++ java csharp

         .. oe:api::

            void close()

      .. oe:language:: python

         .. oe:api:: python

            close() -> None

      This method clears the :ref:`OECSVHeader <OEChem_OECSVHeader>` object owned
      by this stream, and resets the file name returned by
      :oe:meth:`OEChem::oemolstreambase::GetFileName` back to an empty
      string. It is expected that the user will not need to call this
      method directly, but rely on the following subclass methods to
      call this function:

      * :oe:meth:`OEChem::oemolistream::close`
      * :oe:meth:`OEChem::oemolithread::close`
      * :oe:meth:`OEChem::oemolostream::close`
      * :oe:meth:`OEChem::oemolothread::close`

   .. oe:method:: open

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool open()

      .. oe:language:: python

         .. oe:api:: python

            open() -> bool

      The input molstreams (:ref:`oemolistream <OEChem_oemolistream>`,
      :ref:`oemolithread <OEChem_oemolithread>`) read from to standard input.
      The output molstreams (:ref:`oemolostream <OEChem_oemolostream>`,
      :ref:`oemolothread <OEChem_oemolothread>`) write to standard input.
      The default file format for both input and output molstreams are
      :oe:const:`OEChem::OEFormat::SMI`.
      Calling :oe:meth:`OEChem::oemolstreambase::open` (no arguments)
      on input or output molstreams will force the stream format to
      the default :oe:const:`OEChem::OEFormat::SMI` and the
      gzip compression property to false.

      .. oe:language:: c++ java csharp

         .. oe:api::

            bool open(const char* fname)
            bool open(const std::string& fname)

      .. oe:language:: python

         .. oe:api:: python

            open(name: str) -> bool

      In case of an **input molstream** (:ref:`oemolistream <OEChem_oemolistream>`,
      :ref:`oemolithread <OEChem_oemolithread>`), this method opens a file ,
      specified by its filename ('fname') for reading.
      The file format property of the input molstream is set based
      upon the extension of the given filename.
      If the file extension isn't recognized, a warning is issued and
      the existing file format is unchanged.
      If the filename is appended with :file:`.gz`, the input
      molstream will decompress the file on-the-fly when reading.
      If only a file extension is used as the filename
      (:file:`.oeb.gz`), then the standard input is opened with the
      format specified by the given extensions.

      In case of an **output molstream**
      (:ref:`oemolostream <OEChem_oemolostream>`, :ref:`oemolothread <OEChem_oemolothread>`),
      this method creates (or overwrite) a file , specified by its
      filename ('fname') for writing.
      The file format property of the output molstream is set based
      upon the extension of the given filename.
      If the filename is appended with :file:`.gz`, the output
      molstream will compress the file on-the-fly when writing.
      If the file extension isn't recognized, a warning is issued and
      the existing file format is unchanged.
      If only a file extension is used as the filename
      (:file:`.oeb.gz`), then the standard output is opened with the
      format specified by the given extensions.

      In case of both **input** and **output molstream**, the filename based
      file format may be overridden by calling
      :oe:meth:`OEChem::oemolstreambase::SetFormat` explicitly with
      the desired file format.

